diff options
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | crates/base_db/src/input.rs | 13 | ||||
-rw-r--r-- | crates/base_db/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/proc_macro_api/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/proc_macro_api/src/lib.rs | 33 | ||||
-rw-r--r-- | crates/proc_macro_api/src/rpc.rs | 2 |
6 files changed, 30 insertions, 22 deletions
diff --git a/Cargo.lock b/Cargo.lock index f1847e769..b73fb909c 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -1187,6 +1187,7 @@ dependencies = [ | |||
1187 | name = "proc_macro_api" | 1187 | name = "proc_macro_api" |
1188 | version = "0.0.0" | 1188 | version = "0.0.0" |
1189 | dependencies = [ | 1189 | dependencies = [ |
1190 | "base_db", | ||
1190 | "crossbeam-channel 0.5.0", | 1191 | "crossbeam-channel 0.5.0", |
1191 | "jod-thread", | 1192 | "jod-thread", |
1192 | "log", | 1193 | "log", |
diff --git a/crates/base_db/src/input.rs b/crates/base_db/src/input.rs index 98ba372ad..cda5e57dc 100644 --- a/crates/base_db/src/input.rs +++ b/crates/base_db/src/input.rs | |||
@@ -143,9 +143,17 @@ impl CrateDisplayName { | |||
143 | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] | 143 | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] |
144 | pub struct ProcMacroId(pub u32); | 144 | pub struct ProcMacroId(pub u32); |
145 | 145 | ||
146 | #[derive(Copy, Clone, Eq, PartialEq, Debug)] | ||
147 | pub enum ProcMacroKind { | ||
148 | CustomDerive, | ||
149 | FuncLike, | ||
150 | Attr, | ||
151 | } | ||
152 | |||
146 | #[derive(Debug, Clone)] | 153 | #[derive(Debug, Clone)] |
147 | pub struct ProcMacro { | 154 | pub struct ProcMacro { |
148 | pub name: SmolStr, | 155 | pub name: SmolStr, |
156 | pub kind: ProcMacroKind, | ||
149 | pub expander: Arc<dyn TokenExpander>, | 157 | pub expander: Arc<dyn TokenExpander>, |
150 | } | 158 | } |
151 | 159 | ||
@@ -198,11 +206,8 @@ impl CrateGraph { | |||
198 | display_name: Option<CrateDisplayName>, | 206 | display_name: Option<CrateDisplayName>, |
199 | cfg_options: CfgOptions, | 207 | cfg_options: CfgOptions, |
200 | env: Env, | 208 | env: Env, |
201 | proc_macro: Vec<(SmolStr, Arc<dyn tt::TokenExpander>)>, | 209 | proc_macro: Vec<ProcMacro>, |
202 | ) -> CrateId { | 210 | ) -> CrateId { |
203 | let proc_macro = | ||
204 | proc_macro.into_iter().map(|(name, it)| ProcMacro { name, expander: it }).collect(); | ||
205 | |||
206 | let data = CrateData { | 211 | let data = CrateData { |
207 | root_file_id: file_id, | 212 | root_file_id: file_id, |
208 | edition, | 213 | edition, |
diff --git a/crates/base_db/src/lib.rs b/crates/base_db/src/lib.rs index ce75a5337..5571af495 100644 --- a/crates/base_db/src/lib.rs +++ b/crates/base_db/src/lib.rs | |||
@@ -14,7 +14,7 @@ pub use crate::{ | |||
14 | change::Change, | 14 | change::Change, |
15 | input::{ | 15 | input::{ |
16 | CrateData, CrateDisplayName, CrateGraph, CrateId, CrateName, Dependency, Edition, Env, | 16 | CrateData, CrateDisplayName, CrateGraph, CrateId, CrateName, Dependency, Edition, Env, |
17 | ProcMacroId, SourceRoot, SourceRootId, | 17 | ProcMacro, ProcMacroId, ProcMacroKind, SourceRoot, SourceRootId, |
18 | }, | 18 | }, |
19 | }; | 19 | }; |
20 | pub use salsa; | 20 | pub use salsa; |
diff --git a/crates/proc_macro_api/Cargo.toml b/crates/proc_macro_api/Cargo.toml index 3863e5189..1af2bbca7 100644 --- a/crates/proc_macro_api/Cargo.toml +++ b/crates/proc_macro_api/Cargo.toml | |||
@@ -17,3 +17,4 @@ crossbeam-channel = "0.5.0" | |||
17 | jod-thread = "0.1.1" | 17 | jod-thread = "0.1.1" |
18 | 18 | ||
19 | tt = { path = "../tt", version = "0.0.0" } | 19 | tt = { path = "../tt", version = "0.0.0" } |
20 | base_db = { path = "../base_db", version = "0.0.0" } | ||
diff --git a/crates/proc_macro_api/src/lib.rs b/crates/proc_macro_api/src/lib.rs index 40fdbfd5a..bf1f90879 100644 --- a/crates/proc_macro_api/src/lib.rs +++ b/crates/proc_macro_api/src/lib.rs | |||
@@ -16,6 +16,7 @@ use std::{ | |||
16 | sync::Arc, | 16 | sync::Arc, |
17 | }; | 17 | }; |
18 | 18 | ||
19 | use base_db::ProcMacro; | ||
19 | use tt::{SmolStr, Subtree}; | 20 | use tt::{SmolStr, Subtree}; |
20 | 21 | ||
21 | use crate::process::{ProcMacroProcessSrv, ProcMacroProcessThread}; | 22 | use crate::process::{ProcMacroProcessSrv, ProcMacroProcessThread}; |
@@ -82,7 +83,7 @@ impl ProcMacroClient { | |||
82 | ProcMacroClient { kind: ProcMacroClientKind::Dummy } | 83 | ProcMacroClient { kind: ProcMacroClientKind::Dummy } |
83 | } | 84 | } |
84 | 85 | ||
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> { |
86 | match &self.kind { | 87 | match &self.kind { |
87 | ProcMacroClientKind::Dummy => vec![], | 88 | ProcMacroClientKind::Dummy => vec![], |
88 | ProcMacroClientKind::Process { process, .. } => { | 89 | ProcMacroClientKind::Process { process, .. } => { |
@@ -96,21 +97,21 @@ impl ProcMacroClient { | |||
96 | 97 | ||
97 | macros | 98 | macros |
98 | .into_iter() | 99 | .into_iter() |
99 | .filter_map(|(name, kind)| { | 100 | .map(|(name, kind)| { |
100 | match kind { | 101 | let name = SmolStr::new(&name); |
101 | ProcMacroKind::CustomDerive | ProcMacroKind::FuncLike => { | 102 | let kind = match kind { |
102 | let name = SmolStr::new(&name); | 103 | ProcMacroKind::CustomDerive => base_db::ProcMacroKind::CustomDerive, |
103 | let expander: Arc<dyn tt::TokenExpander> = | 104 | ProcMacroKind::FuncLike => base_db::ProcMacroKind::FuncLike, |
104 | Arc::new(ProcMacroProcessExpander { | 105 | ProcMacroKind::Attr => base_db::ProcMacroKind::Attr, |
105 | process: process.clone(), | 106 | }; |
106 | name: name.clone(), | 107 | let expander: Arc<dyn tt::TokenExpander> = |
107 | dylib_path: dylib_path.into(), | 108 | Arc::new(ProcMacroProcessExpander { |
108 | }); | 109 | process: process.clone(), |
109 | Some((name, expander)) | 110 | name: name.clone(), |
110 | } | 111 | dylib_path: dylib_path.into(), |
111 | // FIXME: Attribute macro are currently unsupported. | 112 | }); |
112 | ProcMacroKind::Attr => None, | 113 | |
113 | } | 114 | ProcMacro { name, kind, expander } |
114 | }) | 115 | }) |
115 | .collect() | 116 | .collect() |
116 | } | 117 | } |
diff --git a/crates/proc_macro_api/src/rpc.rs b/crates/proc_macro_api/src/rpc.rs index 203109ca4..b85f92eea 100644 --- a/crates/proc_macro_api/src/rpc.rs +++ b/crates/proc_macro_api/src/rpc.rs | |||
@@ -19,7 +19,7 @@ pub struct ListMacrosTask { | |||
19 | pub lib: PathBuf, | 19 | pub lib: PathBuf, |
20 | } | 20 | } |
21 | 21 | ||
22 | #[derive(Clone, Eq, PartialEq, Debug, Serialize, Deserialize)] | 22 | #[derive(Copy, Clone, Eq, PartialEq, Debug, Serialize, Deserialize)] |
23 | pub enum ProcMacroKind { | 23 | pub enum ProcMacroKind { |
24 | CustomDerive, | 24 | CustomDerive, |
25 | FuncLike, | 25 | FuncLike, |