Added extract path attribute for current module

#1211
This commit is contained in:
Alexander Andreev 2019-07-06 14:04:56 +03:00
parent 219e0e8c8d
commit 35a0f04128
4 changed files with 23 additions and 7 deletions

View file

@ -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,

View file

@ -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) {

View file

@ -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<ast::Module> },
Declaration { name: Name, ast_id: FileAstId<ast::Module>, attr_path: Option<SmolStr> },
Definition { name: Name, ast_id: FileAstId<ast::Module>, items: Vec<RawItem> },
}
@ -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<SmolStr> {
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
}
})
})
}

View file

@ -52,7 +52,7 @@ pub fn set_filter(f: Filter) {
/// It supports nested profiling scopes in case when this function invoked multiple times at the execution stack. In this case the profiling information will be nested at the output.
/// Profiling information is being printed in the stderr.
///
/// #Example
/// # Example
/// ```
/// use ra_prof::{profile, set_filter, Filter};
///