diff options
author | Alexander Andreev <[email protected]> | 2019-07-06 12:04:56 +0100 |
---|---|---|
committer | Alexander Andreev <[email protected]> | 2019-07-06 12:04:56 +0100 |
commit | 35a0f04128b1ba84da8f3a107e7eed0b164733ed (patch) | |
tree | 78f7b70553476cc68f7aa0a15fda1dce4c2c8f38 /crates/ra_hir/src | |
parent | 219e0e8c8d6672feaab2f19b7c3280d5967360e4 (diff) |
Added extract path attribute for current module
#1211
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/nameres.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/collector.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/raw.rs | 22 |
3 files changed, 22 insertions, 6 deletions
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::{ | |||
76 | raw::ImportId, | 76 | raw::ImportId, |
77 | }; | 77 | }; |
78 | 78 | ||
79 | /// Contans all top-level defs from a macro-expanded crate | 79 | /// Contains all top-level defs from a macro-expanded crate |
80 | #[derive(Debug, PartialEq, Eq)] | 80 | #[derive(Debug, PartialEq, Eq)] |
81 | pub struct CrateDefMap { | 81 | pub struct CrateDefMap { |
82 | krate: Crate, | 82 | 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 | |||
508 | } | 508 | } |
509 | .collect(&*items); | 509 | .collect(&*items); |
510 | } | 510 | } |
511 | // out of line module, resovle, parse and recurse | 511 | // out of line module, resolve, parse and recurse |
512 | raw::ModuleData::Declaration { name, ast_id } => { | 512 | raw::ModuleData::Declaration { name, ast_id, .. } => { |
513 | let ast_id = ast_id.with_file_id(self.file_id); | 513 | let ast_id = ast_id.with_file_id(self.file_id); |
514 | let is_root = self.def_collector.def_map.modules[self.module_id].parent.is_none(); | 514 | let is_root = self.def_collector.def_map.modules[self.module_id].parent.is_none(); |
515 | match resolve_submodule(self.def_collector.db, self.file_id, name, is_root) { | 515 | 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}; | |||
3 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; | 3 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; |
4 | use ra_syntax::{ | 4 | use 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 | }; |
8 | use test_utils::tested_by; | 8 | use 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)] |
132 | pub(super) enum ModuleData { | 132 | 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> }, |
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 | |||
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 | } | ||