Skip to content

Commit fb21a21

Browse files
Retain types of proc macros and allow attr. macros
1 parent e8a19e2 commit fb21a21

File tree

6 files changed

+30
-22
lines changed

6 files changed

+30
-22
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/base_db/src/input.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,17 @@ impl CrateDisplayName {
143143
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
144144
pub struct ProcMacroId(pub u32);
145145

146+
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
147+
pub enum ProcMacroKind {
148+
CustomDerive,
149+
FuncLike,
150+
Attr,
151+
}
152+
146153
#[derive(Debug, Clone)]
147154
pub struct ProcMacro {
148155
pub name: SmolStr,
156+
pub kind: ProcMacroKind,
149157
pub expander: Arc<dyn TokenExpander>,
150158
}
151159

@@ -198,11 +206,8 @@ impl CrateGraph {
198206
display_name: Option<CrateDisplayName>,
199207
cfg_options: CfgOptions,
200208
env: Env,
201-
proc_macro: Vec<(SmolStr, Arc<dyn tt::TokenExpander>)>,
209+
proc_macro: Vec<ProcMacro>,
202210
) -> CrateId {
203-
let proc_macro =
204-
proc_macro.into_iter().map(|(name, it)| ProcMacro { name, expander: it }).collect();
205-
206211
let data = CrateData {
207212
root_file_id: file_id,
208213
edition,

crates/base_db/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub use crate::{
1414
change::Change,
1515
input::{
1616
CrateData, CrateDisplayName, CrateGraph, CrateId, CrateName, Dependency, Edition, Env,
17-
ProcMacroId, SourceRoot, SourceRootId,
17+
ProcMacro, ProcMacroId, ProcMacroKind, SourceRoot, SourceRootId,
1818
},
1919
};
2020
pub use salsa;

crates/proc_macro_api/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ crossbeam-channel = "0.5.0"
1717
jod-thread = "0.1.1"
1818

1919
tt = { path = "../tt", version = "0.0.0" }
20+
base_db = { path = "../base_db", version = "0.0.0" }

crates/proc_macro_api/src/lib.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::{
1616
sync::Arc,
1717
};
1818

19+
use base_db::ProcMacro;
1920
use tt::{SmolStr, Subtree};
2021

2122
use crate::process::{ProcMacroProcessSrv, ProcMacroProcessThread};
@@ -82,7 +83,7 @@ impl ProcMacroClient {
8283
ProcMacroClient { kind: ProcMacroClientKind::Dummy }
8384
}
8485

85-
pub fn by_dylib_path(&self, dylib_path: &Path) -> Vec<(SmolStr, Arc<dyn tt::TokenExpander>)> {
86+
pub fn by_dylib_path(&self, dylib_path: &Path) -> Vec<ProcMacro> {
8687
match &self.kind {
8788
ProcMacroClientKind::Dummy => vec![],
8889
ProcMacroClientKind::Process { process, .. } => {
@@ -96,21 +97,21 @@ impl ProcMacroClient {
9697

9798
macros
9899
.into_iter()
99-
.filter_map(|(name, kind)| {
100-
match kind {
101-
ProcMacroKind::CustomDerive | ProcMacroKind::FuncLike => {
102-
let name = SmolStr::new(&name);
103-
let expander: Arc<dyn tt::TokenExpander> =
104-
Arc::new(ProcMacroProcessExpander {
105-
process: process.clone(),
106-
name: name.clone(),
107-
dylib_path: dylib_path.into(),
108-
});
109-
Some((name, expander))
110-
}
111-
// FIXME: Attribute macro are currently unsupported.
112-
ProcMacroKind::Attr => None,
113-
}
100+
.map(|(name, kind)| {
101+
let name = SmolStr::new(&name);
102+
let kind = match kind {
103+
ProcMacroKind::CustomDerive => base_db::ProcMacroKind::CustomDerive,
104+
ProcMacroKind::FuncLike => base_db::ProcMacroKind::FuncLike,
105+
ProcMacroKind::Attr => base_db::ProcMacroKind::Attr,
106+
};
107+
let expander: Arc<dyn tt::TokenExpander> =
108+
Arc::new(ProcMacroProcessExpander {
109+
process: process.clone(),
110+
name: name.clone(),
111+
dylib_path: dylib_path.into(),
112+
});
113+
114+
ProcMacro { name, kind, expander }
114115
})
115116
.collect()
116117
}

crates/proc_macro_api/src/rpc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct ListMacrosTask {
1919
pub lib: PathBuf,
2020
}
2121

22-
#[derive(Clone, Eq, PartialEq, Debug, Serialize, Deserialize)]
22+
#[derive(Copy, Clone, Eq, PartialEq, Debug, Serialize, Deserialize)]
2323
pub enum ProcMacroKind {
2424
CustomDerive,
2525
FuncLike,

0 commit comments

Comments
 (0)