diff options
Diffstat (limited to 'crates/ra_hir_def/src/nameres')
-rw-r--r-- | crates/ra_hir_def/src/nameres/raw.rs | 55 |
1 files changed, 24 insertions, 31 deletions
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index 86b4fef96..86c05d602 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -2,21 +2,20 @@ | |||
2 | 2 | ||
3 | use std::{ops::Index, sync::Arc}; | 3 | use std::{ops::Index, sync::Arc}; |
4 | 4 | ||
5 | use hir_expand::{ast_id_map::AstIdMap, db::AstDatabase}; | 5 | use hir_expand::{ |
6 | ast_id_map::AstIdMap, | ||
7 | db::AstDatabase, | ||
8 | either::Either, | ||
9 | hygiene::Hygiene, | ||
10 | name::{AsName, Name}, | ||
11 | }; | ||
6 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; | 12 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; |
7 | use ra_syntax::{ | 13 | use ra_syntax::{ |
8 | ast::{self, AttrsOwner, NameOwner}, | 14 | ast::{self, AttrsOwner, NameOwner}, |
9 | AstNode, AstPtr, SourceFile, | 15 | AstNode, AstPtr, SourceFile, |
10 | }; | 16 | }; |
11 | 17 | ||
12 | use crate::{ | 18 | use crate::{attr::Attr, db::DefDatabase2, path::Path, FileAstId, HirFileId, ModuleSource, Source}; |
13 | attr::Attr, | ||
14 | db::DefDatabase2, | ||
15 | either::Either, | ||
16 | name::{AsName, Name}, | ||
17 | path::Path, | ||
18 | FileAstId, HirFileId, ModuleSource, Source, | ||
19 | }; | ||
20 | 19 | ||
21 | /// `RawItems` is a set of top-level items in a file (except for impls). | 20 | /// `RawItems` is a set of top-level items in a file (except for impls). |
22 | /// | 21 | /// |
@@ -40,10 +39,8 @@ pub struct ImportSourceMap { | |||
40 | type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>; | 39 | type ImportSourcePtr = Either<AstPtr<ast::UseTree>, AstPtr<ast::ExternCrateItem>>; |
41 | type ImportSource = Either<ast::UseTree, ast::ExternCrateItem>; | 40 | type ImportSource = Either<ast::UseTree, ast::ExternCrateItem>; |
42 | 41 | ||
43 | impl ImportSourcePtr { | 42 | fn to_node(ptr: ImportSourcePtr, file: &SourceFile) -> ImportSource { |
44 | fn to_node(self, file: &SourceFile) -> ImportSource { | 43 | ptr.map(|ptr| ptr.to_node(file.syntax()), |ptr| ptr.to_node(file.syntax())) |
45 | self.map(|ptr| ptr.to_node(file.syntax()), |ptr| ptr.to_node(file.syntax())) | ||
46 | } | ||
47 | } | 44 | } |
48 | 45 | ||
49 | impl ImportSourceMap { | 46 | impl ImportSourceMap { |
@@ -57,7 +54,7 @@ impl ImportSourceMap { | |||
57 | ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(), | 54 | ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(), |
58 | }; | 55 | }; |
59 | 56 | ||
60 | self.map[import].to_node(&file) | 57 | to_node(self.map[import], &file) |
61 | } | 58 | } |
62 | } | 59 | } |
63 | 60 | ||
@@ -78,7 +75,7 @@ impl RawItems { | |||
78 | source_ast_id_map: db.ast_id_map(file_id), | 75 | source_ast_id_map: db.ast_id_map(file_id), |
79 | source_map: ImportSourceMap::default(), | 76 | source_map: ImportSourceMap::default(), |
80 | file_id, | 77 | file_id, |
81 | db, | 78 | hygiene: Hygiene::new(db, file_id), |
82 | }; | 79 | }; |
83 | if let Some(node) = db.parse_or_expand(file_id) { | 80 | if let Some(node) = db.parse_or_expand(file_id) { |
84 | if let Some(source_file) = ast::SourceFile::cast(node.clone()) { | 81 | if let Some(source_file) = ast::SourceFile::cast(node.clone()) { |
@@ -204,15 +201,15 @@ pub struct MacroData { | |||
204 | pub export: bool, | 201 | pub export: bool, |
205 | } | 202 | } |
206 | 203 | ||
207 | struct RawItemsCollector<DB> { | 204 | struct RawItemsCollector { |
208 | raw_items: RawItems, | 205 | raw_items: RawItems, |
209 | source_ast_id_map: Arc<AstIdMap>, | 206 | source_ast_id_map: Arc<AstIdMap>, |
210 | source_map: ImportSourceMap, | 207 | source_map: ImportSourceMap, |
211 | file_id: HirFileId, | 208 | file_id: HirFileId, |
212 | db: DB, | 209 | hygiene: Hygiene, |
213 | } | 210 | } |
214 | 211 | ||
215 | impl<DB: AstDatabase> RawItemsCollector<&DB> { | 212 | impl RawItemsCollector { |
216 | fn process_module(&mut self, current_module: Option<Module>, body: impl ast::ModuleItemOwner) { | 213 | fn process_module(&mut self, current_module: Option<Module>, body: impl ast::ModuleItemOwner) { |
217 | for item_or_macro in body.items_with_macros() { | 214 | for item_or_macro in body.items_with_macros() { |
218 | match item_or_macro { | 215 | match item_or_macro { |
@@ -309,9 +306,10 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> { | |||
309 | let is_prelude = use_item.has_atom_attr("prelude_import"); | 306 | let is_prelude = use_item.has_atom_attr("prelude_import"); |
310 | let attrs = self.parse_attrs(&use_item); | 307 | let attrs = self.parse_attrs(&use_item); |
311 | 308 | ||
309 | let mut buf = Vec::new(); | ||
312 | Path::expand_use_item( | 310 | Path::expand_use_item( |
313 | Source { ast: use_item, file_id: self.file_id }, | 311 | Source { ast: use_item, file_id: self.file_id }, |
314 | self.db, | 312 | &self.hygiene, |
315 | |path, use_tree, is_glob, alias| { | 313 | |path, use_tree, is_glob, alias| { |
316 | let import_data = ImportData { | 314 | let import_data = ImportData { |
317 | path, | 315 | path, |
@@ -321,14 +319,12 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> { | |||
321 | is_extern_crate: false, | 319 | is_extern_crate: false, |
322 | is_macro_use: false, | 320 | is_macro_use: false, |
323 | }; | 321 | }; |
324 | self.push_import( | 322 | buf.push((import_data, Either::A(AstPtr::new(use_tree)))); |
325 | current_module, | ||
326 | attrs.clone(), | ||
327 | import_data, | ||
328 | Either::A(AstPtr::new(use_tree)), | ||
329 | ); | ||
330 | }, | 323 | }, |
331 | ) | 324 | ); |
325 | for (import_data, ptr) in buf { | ||
326 | self.push_import(current_module, attrs.clone(), import_data, ptr); | ||
327 | } | ||
332 | } | 328 | } |
333 | 329 | ||
334 | fn add_extern_crate_item( | 330 | fn add_extern_crate_item( |
@@ -361,10 +357,7 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> { | |||
361 | 357 | ||
362 | fn add_macro(&mut self, current_module: Option<Module>, m: ast::MacroCall) { | 358 | fn add_macro(&mut self, current_module: Option<Module>, m: ast::MacroCall) { |
363 | let attrs = self.parse_attrs(&m); | 359 | let attrs = self.parse_attrs(&m); |
364 | let path = match m | 360 | let path = match m.path().and_then(|path| Path::from_src(path, &self.hygiene)) { |
365 | .path() | ||
366 | .and_then(|path| Path::from_src(Source { ast: path, file_id: self.file_id }, self.db)) | ||
367 | { | ||
368 | Some(it) => it, | 361 | Some(it) => it, |
369 | _ => return, | 362 | _ => return, |
370 | }; | 363 | }; |
@@ -402,6 +395,6 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> { | |||
402 | } | 395 | } |
403 | 396 | ||
404 | fn parse_attrs(&self, item: &impl ast::AttrsOwner) -> Attrs { | 397 | fn parse_attrs(&self, item: &impl ast::AttrsOwner) -> Attrs { |
405 | Attr::from_attrs_owner(self.file_id, item, self.db) | 398 | Attr::from_attrs_owner(item, &self.hygiene) |
406 | } | 399 | } |
407 | } | 400 | } |