Retain types of proc macros and allow attr. macros

This commit is contained in:
Jonas Schievink 2020-12-07 17:06:14 +01:00
parent e8a19e24ea
commit fb21a215be
6 changed files with 30 additions and 22 deletions

1
Cargo.lock generated
View file

@ -1187,6 +1187,7 @@ dependencies = [
name = "proc_macro_api"
version = "0.0.0"
dependencies = [
"base_db",
"crossbeam-channel 0.5.0",
"jod-thread",
"log",

View file

@ -143,9 +143,17 @@ pub fn from_canonical_name(canonical_name: String) -> 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 @@ pub fn add_crate_root(
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,

View file

@ -14,7 +14,7 @@
change::Change,
input::{
CrateData, CrateDisplayName, CrateGraph, CrateId, CrateName, Dependency, Edition, Env,
ProcMacroId, SourceRoot, SourceRootId,
ProcMacro, ProcMacroId, ProcMacroKind, SourceRoot, SourceRootId,
},
};
pub use salsa;

View file

@ -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" }

View file

@ -16,6 +16,7 @@
sync::Arc,
};
use base_db::ProcMacro;
use tt::{SmolStr, Subtree};
use crate::process::{ProcMacroProcessSrv, ProcMacroProcessThread};
@ -82,7 +83,7 @@ pub fn dummy() -> 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 @@ pub fn by_dylib_path(&self, dylib_path: &Path) -> Vec<(SmolStr, Arc<dyn tt::Toke
macros
.into_iter()
.filter_map(|(name, kind)| {
match kind {
ProcMacroKind::CustomDerive | ProcMacroKind::FuncLike => {
.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(),
});
Some((name, expander))
}
// FIXME: Attribute macro are currently unsupported.
ProcMacroKind::Attr => None,
}
ProcMacro { name, kind, expander }
})
.collect()
}

View file

@ -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,