Skip to content

Commit 4ecc93f

Browse files
committed
feat: notify users that we are showing docs for different def
1 parent da102d0 commit 4ecc93f

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

crates/ide/src/hover/render.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ fn get_docs(
833833
) -> Option<Documentation> {
834834
let mut docs = def.docs(db, famous_defs, edition);
835835
let mut def = def;
836+
let mut docs_changed = false;
836837

837838
// Searching for type alias without docs attr.
838839
while let Definition::TypeAlias(type_alias) = def {
@@ -849,6 +850,19 @@ fn get_docs(
849850

850851
def = get_definition(sema, token)?;
851852
docs = def.docs(db, famous_defs, edition);
853+
docs_changed = true;
854+
}
855+
856+
if docs_changed {
857+
// Notify user that we are showing the docs for different def.
858+
docs = docs.map(|docs| {
859+
let new_docs = format!(
860+
"*This is the documentation for* `{}`.\n\n{}",
861+
def.label(db, edition),
862+
docs.as_str()
863+
);
864+
Documentation::new(new_docs)
865+
})
852866
}
853867

854868
docs

crates/ide/src/hover/tests.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9043,6 +9043,8 @@ type A$0 = B;
90439043
90449044
---
90459045
9046+
*This is the documentation for* `struct B`.
9047+
90469048
Docs for B
90479049
"#]],
90489050
);
@@ -9071,6 +9073,8 @@ type A$0 = B;
90719073
90729074
---
90739075
9076+
*This is the documentation for* `struct C`.
9077+
90749078
Docs for C
90759079
"#]],
90769080
);
@@ -9100,6 +9104,8 @@ type A$0 = B;
91009104
91019105
---
91029106
9107+
*This is the documentation for* `type B = C`.
9108+
91039109
Docs for B
91049110
"#]],
91059111
);
@@ -9159,6 +9165,8 @@ use a::A$0;
91599165
91609166
---
91619167
9168+
*This is the documentation for* `pub struct C`.
9169+
91629170
Docs for C
91639171
"#]],
91649172
);

0 commit comments

Comments
 (0)