Skip to content

Commit 35a0f04

Browse files
committed
Added extract path attribute for current module
#1211
1 parent 219e0e8 commit 35a0f04

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

crates/ra_hir/src/nameres.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub use self::{
7676
raw::ImportId,
7777
};
7878

79-
/// Contans all top-level defs from a macro-expanded crate
79+
/// Contains all top-level defs from a macro-expanded crate
8080
#[derive(Debug, PartialEq, Eq)]
8181
pub struct CrateDefMap {
8282
krate: Crate,

crates/ra_hir/src/nameres/collector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,8 @@ where
508508
}
509509
.collect(&*items);
510510
}
511-
// out of line module, resovle, parse and recurse
512-
raw::ModuleData::Declaration { name, ast_id } => {
511+
// out of line module, resolve, parse and recurse
512+
raw::ModuleData::Declaration { name, ast_id, .. } => {
513513
let ast_id = ast_id.with_file_id(self.file_id);
514514
let is_root = self.def_collector.def_map.modules[self.module_id].parent.is_none();
515515
match resolve_submodule(self.def_collector.db, self.file_id, name, is_root) {

crates/ra_hir/src/nameres/raw.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{ops::Index, sync::Arc};
33
use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId};
44
use ra_syntax::{
55
ast::{self, AttrsOwner, NameOwner},
6-
AstNode, AstPtr, SourceFile, TreeArc,
6+
AstNode, AstPtr, SmolStr, SourceFile, TreeArc,
77
};
88
use test_utils::tested_by;
99

@@ -130,7 +130,7 @@ impl_arena_id!(Module);
130130

131131
#[derive(Debug, PartialEq, Eq)]
132132
pub(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> },
134134
Definition { name: Name, ast_id: FileAstId<ast::Module>, items: Vec<RawItem> },
135135
}
136136

@@ -255,9 +255,12 @@ impl RawItemsCollector {
255255
Some(it) => it.as_name(),
256256
None => return,
257257
};
258+
259+
let attr_path = extract_mod_path_attribute(module);
258260
let ast_id = self.source_ast_id_map.ast_id(module);
259261
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 });
261264
self.push_item(current_module, RawItem::Module(item));
262265
return;
263266
}
@@ -339,3 +342,16 @@ impl RawItemsCollector {
339342
.push(item)
340343
}
341344
}
345+
346+
fn 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+
}

crates/ra_prof/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub fn set_filter(f: Filter) {
5252
/// 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.
5353
/// Profiling information is being printed in the stderr.
5454
///
55-
/// #Example
55+
/// # Example
5656
/// ```
5757
/// use ra_prof::{profile, set_filter, Filter};
5858
///

0 commit comments

Comments
 (0)