]> git.lizzy.rs Git - rust.git/commitdiff
Added extract path attribute for current module
authorAlexander Andreev <andreevlex.as@gmail.com>
Sat, 6 Jul 2019 11:04:56 +0000 (14:04 +0300)
committerAlexander Andreev <andreevlex.as@gmail.com>
Sat, 6 Jul 2019 11:04:56 +0000 (14:04 +0300)
#1211

crates/ra_hir/src/nameres.rs
crates/ra_hir/src/nameres/collector.rs
crates/ra_hir/src/nameres/raw.rs
crates/ra_prof/src/lib.rs

index 53ef8d58accdcec601be62fa621faa046bbe4b12..cf9ff0636f335f5ae8bb5358253faabf672ce1ab 100644 (file)
@@ -76,7 +76,7 @@
     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,
index d66be34dbd1a5a2b6cdc2ff3a3a66207d9a6a626..951468a98a80d3035a5130d95358d2545921f263 100644 (file)
@@ -508,8 +508,8 @@ fn collect_module(&mut self, module: &raw::ModuleData) {
                 }
                 .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) {
index 7ea59cb7591449e5819c82d7ca86d7adb8160351..46b2bef5b579d75bbab9954499613af7c1064b68 100644 (file)
@@ -3,7 +3,7 @@
 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 @@ pub(super) enum RawItem {
 
 #[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 @@ fn add_module(&mut self, current_module: Option<Module>, module: &ast::Module) {
             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 @@ fn push_item(&mut self, current_module: Option<Module>, item: RawItem) {
         .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
+            }
+        })
+    })
+}
index 919cc1b3cef4e89302a750d64532ec72cf440971..6d44fef33e8e88d960e5d6ddf3f0ad131cb5b3a7 100644 (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};
 ///