@@ -3,8 +3,8 @@ use std::{mem, ops::Not};
33
44use either:: Either ;
55use hir:: {
6- Adt , AsAssocItem , CaptureKind , HasCrate , HasSource , HirDisplay , Layout , LayoutError , Name ,
7- Semantics , Trait , Type , TypeInfo ,
6+ Adt , AsAssocItem , AsExternAssocItem , CaptureKind , HasCrate , HasSource , HirDisplay , Layout ,
7+ LayoutError , Name , Semantics , Trait , Type , TypeInfo ,
88} ;
99use ide_db:: {
1010 base_db:: SourceDatabase ,
@@ -264,7 +264,7 @@ pub(super) fn keyword(
264264 let markup = process_markup (
265265 sema. db ,
266266 Definition :: Module ( doc_owner) ,
267- & markup ( Some ( docs. into ( ) ) , description, None ) ? ,
267+ & markup ( Some ( docs. into ( ) ) , description, None ) ,
268268 config,
269269 ) ;
270270 Some ( HoverResult { markup, actions } )
@@ -369,12 +369,20 @@ fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String>
369369 match def {
370370 Definition :: Field ( f) => Some ( f. parent_def ( db) . name ( db) ) ,
371371 Definition :: Local ( l) => l. parent ( db) . name ( db) ,
372- Definition :: Function ( f) => match f. as_assoc_item ( db) ?. container ( db) {
373- hir:: AssocItemContainer :: Trait ( t) => Some ( t. name ( db) ) ,
374- hir:: AssocItemContainer :: Impl ( i) => i. self_ty ( db) . as_adt ( ) . map ( |adt| adt. name ( db) ) ,
375- } ,
376372 Definition :: Variant ( e) => Some ( e. parent_enum ( db) . name ( db) ) ,
377- _ => None ,
373+
374+ d => {
375+ if let Some ( assoc_item) = d. as_assoc_item ( db) {
376+ match assoc_item. container ( db) {
377+ hir:: AssocItemContainer :: Trait ( t) => Some ( t. name ( db) ) ,
378+ hir:: AssocItemContainer :: Impl ( i) => {
379+ i. self_ty ( db) . as_adt ( ) . map ( |adt| adt. name ( db) )
380+ }
381+ }
382+ } else {
383+ return d. as_extern_assoc_item ( db) . map ( |_| "<extern>" . to_owned ( ) ) ;
384+ }
385+ }
378386 }
379387 . map ( |name| name. display ( db) . to_string ( ) )
380388}
@@ -396,11 +404,11 @@ pub(super) fn definition(
396404 famous_defs : Option < & FamousDefs < ' _ , ' _ > > ,
397405 notable_traits : & [ ( Trait , Vec < ( Option < Type > , Name ) > ) ] ,
398406 config : & HoverConfig ,
399- ) -> Option < Markup > {
407+ ) -> Markup {
400408 let mod_path = definition_mod_path ( db, & def) ;
401- let label = def. label ( db) ? ;
409+ let label = def. label ( db) ;
402410 let docs = def. docs ( db, famous_defs) ;
403- let value = match def {
411+ let value = ( || match def {
404412 Definition :: Variant ( it) => {
405413 if !it. parent_enum ( db) . is_data_carrying ( db) {
406414 match it. eval ( db) {
@@ -436,7 +444,7 @@ pub(super) fn definition(
436444 Some ( body. to_string ( ) )
437445 }
438446 _ => None ,
439- } ;
447+ } ) ( ) ;
440448
441449 let layout_info = match def {
442450 Definition :: Field ( it) => render_memory_layout (
@@ -683,7 +691,7 @@ fn definition_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
683691 def. module ( db) . map ( |module| path ( db, module, definition_owner_name ( db, def) ) )
684692}
685693
686- fn markup ( docs : Option < String > , desc : String , mod_path : Option < String > ) -> Option < Markup > {
694+ fn markup ( docs : Option < String > , desc : String , mod_path : Option < String > ) -> Markup {
687695 let mut buf = String :: new ( ) ;
688696
689697 if let Some ( mod_path) = mod_path {
@@ -696,7 +704,7 @@ fn markup(docs: Option<String>, desc: String, mod_path: Option<String>) -> Optio
696704 if let Some ( doc) = docs {
697705 format_to ! ( buf, "\n ___\n \n {}" , doc) ;
698706 }
699- Some ( buf. into ( ) )
707+ buf. into ( )
700708}
701709
702710fn find_std_module ( famous_defs : & FamousDefs < ' _ , ' _ > , name : & str ) -> Option < hir:: Module > {
0 commit comments