@@ -300,6 +300,7 @@ pub struct InlayHintsConfig {
300300 pub closing_brace_hints_min_lines : Option < usize > ,
301301 pub fields_to_resolve : InlayFieldsToResolve ,
302302}
303+
303304impl InlayHintsConfig {
304305 fn lazy_text_edit ( & self , finish : impl FnOnce ( ) -> TextEdit ) -> Lazy < TextEdit > {
305306 if self . fields_to_resolve . resolve_text_edits {
@@ -329,6 +330,19 @@ impl InlayHintsConfig {
329330 Lazy :: Computed ( tooltip)
330331 }
331332 }
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+ }
332346}
333347
334348#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
@@ -509,7 +523,7 @@ impl InlayHintLabel {
509523 pub fn simple (
510524 s : impl Into < String > ,
511525 tooltip : Option < Lazy < InlayTooltip > > ,
512- linked_location : Option < FileRange > ,
526+ linked_location : Option < Lazy < FileRange > > ,
513527 ) -> InlayHintLabel {
514528 InlayHintLabel {
515529 parts : smallvec ! [ InlayHintLabelPart { text: s. into( ) , linked_location, tooltip } ] ,
@@ -593,7 +607,7 @@ pub struct InlayHintLabelPart {
593607 /// refers to (not necessarily the location itself).
594608 /// When setting this, no tooltip must be set on the containing hint, or VS Code will display
595609 /// them both.
596- pub linked_location : Option < FileRange > ,
610+ pub linked_location : Option < Lazy < FileRange > > ,
597611 /// The tooltip to show when hovering over the inlay hint, this may invoke other actions like
598612 /// hover requests to show.
599613 pub tooltip : Option < Lazy < InlayTooltip > > ,
@@ -602,7 +616,7 @@ pub struct InlayHintLabelPart {
602616impl std:: hash:: Hash for InlayHintLabelPart {
603617 fn hash < H : std:: hash:: Hasher > ( & self , state : & mut H ) {
604618 self . text . hash ( state) ;
605- self . linked_location . hash ( state) ;
619+ self . linked_location . is_some ( ) . hash ( state) ;
606620 self . tooltip . is_some ( ) . hash ( state) ;
607621 }
608622}
@@ -663,7 +677,7 @@ impl InlayHintLabelBuilder<'_> {
663677 if !text. is_empty ( ) {
664678 self . result . parts . push ( InlayHintLabelPart {
665679 text,
666- linked_location : self . location . take ( ) ,
680+ linked_location : self . location . take ( ) . map ( Lazy :: Computed ) ,
667681 tooltip : None ,
668682 } ) ;
669683 }
0 commit comments