@@ -273,7 +273,7 @@ pub(super) fn keyword(
273
273
let markup = process_markup (
274
274
sema. db ,
275
275
Definition :: Module ( doc_owner) ,
276
- & markup ( Some ( docs. into ( ) ) , description, None ) ,
276
+ & markup ( Some ( docs. into ( ) ) , description, None , None ) ,
277
277
config,
278
278
) ;
279
279
Some ( HoverResult { markup, actions } )
@@ -539,28 +539,29 @@ pub(super) fn definition(
539
539
_ => None ,
540
540
} ;
541
541
542
- let mut desc = String :: new ( ) ;
543
- if let Some ( notable_traits) = render_notable_trait_comment ( db, notable_traits, edition) {
544
- desc. push_str ( & notable_traits) ;
545
- desc. push ( '\n' ) ;
546
- }
542
+ let mut extra = String :: new ( ) ;
547
543
if hovered_definition {
544
+ if let Some ( notable_traits) = render_notable_trait ( db, notable_traits, edition) {
545
+ extra. push_str ( "\n ___\n " ) ;
546
+ extra. push_str ( & notable_traits) ;
547
+ }
548
548
if let Some ( layout_info) = layout_info ( ) {
549
- desc . push_str ( & layout_info ) ;
550
- desc . push ( '\n' ) ;
549
+ extra . push_str ( " \n ___ \n " ) ;
550
+ extra . push_str ( & layout_info ) ;
551
551
}
552
552
if let Some ( dyn_compatibility_info) = dyn_compatibility_info ( ) {
553
- desc . push_str ( & dyn_compatibility_info ) ;
554
- desc . push ( '\n' ) ;
553
+ extra . push_str ( " \n ___ \n " ) ;
554
+ extra . push_str ( & dyn_compatibility_info ) ;
555
555
}
556
556
}
557
+ let mut desc = String :: new ( ) ;
557
558
desc. push_str ( & label) ;
558
559
if let Some ( value) = value ( ) {
559
560
desc. push_str ( " = " ) ;
560
561
desc. push_str ( & value) ;
561
562
}
562
563
563
- markup ( docs. map ( Into :: into) , desc, mod_path)
564
+ markup ( docs. map ( Into :: into) , desc, extra . is_empty ( ) . not ( ) . then_some ( extra ) , mod_path)
564
565
}
565
566
566
567
pub ( super ) fn literal (
@@ -630,7 +631,7 @@ pub(super) fn literal(
630
631
Some ( s. into ( ) )
631
632
}
632
633
633
- fn render_notable_trait_comment (
634
+ fn render_notable_trait (
634
635
db : & RootDatabase ,
635
636
notable_traits : & [ ( Trait , Vec < ( Option < Type > , Name ) > ) ] ,
636
637
edition : Edition ,
@@ -639,7 +640,7 @@ fn render_notable_trait_comment(
639
640
let mut needs_impl_header = true ;
640
641
for ( trait_, assoc_types) in notable_traits {
641
642
desc. push_str ( if mem:: take ( & mut needs_impl_header) {
642
- "// Implements notable traits: "
643
+ "Implements notable traits: "
643
644
} else {
644
645
", "
645
646
} ) ;
@@ -732,13 +733,12 @@ fn type_info(
732
733
)
733
734
. into ( )
734
735
} else {
735
- let mut desc =
736
- match render_notable_trait_comment ( db, & notable_traits ( db, & original) , edition) {
737
- Some ( desc) => desc + "\n " ,
738
- None => String :: new ( ) ,
739
- } ;
740
- format_to ! ( desc, "{}" , original. display( db, edition) ) ;
741
- Markup :: fenced_block ( & desc)
736
+ let mut desc = format ! ( "```rust\n {}\n ```" , original. display( db, edition) ) ;
737
+ if let Some ( extra) = render_notable_trait ( db, & notable_traits ( db, & original) , edition) {
738
+ desc. push_str ( "\n ___\n " ) ;
739
+ desc. push_str ( & extra) ;
740
+ } ;
741
+ desc. into ( )
742
742
} ;
743
743
if let Some ( actions) = HoverAction :: goto_type_from_targets ( db, targets, edition) {
744
744
res. actions . push ( actions) ;
@@ -790,20 +790,16 @@ fn closure_ty(
790
790
} ;
791
791
let mut markup = format ! ( "```rust\n {}" , c. display_with_id( sema. db, edition) ) ;
792
792
793
+ if let Some ( trait_) = c. fn_trait ( sema. db ) . get_id ( sema. db , original. krate ( sema. db ) . into ( ) ) {
794
+ push_new_def ( hir:: Trait :: from ( trait_) . into ( ) )
795
+ }
796
+ format_to ! ( markup, "\n {}\n ```" , c. display_with_impl( sema. db, edition) , ) ;
793
797
if let Some ( layout) =
794
798
render_memory_layout ( config. memory_layout , || original. layout ( sema. db ) , |_| None , |_| None )
795
799
{
796
- format_to ! ( markup, " {layout}" ) ;
797
- }
798
- if let Some ( trait_) = c. fn_trait ( sema. db ) . get_id ( sema. db , original. krate ( sema. db ) . into ( ) ) {
799
- push_new_def ( hir:: Trait :: from ( trait_) . into ( ) )
800
+ format_to ! ( markup, "\n ___\n {layout}" ) ;
800
801
}
801
- format_to ! (
802
- markup,
803
- "\n {}\n ```{adjusted}\n \n ## Captures\n {}" ,
804
- c. display_with_impl( sema. db, edition) ,
805
- captures_rendered,
806
- ) ;
802
+ format_to ! ( markup, "{adjusted}\n \n ## Captures\n {}" , captures_rendered, ) ;
807
803
808
804
let mut res = HoverResult :: default ( ) ;
809
805
if let Some ( actions) = HoverAction :: goto_type_from_targets ( sema. db , targets, edition) {
@@ -828,15 +824,24 @@ fn definition_mod_path(db: &RootDatabase, def: &Definition, edition: Edition) ->
828
824
. map ( |module| path ( db, module, definition_owner_name ( db, def, edition) , edition) )
829
825
}
830
826
831
- fn markup ( docs : Option < String > , desc : String , mod_path : Option < String > ) -> Markup {
827
+ fn markup (
828
+ docs : Option < String > ,
829
+ rust : String ,
830
+ extra : Option < String > ,
831
+ mod_path : Option < String > ,
832
+ ) -> Markup {
832
833
let mut buf = String :: new ( ) ;
833
834
834
835
if let Some ( mod_path) = mod_path {
835
836
if !mod_path. is_empty ( ) {
836
837
format_to ! ( buf, "```rust\n {}\n ```\n \n " , mod_path) ;
837
838
}
838
839
}
839
- format_to ! ( buf, "```rust\n {}\n ```" , desc) ;
840
+ format_to ! ( buf, "```rust\n {}\n ```" , rust) ;
841
+
842
+ if let Some ( extra) = extra {
843
+ buf. push_str ( & extra) ;
844
+ }
840
845
841
846
if let Some ( doc) = docs {
842
847
format_to ! ( buf, "\n ___\n \n {}" , doc) ;
@@ -866,7 +871,7 @@ fn render_memory_layout(
866
871
let config = config?;
867
872
let layout = layout ( ) . ok ( ) ?;
868
873
869
- let mut label = String :: from ( "// " ) ;
874
+ let mut label = String :: new ( ) ;
870
875
871
876
if let Some ( render) = config. size {
872
877
let size = match tag ( & layout) {
@@ -998,10 +1003,10 @@ fn render_dyn_compatibility(
998
1003
safety : Option < DynCompatibilityViolation > ,
999
1004
) {
1000
1005
let Some ( osv) = safety else {
1001
- buf. push_str ( "// Is Dyn compatible" ) ;
1006
+ buf. push_str ( "Is Dyn compatible" ) ;
1002
1007
return ;
1003
1008
} ;
1004
- buf. push_str ( "// Is not Dyn compatible due to " ) ;
1009
+ buf. push_str ( "Is not Dyn compatible due to " ) ;
1005
1010
match osv {
1006
1011
DynCompatibilityViolation :: SizedSelf => {
1007
1012
buf. push_str ( "having a `Self: Sized` bound" ) ;
0 commit comments