diff options
Diffstat (limited to 'crates/ra_hir/src/nameres/raw.rs')
-rw-r--r-- | crates/ra_hir/src/nameres/raw.rs | 43 |
1 files changed, 4 insertions, 39 deletions
diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs index 5f93f920f..57f2929c3 100644 --- a/crates/ra_hir/src/nameres/raw.rs +++ b/crates/ra_hir/src/nameres/raw.rs | |||
@@ -5,7 +5,7 @@ use std::{ops::Index, sync::Arc}; | |||
5 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; | 5 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; |
6 | use ra_syntax::{ | 6 | use ra_syntax::{ |
7 | ast::{self, AttrsOwner, NameOwner}, | 7 | ast::{self, AttrsOwner, NameOwner}, |
8 | AstNode, AstPtr, SmolStr, SourceFile, | 8 | AstNode, AstPtr, SourceFile, |
9 | }; | 9 | }; |
10 | use test_utils::tested_by; | 10 | use test_utils::tested_by; |
11 | 11 | ||
@@ -149,19 +149,8 @@ impl_arena_id!(Module); | |||
149 | 149 | ||
150 | #[derive(Debug, PartialEq, Eq)] | 150 | #[derive(Debug, PartialEq, Eq)] |
151 | pub(super) enum ModuleData { | 151 | pub(super) enum ModuleData { |
152 | Declaration { | 152 | Declaration { name: Name, ast_id: FileAstId<ast::Module> }, |
153 | name: Name, | 153 | Definition { name: Name, ast_id: FileAstId<ast::Module>, items: Vec<RawItem> }, |
154 | ast_id: FileAstId<ast::Module>, | ||
155 | attr_path: Option<SmolStr>, | ||
156 | is_macro_use: bool, | ||
157 | }, | ||
158 | Definition { | ||
159 | name: Name, | ||
160 | ast_id: FileAstId<ast::Module>, | ||
161 | items: Vec<RawItem>, | ||
162 | attr_path: Option<SmolStr>, | ||
163 | is_macro_use: bool, | ||
164 | }, | ||
165 | } | 154 | } |
166 | 155 | ||
167 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 156 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -292,28 +281,17 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> { | |||
292 | let attrs = self.parse_attrs(&module); | 281 | let attrs = self.parse_attrs(&module); |
293 | 282 | ||
294 | let ast_id = self.source_ast_id_map.ast_id(&module); | 283 | let ast_id = self.source_ast_id_map.ast_id(&module); |
295 | // FIXME: cfg_attr | ||
296 | let is_macro_use = module.has_atom_attr("macro_use"); | ||
297 | if module.has_semi() { | 284 | if module.has_semi() { |
298 | let attr_path = extract_mod_path_attribute(&module); | 285 | let item = self.raw_items.modules.alloc(ModuleData::Declaration { name, ast_id }); |
299 | let item = self.raw_items.modules.alloc(ModuleData::Declaration { | ||
300 | name, | ||
301 | ast_id, | ||
302 | attr_path, | ||
303 | is_macro_use, | ||
304 | }); | ||
305 | self.push_item(current_module, attrs, RawItemKind::Module(item)); | 286 | self.push_item(current_module, attrs, RawItemKind::Module(item)); |
306 | return; | 287 | return; |
307 | } | 288 | } |
308 | 289 | ||
309 | if let Some(item_list) = module.item_list() { | 290 | if let Some(item_list) = module.item_list() { |
310 | let attr_path = extract_mod_path_attribute(&module); | ||
311 | let item = self.raw_items.modules.alloc(ModuleData::Definition { | 291 | let item = self.raw_items.modules.alloc(ModuleData::Definition { |
312 | name, | 292 | name, |
313 | ast_id, | 293 | ast_id, |
314 | items: Vec::new(), | 294 | items: Vec::new(), |
315 | attr_path, | ||
316 | is_macro_use, | ||
317 | }); | 295 | }); |
318 | self.process_module(Some(item), item_list); | 296 | self.process_module(Some(item), item_list); |
319 | self.push_item(current_module, attrs, RawItemKind::Module(item)); | 297 | self.push_item(current_module, attrs, RawItemKind::Module(item)); |
@@ -423,16 +401,3 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> { | |||
423 | Attr::from_attrs_owner(self.file_id, item, self.db) | 401 | Attr::from_attrs_owner(self.file_id, item, self.db) |
424 | } | 402 | } |
425 | } | 403 | } |
426 | |||
427 | fn extract_mod_path_attribute(module: &ast::Module) -> Option<SmolStr> { | ||
428 | module.attrs().into_iter().find_map(|attr| { | ||
429 | attr.as_simple_key_value().and_then(|(name, value)| { | ||
430 | let is_path = name == "path"; | ||
431 | if is_path { | ||
432 | Some(value) | ||
433 | } else { | ||
434 | None | ||
435 | } | ||
436 | }) | ||
437 | }) | ||
438 | } | ||