Retain types of proc macros and allow attr. macros
This commit is contained in:
parent
e8a19e24ea
commit
fb21a215be
6 changed files with 30 additions and 22 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1187,6 +1187,7 @@ dependencies = [
|
|||
name = "proc_macro_api"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"base_db",
|
||||
"crossbeam-channel 0.5.0",
|
||||
"jod-thread",
|
||||
"log",
|
||||
|
|
|
@ -143,9 +143,17 @@ impl CrateDisplayName {
|
|||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ProcMacroId(pub u32);
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
||||
pub enum ProcMacroKind {
|
||||
CustomDerive,
|
||||
FuncLike,
|
||||
Attr,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ProcMacro {
|
||||
pub name: SmolStr,
|
||||
pub kind: ProcMacroKind,
|
||||
pub expander: Arc<dyn TokenExpander>,
|
||||
}
|
||||
|
||||
|
@ -198,11 +206,8 @@ impl CrateGraph {
|
|||
display_name: Option<CrateDisplayName>,
|
||||
cfg_options: CfgOptions,
|
||||
env: Env,
|
||||
proc_macro: Vec<(SmolStr, Arc<dyn tt::TokenExpander>)>,
|
||||
proc_macro: Vec<ProcMacro>,
|
||||
) -> CrateId {
|
||||
let proc_macro =
|
||||
proc_macro.into_iter().map(|(name, it)| ProcMacro { name, expander: it }).collect();
|
||||
|
||||
let data = CrateData {
|
||||
root_file_id: file_id,
|
||||
edition,
|
||||
|
|
|
@ -14,7 +14,7 @@ pub use crate::{
|
|||
change::Change,
|
||||
input::{
|
||||
CrateData, CrateDisplayName, CrateGraph, CrateId, CrateName, Dependency, Edition, Env,
|
||||
ProcMacroId, SourceRoot, SourceRootId,
|
||||
ProcMacro, ProcMacroId, ProcMacroKind, SourceRoot, SourceRootId,
|
||||
},
|
||||
};
|
||||
pub use salsa;
|
||||
|
|
|
@ -17,3 +17,4 @@ crossbeam-channel = "0.5.0"
|
|||
jod-thread = "0.1.1"
|
||||
|
||||
tt = { path = "../tt", version = "0.0.0" }
|
||||
base_db = { path = "../base_db", version = "0.0.0" }
|
||||
|
|
|
@ -16,6 +16,7 @@ use std::{
|
|||
sync::Arc,
|
||||
};
|
||||
|
||||
use base_db::ProcMacro;
|
||||
use tt::{SmolStr, Subtree};
|
||||
|
||||
use crate::process::{ProcMacroProcessSrv, ProcMacroProcessThread};
|
||||
|
@ -82,7 +83,7 @@ impl ProcMacroClient {
|
|||
ProcMacroClient { kind: ProcMacroClientKind::Dummy }
|
||||
}
|
||||
|
||||
pub fn by_dylib_path(&self, dylib_path: &Path) -> Vec<(SmolStr, Arc<dyn tt::TokenExpander>)> {
|
||||
pub fn by_dylib_path(&self, dylib_path: &Path) -> Vec<ProcMacro> {
|
||||
match &self.kind {
|
||||
ProcMacroClientKind::Dummy => vec![],
|
||||
ProcMacroClientKind::Process { process, .. } => {
|
||||
|
@ -96,21 +97,21 @@ impl ProcMacroClient {
|
|||
|
||||
macros
|
||||
.into_iter()
|
||||
.filter_map(|(name, kind)| {
|
||||
match kind {
|
||||
ProcMacroKind::CustomDerive | ProcMacroKind::FuncLike => {
|
||||
let name = SmolStr::new(&name);
|
||||
let expander: Arc<dyn tt::TokenExpander> =
|
||||
Arc::new(ProcMacroProcessExpander {
|
||||
process: process.clone(),
|
||||
name: name.clone(),
|
||||
dylib_path: dylib_path.into(),
|
||||
});
|
||||
Some((name, expander))
|
||||
}
|
||||
// FIXME: Attribute macro are currently unsupported.
|
||||
ProcMacroKind::Attr => None,
|
||||
}
|
||||
.map(|(name, kind)| {
|
||||
let name = SmolStr::new(&name);
|
||||
let kind = match kind {
|
||||
ProcMacroKind::CustomDerive => base_db::ProcMacroKind::CustomDerive,
|
||||
ProcMacroKind::FuncLike => base_db::ProcMacroKind::FuncLike,
|
||||
ProcMacroKind::Attr => base_db::ProcMacroKind::Attr,
|
||||
};
|
||||
let expander: Arc<dyn tt::TokenExpander> =
|
||||
Arc::new(ProcMacroProcessExpander {
|
||||
process: process.clone(),
|
||||
name: name.clone(),
|
||||
dylib_path: dylib_path.into(),
|
||||
});
|
||||
|
||||
ProcMacro { name, kind, expander }
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ pub struct ListMacrosTask {
|
|||
pub lib: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Clone, Eq, PartialEq, Debug, Serialize, Deserialize)]
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Debug, Serialize, Deserialize)]
|
||||
pub enum ProcMacroKind {
|
||||
CustomDerive,
|
||||
FuncLike,
|
||||
|
|
Loading…
Add table
Reference in a new issue