aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authoruHOOCCOOHu <[email protected]>2019-08-29 18:56:00 +0100
committeruHOOCCOOHu <[email protected]>2019-08-31 18:54:41 +0100
commitf5bea9051b81f3a490c08afdb336c63c9180aae0 (patch)
treedca2027e759bbaeaa116b1cae828cd28d507f6e3 /crates
parentf2a200c1ee8016f47b35e2e13a899fc96286a1eb (diff)
Support resolution of `#[macro_use] extern crate`
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/nameres/collector.rs17
-rw-r--r--crates/ra_hir/src/nameres/raw.rs13
-rw-r--r--crates/ra_syntax/src/ast/generated.rs1
-rw-r--r--crates/ra_syntax/src/grammar.ron1
4 files changed, 30 insertions, 2 deletions
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs
index 7da2dcdff..26158b5c3 100644
--- a/crates/ra_hir/src/nameres/collector.rs
+++ b/crates/ra_hir/src/nameres/collector.rs
@@ -295,6 +295,23 @@ where
295 } 295 }
296 } 296 }
297 297
298 // `#[macro_use] extern crate` glob import macros
299 if import.is_extern_crate && import.is_macro_use {
300 if let Some(ModuleDef::Module(m)) =
301 def.a().and_then(|item| item.take_types())
302 {
303 let item_map = self.db.crate_def_map(m.krate);
304 let scope = &item_map[m.module_id].scope;
305 let macros = scope
306 .macros
307 .iter()
308 .map(|(name, res)| (name.clone(), Either::B(*res)))
309 .collect::<Vec<_>>();
310
311 self.update(module_id, Some(import_id), &macros);
312 }
313 }
314
298 let resolution = match def { 315 let resolution = match def {
299 Either::A(item) => { 316 Either::A(item) => {
300 Either::A(Resolution { def: item, import: Some(import_id) }) 317 Either::A(Resolution { def: item, import: Some(import_id) })
diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs
index 2f973359f..129b047eb 100644
--- a/crates/ra_hir/src/nameres/raw.rs
+++ b/crates/ra_hir/src/nameres/raw.rs
@@ -154,6 +154,7 @@ pub struct ImportData {
154 pub(super) is_glob: bool, 154 pub(super) is_glob: bool,
155 pub(super) is_prelude: bool, 155 pub(super) is_prelude: bool,
156 pub(super) is_extern_crate: bool, 156 pub(super) is_extern_crate: bool,
157 pub(super) is_macro_use: bool,
157} 158}
158 159
159#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 160#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -293,8 +294,14 @@ impl RawItemsCollector {
293 let is_prelude = use_item.has_atom_attr("prelude_import"); 294 let is_prelude = use_item.has_atom_attr("prelude_import");
294 295
295 Path::expand_use_item(&use_item, |path, use_tree, is_glob, alias| { 296 Path::expand_use_item(&use_item, |path, use_tree, is_glob, alias| {
296 let import_data = 297 let import_data = ImportData {
297 ImportData { path, alias, is_glob, is_prelude, is_extern_crate: false }; 298 path,
299 alias,
300 is_glob,
301 is_prelude,
302 is_extern_crate: false,
303 is_macro_use: false,
304 };
298 self.push_import(current_module, import_data, Either::A(AstPtr::new(use_tree))); 305 self.push_import(current_module, import_data, Either::A(AstPtr::new(use_tree)));
299 }) 306 })
300 } 307 }
@@ -307,12 +314,14 @@ impl RawItemsCollector {
307 if let Some(name_ref) = extern_crate.name_ref() { 314 if let Some(name_ref) = extern_crate.name_ref() {
308 let path = Path::from_name_ref(&name_ref); 315 let path = Path::from_name_ref(&name_ref);
309 let alias = extern_crate.alias().and_then(|a| a.name()).map(|it| it.as_name()); 316 let alias = extern_crate.alias().and_then(|a| a.name()).map(|it| it.as_name());
317 let is_macro_use = extern_crate.has_atom_attr("macro_use");
310 let import_data = ImportData { 318 let import_data = ImportData {
311 path, 319 path,
312 alias, 320 alias,
313 is_glob: false, 321 is_glob: false,
314 is_prelude: false, 322 is_prelude: false,
315 is_extern_crate: true, 323 is_extern_crate: true,
324 is_macro_use,
316 }; 325 };
317 self.push_import(current_module, import_data, Either::B(AstPtr::new(&extern_crate))); 326 self.push_import(current_module, import_data, Either::B(AstPtr::new(&extern_crate)));
318 } 327 }
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index 90480b6ca..d161470e7 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -934,6 +934,7 @@ impl AstNode for ExternCrateItem {
934 &self.syntax 934 &self.syntax
935 } 935 }
936} 936}
937impl ast::AttrsOwner for ExternCrateItem {}
937impl ExternCrateItem { 938impl ExternCrateItem {
938 pub fn name_ref(&self) -> Option<NameRef> { 939 pub fn name_ref(&self) -> Option<NameRef> {
939 AstChildren::new(&self.syntax).next() 940 AstChildren::new(&self.syntax).next()
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron
index 1836862fe..a07293a46 100644
--- a/crates/ra_syntax/src/grammar.ron
+++ b/crates/ra_syntax/src/grammar.ron
@@ -669,6 +669,7 @@ Grammar(
669 collections: [("use_trees", "UseTree")] 669 collections: [("use_trees", "UseTree")]
670 ), 670 ),
671 "ExternCrateItem": ( 671 "ExternCrateItem": (
672 traits: ["AttrsOwner"],
672 options: ["NameRef", "Alias"], 673 options: ["NameRef", "Alias"],
673 ), 674 ),
674 "ArgList": ( 675 "ArgList": (