diff options
author | Aleksey Kladov <[email protected]> | 2019-10-30 15:41:50 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-10-30 15:41:50 +0000 |
commit | 0bc7d285189caaffc13e4d6856baf895f72ed80c (patch) | |
tree | 792693f3b35d2a23107ee5a1e4bbb13bc2806c41 /crates/ra_hir_def/src/nameres | |
parent | e34e71c62d9b4cf0ab237969e03ecde893ab347b (diff) |
refactor $crate handling
Introduce proper hygiene module, which should grow quite a bit
eventually.
Diffstat (limited to 'crates/ra_hir_def/src/nameres')
-rw-r--r-- | crates/ra_hir_def/src/nameres/raw.rs | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index 86b4fef96..636364628 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -13,6 +13,7 @@ use crate::{ | |||
13 | attr::Attr, | 13 | attr::Attr, |
14 | db::DefDatabase2, | 14 | db::DefDatabase2, |
15 | either::Either, | 15 | either::Either, |
16 | hygiene::Hygiene, | ||
16 | name::{AsName, Name}, | 17 | name::{AsName, Name}, |
17 | path::Path, | 18 | path::Path, |
18 | FileAstId, HirFileId, ModuleSource, Source, | 19 | FileAstId, HirFileId, ModuleSource, Source, |
@@ -78,7 +79,7 @@ impl RawItems { | |||
78 | source_ast_id_map: db.ast_id_map(file_id), | 79 | source_ast_id_map: db.ast_id_map(file_id), |
79 | source_map: ImportSourceMap::default(), | 80 | source_map: ImportSourceMap::default(), |
80 | file_id, | 81 | file_id, |
81 | db, | 82 | hygiene: Hygiene::new(db, file_id), |
82 | }; | 83 | }; |
83 | if let Some(node) = db.parse_or_expand(file_id) { | 84 | if let Some(node) = db.parse_or_expand(file_id) { |
84 | if let Some(source_file) = ast::SourceFile::cast(node.clone()) { | 85 | if let Some(source_file) = ast::SourceFile::cast(node.clone()) { |
@@ -204,15 +205,15 @@ pub struct MacroData { | |||
204 | pub export: bool, | 205 | pub export: bool, |
205 | } | 206 | } |
206 | 207 | ||
207 | struct RawItemsCollector<DB> { | 208 | struct RawItemsCollector { |
208 | raw_items: RawItems, | 209 | raw_items: RawItems, |
209 | source_ast_id_map: Arc<AstIdMap>, | 210 | source_ast_id_map: Arc<AstIdMap>, |
210 | source_map: ImportSourceMap, | 211 | source_map: ImportSourceMap, |
211 | file_id: HirFileId, | 212 | file_id: HirFileId, |
212 | db: DB, | 213 | hygiene: Hygiene, |
213 | } | 214 | } |
214 | 215 | ||
215 | impl<DB: AstDatabase> RawItemsCollector<&DB> { | 216 | impl RawItemsCollector { |
216 | fn process_module(&mut self, current_module: Option<Module>, body: impl ast::ModuleItemOwner) { | 217 | fn process_module(&mut self, current_module: Option<Module>, body: impl ast::ModuleItemOwner) { |
217 | for item_or_macro in body.items_with_macros() { | 218 | for item_or_macro in body.items_with_macros() { |
218 | match item_or_macro { | 219 | match item_or_macro { |
@@ -309,9 +310,10 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> { | |||
309 | let is_prelude = use_item.has_atom_attr("prelude_import"); | 310 | let is_prelude = use_item.has_atom_attr("prelude_import"); |
310 | let attrs = self.parse_attrs(&use_item); | 311 | let attrs = self.parse_attrs(&use_item); |
311 | 312 | ||
313 | let mut buf = Vec::new(); | ||
312 | Path::expand_use_item( | 314 | Path::expand_use_item( |
313 | Source { ast: use_item, file_id: self.file_id }, | 315 | Source { ast: use_item, file_id: self.file_id }, |
314 | self.db, | 316 | &self.hygiene, |
315 | |path, use_tree, is_glob, alias| { | 317 | |path, use_tree, is_glob, alias| { |
316 | let import_data = ImportData { | 318 | let import_data = ImportData { |
317 | path, | 319 | path, |
@@ -321,14 +323,12 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> { | |||
321 | is_extern_crate: false, | 323 | is_extern_crate: false, |
322 | is_macro_use: false, | 324 | is_macro_use: false, |
323 | }; | 325 | }; |
324 | self.push_import( | 326 | 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 | }, | 327 | }, |
331 | ) | 328 | ); |
329 | for (import_data, ptr) in buf { | ||
330 | self.push_import(current_module, attrs.clone(), import_data, ptr); | ||
331 | } | ||
332 | } | 332 | } |
333 | 333 | ||
334 | fn add_extern_crate_item( | 334 | fn add_extern_crate_item( |
@@ -361,10 +361,7 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> { | |||
361 | 361 | ||
362 | fn add_macro(&mut self, current_module: Option<Module>, m: ast::MacroCall) { | 362 | fn add_macro(&mut self, current_module: Option<Module>, m: ast::MacroCall) { |
363 | let attrs = self.parse_attrs(&m); | 363 | let attrs = self.parse_attrs(&m); |
364 | let path = match m | 364 | 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, | 365 | Some(it) => it, |
369 | _ => return, | 366 | _ => return, |
370 | }; | 367 | }; |
@@ -402,6 +399,6 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> { | |||
402 | } | 399 | } |
403 | 400 | ||
404 | fn parse_attrs(&self, item: &impl ast::AttrsOwner) -> Attrs { | 401 | fn parse_attrs(&self, item: &impl ast::AttrsOwner) -> Attrs { |
405 | Attr::from_attrs_owner(self.file_id, item, self.db) | 402 | Attr::from_attrs_owner(item, &self.hygiene) |
406 | } | 403 | } |
407 | } | 404 | } |