@@ -104,7 +104,7 @@ var AllInlayHints = map[string]*Hint{
104
104
},
105
105
}
106
106
107
- func InlayHint (ctx context.Context , snapshot Snapshot , fh FileHandle , _ protocol.Range ) ([]protocol.InlayHint , error ) {
107
+ func InlayHint (ctx context.Context , snapshot Snapshot , fh FileHandle , pRng protocol.Range ) ([]protocol.InlayHint , error ) {
108
108
ctx , done := event .Start (ctx , "source.InlayHint" )
109
109
defer done ()
110
110
@@ -132,8 +132,23 @@ func InlayHint(ctx context.Context, snapshot Snapshot, fh FileHandle, _ protocol
132
132
info := pkg .GetTypesInfo ()
133
133
q := Qualifier (pgf .File , pkg .GetTypes (), info )
134
134
135
+ // Set the range to the full file if the range is not valid.
136
+ start , end := pgf .File .Pos (), pgf .File .End ()
137
+ if pRng .Start .Line < pRng .End .Line || pRng .Start .Character < pRng .End .Character {
138
+ // Adjust start and end for the specified range.
139
+ rng , err := pgf .Mapper .RangeToSpanRange (pRng )
140
+ if err != nil {
141
+ return nil , err
142
+ }
143
+ start , end = rng .Start , rng .End
144
+ }
145
+
135
146
var hints []protocol.InlayHint
136
147
ast .Inspect (pgf .File , func (node ast.Node ) bool {
148
+ // If not in range, we can stop looking.
149
+ if node == nil || node .End () < start || node .Pos () > end {
150
+ return false
151
+ }
137
152
for _ , fn := range enabledHints {
138
153
hints = append (hints , fn (node , tmap , info , & q )... )
139
154
}
0 commit comments