@@ -307,6 +307,25 @@ impl InlayHintsConfig {
307
307
Lazy :: Computed ( edit)
308
308
}
309
309
}
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
+ }
310
329
}
311
330
312
331
#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
@@ -486,7 +505,7 @@ pub struct InlayHintLabel {
486
505
impl InlayHintLabel {
487
506
pub fn simple (
488
507
s : impl Into < String > ,
489
- tooltip : Option < InlayTooltip > ,
508
+ tooltip : Option < Lazy < InlayTooltip > > ,
490
509
linked_location : Option < FileRange > ,
491
510
) -> InlayHintLabel {
492
511
InlayHintLabel {
@@ -564,7 +583,6 @@ impl fmt::Debug for InlayHintLabel {
564
583
}
565
584
}
566
585
567
- #[ derive( Hash ) ]
568
586
pub struct InlayHintLabelPart {
569
587
pub text : String ,
570
588
/// Source location represented by this label part. The client will use this to fetch the part's
@@ -575,21 +593,30 @@ pub struct InlayHintLabelPart {
575
593
pub linked_location : Option < FileRange > ,
576
594
/// The tooltip to show when hovering over the inlay hint, this may invoke other actions like
577
595
/// 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
+ }
579
605
}
580
606
581
607
impl fmt:: Debug for InlayHintLabelPart {
582
608
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
583
609
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) ,
585
611
Self { text, linked_location, tooltip } => f
586
612
. debug_struct ( "InlayHintLabelPart" )
587
613
. field ( "text" , text)
588
614
. field ( "linked_location" , linked_location)
589
615
. field (
590
616
"tooltip" ,
591
617
& 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 => "" ,
593
620
} ) ,
594
621
)
595
622
. finish ( ) ,
0 commit comments