]> git.lizzy.rs Git - rust.git/commitdiff
Return inner attributes of outline mod declarations in `attrs_query`
authorLukas Wirth <lukastw97@gmail.com>
Sun, 31 Jan 2021 18:53:01 +0000 (19:53 +0100)
committerLukas Wirth <lukastw97@gmail.com>
Sun, 31 Jan 2021 18:53:01 +0000 (19:53 +0100)
crates/hir_def/src/attr.rs
crates/ide/src/hover.rs

index 6513daec87dc9a03cef322ba1373a1126e87deb9..fe4c3fa28e480f54b65213d6aa4f1bc78f5d629a 100644 (file)
@@ -200,7 +200,15 @@ pub(crate) fn attrs_query(db: &dyn DefDatabase, def: AttrDefId) -> Attrs {
                 let mod_data = &def_map[module.local_id];
                 match mod_data.declaration_source(db) {
                     Some(it) => {
-                        RawAttrs::from_attrs_owner(db, it.as_ref().map(|it| it as &dyn AttrsOwner))
+                        let raw_attrs = RawAttrs::from_attrs_owner(
+                            db,
+                            it.as_ref().map(|it| it as &dyn AttrsOwner),
+                        );
+                        match mod_data.definition_source(db) {
+                            InFile { file_id, value: ModuleSource::SourceFile(file) } => raw_attrs
+                                .merge(RawAttrs::from_attrs_owner(db, InFile::new(file_id, &file))),
+                            _ => raw_attrs,
+                        }
                     }
                     None => RawAttrs::from_attrs_owner(
                         db,
index d47a4cb0f1b98aecf87d646a886def52f984259a..5d2d072b1d7fb96fa54966aeed71b698a60e32f7 100644 (file)
@@ -3444,4 +3444,20 @@ impl<const LEN: usize> Foo<LEN$0> {}
             "#]],
         );
     }
+
+    #[test]
+    fn hover_mod_def() {
+        check(
+            r#"
+//- /main.rs
+mod foo$0;
+//- /foo.rs
+//! For the horde!
+"#,
+            expect![[r#"
+                *foo*
+                For the horde!
+            "#]],
+        );
+    }
 }