@@ -300,6 +300,7 @@ pub struct InlayHintsConfig {
300
300
pub closing_brace_hints_min_lines : Option < usize > ,
301
301
pub fields_to_resolve : InlayFieldsToResolve ,
302
302
}
303
+
303
304
impl InlayHintsConfig {
304
305
fn lazy_text_edit ( & self , finish : impl FnOnce ( ) -> TextEdit ) -> Lazy < TextEdit > {
305
306
if self . fields_to_resolve . resolve_text_edits {
@@ -329,6 +330,19 @@ impl InlayHintsConfig {
329
330
Lazy :: Computed ( tooltip)
330
331
}
331
332
}
333
+
334
+ /// This always reports a resolvable location, so only use this when it is very likely for a
335
+ /// location link to actually resolve but where computing `finish` would be costly.
336
+ fn lazy_location_opt (
337
+ & self ,
338
+ finish : impl FnOnce ( ) -> Option < FileRange > ,
339
+ ) -> Option < Lazy < FileRange > > {
340
+ if self . fields_to_resolve . resolve_label_location {
341
+ Some ( Lazy :: Lazy )
342
+ } else {
343
+ finish ( ) . map ( Lazy :: Computed )
344
+ }
345
+ }
332
346
}
333
347
334
348
#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
@@ -509,7 +523,7 @@ impl InlayHintLabel {
509
523
pub fn simple (
510
524
s : impl Into < String > ,
511
525
tooltip : Option < Lazy < InlayTooltip > > ,
512
- linked_location : Option < FileRange > ,
526
+ linked_location : Option < Lazy < FileRange > > ,
513
527
) -> InlayHintLabel {
514
528
InlayHintLabel {
515
529
parts : smallvec ! [ InlayHintLabelPart { text: s. into( ) , linked_location, tooltip } ] ,
@@ -593,7 +607,7 @@ pub struct InlayHintLabelPart {
593
607
/// refers to (not necessarily the location itself).
594
608
/// When setting this, no tooltip must be set on the containing hint, or VS Code will display
595
609
/// them both.
596
- pub linked_location : Option < FileRange > ,
610
+ pub linked_location : Option < Lazy < FileRange > > ,
597
611
/// The tooltip to show when hovering over the inlay hint, this may invoke other actions like
598
612
/// hover requests to show.
599
613
pub tooltip : Option < Lazy < InlayTooltip > > ,
@@ -602,7 +616,7 @@ pub struct InlayHintLabelPart {
602
616
impl std:: hash:: Hash for InlayHintLabelPart {
603
617
fn hash < H : std:: hash:: Hasher > ( & self , state : & mut H ) {
604
618
self . text . hash ( state) ;
605
- self . linked_location . hash ( state) ;
619
+ self . linked_location . is_some ( ) . hash ( state) ;
606
620
self . tooltip . is_some ( ) . hash ( state) ;
607
621
}
608
622
}
@@ -663,7 +677,7 @@ impl InlayHintLabelBuilder<'_> {
663
677
if !text. is_empty ( ) {
664
678
self . result . parts . push ( InlayHintLabelPart {
665
679
text,
666
- linked_location : self . location . take ( ) ,
680
+ linked_location : self . location . take ( ) . map ( Lazy :: Computed ) ,
667
681
tooltip : None ,
668
682
} ) ;
669
683
}
0 commit comments