@@ -113,37 +113,19 @@ func (e *Env) SetBufferContent(name string, content string) {
113
113
}
114
114
}
115
115
116
- // RegexpRange returns the range of the first match for re in the buffer
117
- // specified by name, calling t.Fatal on any error. It first searches for the
118
- // position in open buffers, then in workspace files.
119
- func (e * Env ) RegexpRange (name , re string ) protocol.Range {
120
- e .T .Helper ()
121
- rng , err := e .Editor .RegexpRange (name , re )
122
- if err == fake .ErrUnknownBuffer {
123
- rng , err = e .Sandbox .Workdir .RegexpRange (name , re )
124
- }
125
- if err != nil {
126
- e .T .Fatalf ("RegexpRange: %v, %v" , name , err )
127
- }
128
- return rng
129
- }
130
-
131
116
// RegexpSearch returns the starting position of the first match for re in the
132
117
// buffer specified by name, calling t.Fatal on any error. It first searches
133
118
// for the position in open buffers, then in workspace files.
134
- //
135
- // TODO(rfindley): RegexpSearch should return a protocol.Location (but that is
136
- // a large change).
137
- func (e * Env ) RegexpSearch (name , re string ) protocol.Position {
119
+ func (e * Env ) RegexpSearch (name , re string ) protocol.Location {
138
120
e .T .Helper ()
139
- pos , err := e .Editor .RegexpSearch (name , re )
121
+ loc , err := e .Editor .RegexpSearch (name , re )
140
122
if err == fake .ErrUnknownBuffer {
141
- pos , err = e .Sandbox .Workdir .RegexpSearch (name , re )
123
+ loc , err = e .Sandbox .Workdir .RegexpSearch (name , re )
142
124
}
143
125
if err != nil {
144
126
e .T .Fatalf ("RegexpSearch: %v, %v for %q" , name , err , re )
145
127
}
146
- return pos
128
+ return loc
147
129
}
148
130
149
131
// RegexpReplace replaces the first group in the first match of regexpStr with
@@ -172,13 +154,13 @@ func (e *Env) SaveBufferWithoutActions(name string) {
172
154
173
155
// GoToDefinition goes to definition in the editor, calling t.Fatal on any
174
156
// error. It returns the path and position of the resulting jump.
175
- func (e * Env ) GoToDefinition (name string , pos protocol.Position ) ( string , protocol.Position ) {
157
+ func (e * Env ) GoToDefinition (loc protocol.Location ) protocol.Location {
176
158
e .T .Helper ()
177
- n , p , err := e .Editor .GoToDefinition (e .Ctx , name , pos )
159
+ loc , err := e .Editor .GoToDefinition (e .Ctx , loc )
178
160
if err != nil {
179
161
e .T .Fatal (err )
180
162
}
181
- return n , p
163
+ return loc
182
164
}
183
165
184
166
// FormatBuffer formats the editor buffer, calling t.Fatal on any error.
@@ -201,7 +183,8 @@ func (e *Env) OrganizeImports(name string) {
201
183
// ApplyQuickFixes processes the quickfix codeAction, calling t.Fatal on any error.
202
184
func (e * Env ) ApplyQuickFixes (path string , diagnostics []protocol.Diagnostic ) {
203
185
e .T .Helper ()
204
- if err := e .Editor .ApplyQuickFixes (e .Ctx , path , nil , diagnostics ); err != nil {
186
+ loc := protocol.Location {URI : e .Sandbox .Workdir .URI (path )} // zero Range => whole file
187
+ if err := e .Editor .ApplyQuickFixes (e .Ctx , loc , diagnostics ); err != nil {
205
188
e .T .Fatal (err )
206
189
}
207
190
}
@@ -217,21 +200,22 @@ func (e *Env) ApplyCodeAction(action protocol.CodeAction) {
217
200
// GetQuickFixes returns the available quick fix code actions.
218
201
func (e * Env ) GetQuickFixes (path string , diagnostics []protocol.Diagnostic ) []protocol.CodeAction {
219
202
e .T .Helper ()
220
- actions , err := e .Editor .GetQuickFixes (e .Ctx , path , nil , diagnostics )
203
+ loc := protocol.Location {URI : e .Sandbox .Workdir .URI (path )} // zero Range => whole file
204
+ actions , err := e .Editor .GetQuickFixes (e .Ctx , loc , diagnostics )
221
205
if err != nil {
222
206
e .T .Fatal (err )
223
207
}
224
208
return actions
225
209
}
226
210
227
211
// Hover in the editor, calling t.Fatal on any error.
228
- func (e * Env ) Hover (name string , pos protocol.Position ) (* protocol.MarkupContent , protocol.Position ) {
212
+ func (e * Env ) Hover (loc protocol.Location ) (* protocol.MarkupContent , protocol.Location ) {
229
213
e .T .Helper ()
230
- c , p , err := e .Editor .Hover (e .Ctx , name , pos )
214
+ c , loc , err := e .Editor .Hover (e .Ctx , loc )
231
215
if err != nil {
232
216
e .T .Fatal (err )
233
217
}
234
- return c , p
218
+ return c , loc
235
219
}
236
220
237
221
func (e * Env ) DocumentLink (name string ) []protocol.DocumentLink {
@@ -243,9 +227,9 @@ func (e *Env) DocumentLink(name string) []protocol.DocumentLink {
243
227
return links
244
228
}
245
229
246
- func (e * Env ) DocumentHighlight (name string , pos protocol.Position ) []protocol.DocumentHighlight {
230
+ func (e * Env ) DocumentHighlight (loc protocol.Location ) []protocol.DocumentHighlight {
247
231
e .T .Helper ()
248
- highlights , err := e .Editor .DocumentHighlight (e .Ctx , name , pos )
232
+ highlights , err := e .Editor .DocumentHighlight (e .Ctx , loc )
249
233
if err != nil {
250
234
e .T .Fatal (err )
251
235
}
@@ -398,27 +382,27 @@ func (e *Env) Symbol(query string) []protocol.SymbolInformation {
398
382
}
399
383
400
384
// References wraps Editor.References, calling t.Fatal on any error.
401
- func (e * Env ) References (path string , pos protocol.Position ) []protocol.Location {
385
+ func (e * Env ) References (loc protocol.Location ) []protocol.Location {
402
386
e .T .Helper ()
403
- locations , err := e .Editor .References (e .Ctx , path , pos )
387
+ locations , err := e .Editor .References (e .Ctx , loc )
404
388
if err != nil {
405
389
e .T .Fatal (err )
406
390
}
407
391
return locations
408
392
}
409
393
410
394
// Rename wraps Editor.Rename, calling t.Fatal on any error.
411
- func (e * Env ) Rename (path string , pos protocol.Position , newName string ) {
395
+ func (e * Env ) Rename (loc protocol.Location , newName string ) {
412
396
e .T .Helper ()
413
- if err := e .Editor .Rename (e .Ctx , path , pos , newName ); err != nil {
397
+ if err := e .Editor .Rename (e .Ctx , loc , newName ); err != nil {
414
398
e .T .Fatal (err )
415
399
}
416
400
}
417
401
418
402
// Implementations wraps Editor.Implementations, calling t.Fatal on any error.
419
- func (e * Env ) Implementations (path string , pos protocol.Position ) []protocol.Location {
403
+ func (e * Env ) Implementations (loc protocol.Location ) []protocol.Location {
420
404
e .T .Helper ()
421
- locations , err := e .Editor .Implementations (e .Ctx , path , pos )
405
+ locations , err := e .Editor .Implementations (e .Ctx , loc )
422
406
if err != nil {
423
407
e .T .Fatal (err )
424
408
}
@@ -434,9 +418,9 @@ func (e *Env) RenameFile(oldPath, newPath string) {
434
418
}
435
419
436
420
// Completion executes a completion request on the server.
437
- func (e * Env ) Completion (path string , pos protocol.Position ) * protocol.CompletionList {
421
+ func (e * Env ) Completion (loc protocol.Location ) * protocol.CompletionList {
438
422
e .T .Helper ()
439
- completions , err := e .Editor .Completion (e .Ctx , path , pos )
423
+ completions , err := e .Editor .Completion (e .Ctx , loc )
440
424
if err != nil {
441
425
e .T .Fatal (err )
442
426
}
@@ -445,9 +429,9 @@ func (e *Env) Completion(path string, pos protocol.Position) *protocol.Completio
445
429
446
430
// AcceptCompletion accepts a completion for the given item at the given
447
431
// position.
448
- func (e * Env ) AcceptCompletion (path string , pos protocol.Position , item protocol.CompletionItem ) {
432
+ func (e * Env ) AcceptCompletion (loc protocol.Location , item protocol.CompletionItem ) {
449
433
e .T .Helper ()
450
- if err := e .Editor .AcceptCompletion (e .Ctx , path , pos , item ); err != nil {
434
+ if err := e .Editor .AcceptCompletion (e .Ctx , loc , item ); err != nil {
451
435
e .T .Fatal (err )
452
436
}
453
437
}
@@ -456,7 +440,8 @@ func (e *Env) AcceptCompletion(path string, pos protocol.Position, item protocol
456
440
// t.Fatal if there are errors.
457
441
func (e * Env ) CodeAction (path string , diagnostics []protocol.Diagnostic ) []protocol.CodeAction {
458
442
e .T .Helper ()
459
- actions , err := e .Editor .CodeAction (e .Ctx , path , nil , diagnostics )
443
+ loc := protocol.Location {URI : e .Sandbox .Workdir .URI (path )} // no Range => whole file
444
+ actions , err := e .Editor .CodeAction (e .Ctx , loc , diagnostics )
460
445
if err != nil {
461
446
e .T .Fatal (err )
462
447
}
0 commit comments