aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs46
1 files changed, 23 insertions, 23 deletions
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index 1dcf5a309..9c125f32f 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -65,6 +65,9 @@ pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: CrateDefMap) -> Cr
65 unexpanded_attribute_macros: Vec::new(), 65 unexpanded_attribute_macros: Vec::new(),
66 mod_dirs: FxHashMap::default(), 66 mod_dirs: FxHashMap::default(),
67 cfg_options, 67 cfg_options,
68
69 // FIXME: pass proc-macro from crate-graph
70 proc_macros: Default::default(),
68 }; 71 };
69 collector.collect(); 72 collector.collect();
70 collector.finish() 73 collector.finish()
@@ -123,6 +126,7 @@ struct DefCollector<'a> {
123 unexpanded_attribute_macros: Vec<DeriveDirective>, 126 unexpanded_attribute_macros: Vec<DeriveDirective>,
124 mod_dirs: FxHashMap<LocalModuleId, ModDir>, 127 mod_dirs: FxHashMap<LocalModuleId, ModDir>,
125 cfg_options: &'a CfgOptions, 128 cfg_options: &'a CfgOptions,
129 proc_macros: Vec<(Name, ProcMacroExpander)>,
126} 130}
127 131
128impl DefCollector<'_> { 132impl DefCollector<'_> {
@@ -178,6 +182,24 @@ impl DefCollector<'_> {
178 for directive in unresolved_imports { 182 for directive in unresolved_imports {
179 self.record_resolved_import(&directive) 183 self.record_resolved_import(&directive)
180 } 184 }
185
186 // Record proc-macros
187 self.collect_proc_macro();
188 }
189
190 fn collect_proc_macro(&mut self) {
191 let proc_macros = std::mem::take(&mut self.proc_macros);
192 for (name, expander) in proc_macros {
193 let krate = self.def_map.krate;
194
195 let macro_id = MacroDefId {
196 ast_id: None,
197 krate: Some(krate),
198 kind: MacroDefKind::CustomDerive(expander),
199 };
200
201 self.define_proc_macro(name.clone(), macro_id);
202 }
181 } 203 }
182 204
183 /// Define a macro with `macro_rules`. 205 /// Define a macro with `macro_rules`.
@@ -801,7 +823,6 @@ impl ModCollector<'_, '_> {
801 // in which case we don't add the invocation, just a single attribute 823 // in which case we don't add the invocation, just a single attribute
802 // macro invocation 824 // macro invocation
803 self.collect_derives(attrs, def); 825 self.collect_derives(attrs, def);
804 self.collect_proc_macro(attrs);
805 826
806 let name = def.name.clone(); 827 let name = def.name.clone();
807 let container = ContainerId::ModuleId(module); 828 let container = ContainerId::ModuleId(module);
@@ -878,28 +899,6 @@ impl ModCollector<'_, '_> {
878 } 899 }
879 } 900 }
880 901
881 fn collect_proc_macro(&mut self, attrs: &Attrs) {
882 if let Some(derive_subtree) = attrs.by_key("proc_macro_derive").tt_values().next() {
883 if let Some(tt) = derive_subtree.token_trees.get(0) {
884 let ident = match &tt {
885 tt::TokenTree::Leaf(tt::Leaf::Ident(ident)) => ident,
886 _ => return, // anything else would be an error (which we currently ignore)
887 };
888 let name = ident.as_name();
889 let krate = self.def_collector.def_map.krate;
890 let expander = ProcMacroExpander::new(krate);
891
892 let macro_id = MacroDefId {
893 ast_id: None,
894 krate: Some(krate),
895 kind: MacroDefKind::CustomDerive(expander),
896 };
897
898 self.def_collector.define_proc_macro(name.clone(), macro_id);
899 }
900 }
901 }
902
903 fn collect_macro(&mut self, mac: &raw::MacroData) { 902 fn collect_macro(&mut self, mac: &raw::MacroData) {
904 let mut ast_id = AstIdWithPath::new(self.file_id, mac.ast_id, mac.path.clone()); 903 let mut ast_id = AstIdWithPath::new(self.file_id, mac.ast_id, mac.path.clone());
905 904
@@ -1001,6 +1000,7 @@ mod tests {
1001 unexpanded_attribute_macros: Vec::new(), 1000 unexpanded_attribute_macros: Vec::new(),
1002 mod_dirs: FxHashMap::default(), 1001 mod_dirs: FxHashMap::default(),
1003 cfg_options: &CfgOptions::default(), 1002 cfg_options: &CfgOptions::default(),
1003 proc_macros: Default::default(),
1004 }; 1004 };
1005 collector.collect(); 1005 collector.collect();
1006 collector.def_map 1006 collector.def_map