diff options
Diffstat (limited to 'crates/ra_hir/src/nameres/raw.rs')
-rw-r--r-- | crates/ra_hir/src/nameres/raw.rs | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs index 29aaddbf1..c607b8a11 100644 --- a/crates/ra_hir/src/nameres/raw.rs +++ b/crates/ra_hir/src/nameres/raw.rs | |||
@@ -9,7 +9,7 @@ use test_utils::tested_by; | |||
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | db::{AstDatabase, DefDatabase}, | 11 | db::{AstDatabase, DefDatabase}, |
12 | AsName, AstIdMap, Either, FileAstId, HirFileId, ModuleSource, Name, Path, | 12 | AsName, AstIdMap, Either, FileAstId, HirFileId, ModuleSource, Name, Path, Source, |
13 | }; | 13 | }; |
14 | 14 | ||
15 | /// `RawItems` is a set of top-level items in a file (except for impls). | 15 | /// `RawItems` is a set of top-level items in a file (except for impls). |
@@ -71,6 +71,8 @@ impl RawItems { | |||
71 | raw_items: RawItems::default(), | 71 | raw_items: RawItems::default(), |
72 | source_ast_id_map: db.ast_id_map(file_id), | 72 | source_ast_id_map: db.ast_id_map(file_id), |
73 | source_map: ImportSourceMap::default(), | 73 | source_map: ImportSourceMap::default(), |
74 | file_id, | ||
75 | db, | ||
74 | }; | 76 | }; |
75 | if let Some(node) = db.parse_or_expand(file_id) { | 77 | if let Some(node) = db.parse_or_expand(file_id) { |
76 | if let Some(source_file) = ast::SourceFile::cast(node.clone()) { | 78 | if let Some(source_file) = ast::SourceFile::cast(node.clone()) { |
@@ -192,13 +194,15 @@ pub(super) struct MacroData { | |||
192 | pub(super) export: bool, | 194 | pub(super) export: bool, |
193 | } | 195 | } |
194 | 196 | ||
195 | struct RawItemsCollector { | 197 | struct RawItemsCollector<DB> { |
196 | raw_items: RawItems, | 198 | raw_items: RawItems, |
197 | source_ast_id_map: Arc<AstIdMap>, | 199 | source_ast_id_map: Arc<AstIdMap>, |
198 | source_map: ImportSourceMap, | 200 | source_map: ImportSourceMap, |
201 | file_id: HirFileId, | ||
202 | db: DB, | ||
199 | } | 203 | } |
200 | 204 | ||
201 | impl RawItemsCollector { | 205 | impl<DB: AstDatabase> RawItemsCollector<&'_ DB> { |
202 | fn process_module(&mut self, current_module: Option<Module>, body: impl ast::ModuleItemOwner) { | 206 | fn process_module(&mut self, current_module: Option<Module>, body: impl ast::ModuleItemOwner) { |
203 | for item_or_macro in body.items_with_macros() { | 207 | for item_or_macro in body.items_with_macros() { |
204 | match item_or_macro { | 208 | match item_or_macro { |
@@ -300,17 +304,21 @@ impl RawItemsCollector { | |||
300 | fn add_use_item(&mut self, current_module: Option<Module>, use_item: ast::UseItem) { | 304 | fn add_use_item(&mut self, current_module: Option<Module>, use_item: ast::UseItem) { |
301 | let is_prelude = use_item.has_atom_attr("prelude_import"); | 305 | let is_prelude = use_item.has_atom_attr("prelude_import"); |
302 | 306 | ||
303 | Path::expand_use_item(&use_item, |path, use_tree, is_glob, alias| { | 307 | Path::expand_use_item( |
304 | let import_data = ImportData { | 308 | Source { ast: use_item, file_id: self.file_id }, |
305 | path, | 309 | self.db, |
306 | alias, | 310 | |path, use_tree, is_glob, alias| { |
307 | is_glob, | 311 | let import_data = ImportData { |
308 | is_prelude, | 312 | path, |
309 | is_extern_crate: false, | 313 | alias, |
310 | is_macro_use: false, | 314 | is_glob, |
311 | }; | 315 | is_prelude, |
312 | self.push_import(current_module, import_data, Either::A(AstPtr::new(use_tree))); | 316 | is_extern_crate: false, |
313 | }) | 317 | is_macro_use: false, |
318 | }; | ||
319 | self.push_import(current_module, import_data, Either::A(AstPtr::new(use_tree))); | ||
320 | }, | ||
321 | ) | ||
314 | } | 322 | } |
315 | 323 | ||
316 | fn add_extern_crate_item( | 324 | fn add_extern_crate_item( |
@@ -335,7 +343,10 @@ impl RawItemsCollector { | |||
335 | } | 343 | } |
336 | 344 | ||
337 | fn add_macro(&mut self, current_module: Option<Module>, m: ast::MacroCall) { | 345 | fn add_macro(&mut self, current_module: Option<Module>, m: ast::MacroCall) { |
338 | let path = match m.path().and_then(Path::from_ast) { | 346 | let path = match m |
347 | .path() | ||
348 | .and_then(|path| Path::from_src(Source { ast: path, file_id: self.file_id }, self.db)) | ||
349 | { | ||
339 | Some(it) => it, | 350 | Some(it) => it, |
340 | _ => return, | 351 | _ => return, |
341 | }; | 352 | }; |