Skip to content

Commit

Permalink
feat: notify users that we are showing docs for different def
Browse files Browse the repository at this point in the history
  • Loading branch information
dqkqd committed Oct 21, 2024
1 parent da102d0 commit 4ecc93f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/ide/src/hover/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ fn get_docs(
) -> Option<Documentation> {
let mut docs = def.docs(db, famous_defs, edition);
let mut def = def;
let mut docs_changed = false;

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

def = get_definition(sema, token)?;
docs = def.docs(db, famous_defs, edition);
docs_changed = true;
}

if docs_changed {
// Notify user that we are showing the docs for different def.
docs = docs.map(|docs| {
let new_docs = format!(
"*This is the documentation for* `{}`.\n\n{}",
def.label(db, edition),
docs.as_str()
);
Documentation::new(new_docs)
})
}

docs
Expand Down
8 changes: 8 additions & 0 deletions crates/ide/src/hover/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9043,6 +9043,8 @@ type A$0 = B;
---
*This is the documentation for* `struct B`.
Docs for B
"#]],
);
Expand Down Expand Up @@ -9071,6 +9073,8 @@ type A$0 = B;
---
*This is the documentation for* `struct C`.
Docs for C
"#]],
);
Expand Down Expand Up @@ -9100,6 +9104,8 @@ type A$0 = B;
---
*This is the documentation for* `type B = C`.
Docs for B
"#]],
);
Expand Down Expand Up @@ -9159,6 +9165,8 @@ use a::A$0;
---
*This is the documentation for* `pub struct C`.
Docs for C
"#]],
);
Expand Down

0 comments on commit 4ecc93f

Please sign in to comment.