mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2026-05-02 23:25:50 +00:00
ProcMacroProcessExpander: support attribute macros
This commit is contained in:
@@ -42,9 +42,17 @@ impl tt::TokenExpander for ProcMacroProcessExpander {
|
|||||||
fn expand(
|
fn expand(
|
||||||
&self,
|
&self,
|
||||||
subtree: &Subtree,
|
subtree: &Subtree,
|
||||||
_attr: Option<&Subtree>,
|
attr: Option<&Subtree>,
|
||||||
) -> Result<Subtree, tt::ExpansionError> {
|
) -> Result<Subtree, tt::ExpansionError> {
|
||||||
self.process.custom_derive(&self.dylib_path, subtree, &self.name)
|
let task = ExpansionTask {
|
||||||
|
macro_body: subtree.clone(),
|
||||||
|
macro_name: self.name.to_string(),
|
||||||
|
attributes: attr.cloned(),
|
||||||
|
lib: self.dylib_path.to_path_buf(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let result: ExpansionResult = self.process.send_task(msg::Request::ExpansionMacro(task))?;
|
||||||
|
Ok(result.expansion)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,11 +10,10 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crossbeam_channel::{bounded, Receiver, Sender};
|
use crossbeam_channel::{bounded, Receiver, Sender};
|
||||||
use tt::Subtree;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
msg::{ErrorCode, Message, Request, Response, ResponseError},
|
msg::{ErrorCode, Message, Request, Response, ResponseError},
|
||||||
rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind},
|
rpc::{ListMacrosResult, ListMacrosTask, ProcMacroKind},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
@@ -58,23 +57,6 @@ impl ProcMacroProcessSrv {
|
|||||||
Ok(result.macros)
|
Ok(result.macros)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn custom_derive(
|
|
||||||
&self,
|
|
||||||
dylib_path: &Path,
|
|
||||||
subtree: &Subtree,
|
|
||||||
derive_name: &str,
|
|
||||||
) -> Result<Subtree, tt::ExpansionError> {
|
|
||||||
let task = ExpansionTask {
|
|
||||||
macro_body: subtree.clone(),
|
|
||||||
macro_name: derive_name.to_string(),
|
|
||||||
attributes: None,
|
|
||||||
lib: dylib_path.to_path_buf(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let result: ExpansionResult = self.send_task(Request::ExpansionMacro(task))?;
|
|
||||||
Ok(result.expansion)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn send_task<R>(&self, req: Request) -> Result<R, tt::ExpansionError>
|
pub(crate) fn send_task<R>(&self, req: Request) -> Result<R, tt::ExpansionError>
|
||||||
where
|
where
|
||||||
R: TryFrom<Response, Error = &'static str>,
|
R: TryFrom<Response, Error = &'static str>,
|
||||||
|
|||||||
Reference in New Issue
Block a user