@@ -307,6 +307,25 @@ impl InlayHintsConfig {
307307 Lazy :: Computed ( edit)
308308 }
309309 }
310+
311+ fn lazy_tooltip ( & self , finish : impl FnOnce ( ) -> InlayTooltip ) -> Lazy < InlayTooltip > {
312+ if self . fields_to_resolve . resolve_hint_tooltip
313+ && self . fields_to_resolve . resolve_label_tooltip
314+ {
315+ Lazy :: Lazy
316+ } else {
317+ let tooltip = finish ( ) ;
318+ never ! (
319+ match & tooltip {
320+ InlayTooltip :: String ( s) => s,
321+ InlayTooltip :: Markdown ( s) => s,
322+ }
323+ . is_empty( ) ,
324+ "inlay hint produced an empty tooltip"
325+ ) ;
326+ Lazy :: Computed ( tooltip)
327+ }
328+ }
310329}
311330
312331#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
@@ -486,7 +505,7 @@ pub struct InlayHintLabel {
486505impl InlayHintLabel {
487506 pub fn simple (
488507 s : impl Into < String > ,
489- tooltip : Option < InlayTooltip > ,
508+ tooltip : Option < Lazy < InlayTooltip > > ,
490509 linked_location : Option < FileRange > ,
491510 ) -> InlayHintLabel {
492511 InlayHintLabel {
@@ -564,7 +583,6 @@ impl fmt::Debug for InlayHintLabel {
564583 }
565584}
566585
567- #[ derive( Hash ) ]
568586pub struct InlayHintLabelPart {
569587 pub text : String ,
570588 /// Source location represented by this label part. The client will use this to fetch the part's
@@ -575,21 +593,30 @@ pub struct InlayHintLabelPart {
575593 pub linked_location : Option < FileRange > ,
576594 /// The tooltip to show when hovering over the inlay hint, this may invoke other actions like
577595 /// hover requests to show.
578- pub tooltip : Option < InlayTooltip > ,
596+ pub tooltip : Option < Lazy < InlayTooltip > > ,
597+ }
598+
599+ impl std:: hash:: Hash for InlayHintLabelPart {
600+ fn hash < H : std:: hash:: Hasher > ( & self , state : & mut H ) {
601+ self . text . hash ( state) ;
602+ self . linked_location . hash ( state) ;
603+ self . tooltip . is_some ( ) . hash ( state) ;
604+ }
579605}
580606
581607impl fmt:: Debug for InlayHintLabelPart {
582608 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
583609 match self {
584- Self { text, linked_location : None , tooltip : None } => text. fmt ( f) ,
610+ Self { text, linked_location : None , tooltip : None | Some ( Lazy :: Lazy ) } => text. fmt ( f) ,
585611 Self { text, linked_location, tooltip } => f
586612 . debug_struct ( "InlayHintLabelPart" )
587613 . field ( "text" , text)
588614 . field ( "linked_location" , linked_location)
589615 . field (
590616 "tooltip" ,
591617 & tooltip. as_ref ( ) . map_or ( "" , |it| match it {
592- InlayTooltip :: String ( it) | InlayTooltip :: Markdown ( it) => it,
618+ Lazy :: Computed ( InlayTooltip :: String ( it) | InlayTooltip :: Markdown ( it) ) => it,
619+ Lazy :: Lazy => "" ,
593620 } ) ,
594621 )
595622 . finish ( ) ,
0 commit comments