aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/nameres/raw.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/nameres/raw.rs')
-rw-r--r--crates/ra_hir/src/nameres/raw.rs22
1 files changed, 19 insertions, 3 deletions
diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs
index 7ea59cb75..46b2bef5b 100644
--- a/crates/ra_hir/src/nameres/raw.rs
+++ b/crates/ra_hir/src/nameres/raw.rs
@@ -3,7 +3,7 @@ use std::{ops::Index, sync::Arc};
3use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; 3use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId};
4use ra_syntax::{ 4use ra_syntax::{
5 ast::{self, AttrsOwner, NameOwner}, 5 ast::{self, AttrsOwner, NameOwner},
6 AstNode, AstPtr, SourceFile, TreeArc, 6 AstNode, AstPtr, SmolStr, SourceFile, TreeArc,
7}; 7};
8use test_utils::tested_by; 8use test_utils::tested_by;
9 9
@@ -130,7 +130,7 @@ impl_arena_id!(Module);
130 130
131#[derive(Debug, PartialEq, Eq)] 131#[derive(Debug, PartialEq, Eq)]
132pub(super) enum ModuleData { 132pub(super) enum ModuleData {
133 Declaration { name: Name, ast_id: FileAstId<ast::Module> }, 133 Declaration { name: Name, ast_id: FileAstId<ast::Module>, attr_path: Option<SmolStr> },
134 Definition { name: Name, ast_id: FileAstId<ast::Module>, items: Vec<RawItem> }, 134 Definition { name: Name, ast_id: FileAstId<ast::Module>, items: Vec<RawItem> },
135} 135}
136 136
@@ -255,9 +255,12 @@ impl RawItemsCollector {
255 Some(it) => it.as_name(), 255 Some(it) => it.as_name(),
256 None => return, 256 None => return,
257 }; 257 };
258
259 let attr_path = extract_mod_path_attribute(module);
258 let ast_id = self.source_ast_id_map.ast_id(module); 260 let ast_id = self.source_ast_id_map.ast_id(module);
259 if module.has_semi() { 261 if module.has_semi() {
260 let item = self.raw_items.modules.alloc(ModuleData::Declaration { name, ast_id }); 262 let item =
263 self.raw_items.modules.alloc(ModuleData::Declaration { name, ast_id, attr_path });
261 self.push_item(current_module, RawItem::Module(item)); 264 self.push_item(current_module, RawItem::Module(item));
262 return; 265 return;
263 } 266 }
@@ -339,3 +342,16 @@ impl RawItemsCollector {
339 .push(item) 342 .push(item)
340 } 343 }
341} 344}
345
346fn extract_mod_path_attribute(module: &ast::Module) -> Option<SmolStr> {
347 module.attrs().into_iter().find_map(|attr| {
348 attr.as_key_value().and_then(|(name, value)| {
349 let is_path = name == "path";
350 if is_path {
351 Some(value)
352 } else {
353 None
354 }
355 })
356 })
357}