diff --git a/crates/ide/src/hover/render.rs b/crates/ide/src/hover/render.rs index bcdab3ba5721..d2034acfb18f 100644 --- a/crates/ide/src/hover/render.rs +++ b/crates/ide/src/hover/render.rs @@ -833,6 +833,7 @@ fn get_docs( ) -> Option { 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 { @@ -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 diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs index 7dc1bed6c073..1c6f6a7cd307 100644 --- a/crates/ide/src/hover/tests.rs +++ b/crates/ide/src/hover/tests.rs @@ -9043,6 +9043,8 @@ type A$0 = B; --- + *This is the documentation for* `struct B`. + Docs for B "#]], ); @@ -9071,6 +9073,8 @@ type A$0 = B; --- + *This is the documentation for* `struct C`. + Docs for C "#]], ); @@ -9100,6 +9104,8 @@ type A$0 = B; --- + *This is the documentation for* `type B = C`. + Docs for B "#]], ); @@ -9159,6 +9165,8 @@ use a::A$0; --- + *This is the documentation for* `pub struct C`. + Docs for C "#]], );