From 35a0f04128b1ba84da8f3a107e7eed0b164733ed Mon Sep 17 00:00:00 2001 From: Alexander Andreev Date: Sat, 6 Jul 2019 14:04:56 +0300 Subject: Added extract path attribute for current module #1211 --- crates/ra_hir/src/nameres.rs | 2 +- crates/ra_hir/src/nameres/collector.rs | 4 ++-- crates/ra_hir/src/nameres/raw.rs | 22 +++++++++++++++++++--- 3 files changed, 22 insertions(+), 6 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index 53ef8d58a..cf9ff0636 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -76,7 +76,7 @@ pub use self::{ raw::ImportId, }; -/// Contans all top-level defs from a macro-expanded crate +/// Contains all top-level defs from a macro-expanded crate #[derive(Debug, PartialEq, Eq)] pub struct CrateDefMap { krate: Crate, diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index d66be34db..951468a98 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -508,8 +508,8 @@ where } .collect(&*items); } - // out of line module, resovle, parse and recurse - raw::ModuleData::Declaration { name, ast_id } => { + // out of line module, resolve, parse and recurse + raw::ModuleData::Declaration { name, ast_id, .. } => { let ast_id = ast_id.with_file_id(self.file_id); let is_root = self.def_collector.def_map.modules[self.module_id].parent.is_none(); match resolve_submodule(self.def_collector.db, self.file_id, name, is_root) { 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}; use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; use ra_syntax::{ ast::{self, AttrsOwner, NameOwner}, - AstNode, AstPtr, SourceFile, TreeArc, + AstNode, AstPtr, SmolStr, SourceFile, TreeArc, }; use test_utils::tested_by; @@ -130,7 +130,7 @@ impl_arena_id!(Module); #[derive(Debug, PartialEq, Eq)] pub(super) enum ModuleData { - Declaration { name: Name, ast_id: FileAstId }, + Declaration { name: Name, ast_id: FileAstId, attr_path: Option }, Definition { name: Name, ast_id: FileAstId, items: Vec }, } @@ -255,9 +255,12 @@ impl RawItemsCollector { Some(it) => it.as_name(), None => return, }; + + let attr_path = extract_mod_path_attribute(module); let ast_id = self.source_ast_id_map.ast_id(module); if module.has_semi() { - let item = self.raw_items.modules.alloc(ModuleData::Declaration { name, ast_id }); + let item = + self.raw_items.modules.alloc(ModuleData::Declaration { name, ast_id, attr_path }); self.push_item(current_module, RawItem::Module(item)); return; } @@ -339,3 +342,16 @@ impl RawItemsCollector { .push(item) } } + +fn extract_mod_path_attribute(module: &ast::Module) -> Option { + module.attrs().into_iter().find_map(|attr| { + attr.as_key_value().and_then(|(name, value)| { + let is_path = name == "path"; + if is_path { + Some(value) + } else { + None + } + }) + }) +} -- cgit v1.2.3