@@ -10,9 +10,10 @@ use hir::{
1010use ide_db:: {
1111 base_db:: SourceDatabase ,
1212 defs:: Definition ,
13- documentation:: HasDocs ,
13+ documentation:: { Documentation , HasDocs } ,
1414 famous_defs:: FamousDefs ,
1515 generated:: lints:: { CLIPPY_LINTS , DEFAULT_LINTS , FEATURES } ,
16+ helpers:: get_definition,
1617 syntax_helpers:: prettify_macro_expansion,
1718 RootDatabase ,
1819} ;
@@ -414,7 +415,7 @@ pub(super) fn path(
414415}
415416
416417pub ( super ) fn definition (
417- db : & RootDatabase ,
418+ sema @ & Semantics { db , .. } : & Semantics < ' _ , RootDatabase > ,
418419 def : Definition ,
419420 famous_defs : Option < & FamousDefs < ' _ , ' _ > > ,
420421 notable_traits : & [ ( Trait , Vec < ( Option < Type > , Name ) > ) ] ,
@@ -455,7 +456,7 @@ pub(super) fn definition(
455456 }
456457 _ => def. label ( db, edition) ,
457458 } ;
458- let docs = def . docs ( db , famous_defs, edition) ;
459+ let docs = get_docs ( sema , def , famous_defs, edition) ;
459460 let value = ( || match def {
460461 Definition :: Variant ( it) => {
461462 if !it. parent_enum ( db) . is_data_carrying ( db) {
@@ -824,6 +825,35 @@ fn definition_mod_path(db: &RootDatabase, def: &Definition, edition: Edition) ->
824825 . map ( |module| path ( db, module, definition_owner_name ( db, def, edition) , edition) )
825826}
826827
828+ fn get_docs (
829+ sema @ & Semantics { db, .. } : & Semantics < ' _ , RootDatabase > ,
830+ def : Definition ,
831+ famous_defs : Option < & FamousDefs < ' _ , ' _ > > ,
832+ edition : Edition ,
833+ ) -> Option < Documentation > {
834+ let mut docs = def. docs ( db, famous_defs, edition) ;
835+ let mut def = def;
836+
837+ // Searching for type alias without docs attr.
838+ while let Definition :: TypeAlias ( type_alias) = def {
839+ if docs. is_some ( ) {
840+ break ;
841+ }
842+
843+ let source = sema. source ( type_alias) ?;
844+ let type_alias = source. value . ty ( ) ?;
845+
846+ // Only take the first token, avoid searching docs for type parameters.
847+ // E.g. `type Y = Box<X>`
848+ let token = type_alias. syntax ( ) . first_token ( ) ?;
849+
850+ def = get_definition ( sema, token) ?;
851+ docs = def. docs ( db, famous_defs, edition) ;
852+ }
853+
854+ docs
855+ }
856+
827857fn markup ( docs : Option < String > , desc : String , mod_path : Option < String > ) -> Markup {
828858 let mut buf = String :: new ( ) ;
829859
0 commit comments