Skip to content

Commit f003ff6

Browse files
adonovangopherbot
authored andcommitted
gopls/internal/test/marker: rename s/suggestedfix/quickfix/
At the protocol level, this operation requests all CodeActions of kind "quickfix", so that's the appropriate name. (SuggestedFix refers to types in go/analysis and in gopls/internal/cache that are only loosely related.) All the tests of @quickfix are now beneath testdata/quickfix (except diagnostics/typeerr.txt since that's not its primary aim). Change-Id: I907aab2fcc4c7f99170c1eefa5ee2cb8aca6331f Reviewed-on: https://go-review.googlesource.com/c/tools/+/621598 Auto-Submit: Alan Donovan <[email protected]> Reviewed-by: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 8128bcf commit f003ff6

26 files changed

+116
-118
lines changed

gopls/internal/test/integration/workspace/quickfix_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ func main() {}
341341
}
342342

343343
func TestStubMethods64087(t *testing.T) {
344-
// We can't use the @fix or @suggestedfixerr or @codeactionerr
344+
// We can't use the @fix or @quickfixerr or @codeactionerr
345345
// because the error now reported by the corrected logic
346346
// is internal and silently causes no fix to be offered.
347347
//
@@ -404,7 +404,7 @@ type myerror struct{any}
404404
}
405405

406406
func TestStubMethods64545(t *testing.T) {
407-
// We can't use the @fix or @suggestedfixerr or @codeactionerr
407+
// We can't use the @fix or @quickfixerr or @codeactionerr
408408
// because the error now reported by the corrected logic
409409
// is internal and silently causes no fix to be offered.
410410
//

gopls/internal/test/marker/doc.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,14 @@ The following markers are supported within marker tests:
219219
signatureHelp at the given location should match the provided string, with
220220
the active parameter (an index) highlighted.
221221
222-
- suggestedfix(location, regexp, golden): like diag, the location and
222+
- quickfix(location, regexp, golden): like diag, the location and
223223
regexp identify an expected diagnostic, which must have exactly one
224224
associated "quickfix" code action.
225225
This action is executed for its editing effects on the source files.
226226
Like rename, the golden directory contains the expected transformed files.
227227
228-
- suggestedfixerr(location, regexp, wantError): specifies that the
229-
suggestedfix operation should fail with an error that matches the expectation.
228+
- quickfixerr(location, regexp, wantError): specifies that the
229+
quickfix operation should fail with an error that matches the expectation.
230230
(Failures in the computation to offer a fix do not generally result
231231
in LSP errors, so this marker is not appropriate for testing them.)
232232
@@ -372,6 +372,6 @@ Note that -update does not cause missing @diag or @loc markers to be added.
372372
- If possible, improve handling for optional arguments. Rather than have
373373
multiple variations of a marker, it would be nice to support a more
374374
flexible signature: can codeaction, codeactionedit, codeactionerr, and
375-
suggestedfix be consolidated?
375+
quickfix be consolidated?
376376
*/
377377
package marker

gopls/internal/test/marker/marker_test.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,8 @@ var actionMarkerFuncs = map[string]func(marker){
561561
"selectionrange": actionMarkerFunc(selectionRangeMarker),
562562
"signature": actionMarkerFunc(signatureMarker),
563563
"snippet": actionMarkerFunc(snippetMarker),
564-
"suggestedfix": actionMarkerFunc(suggestedfixMarker),
565-
"suggestedfixerr": actionMarkerFunc(suggestedfixErrMarker),
564+
"quickfix": actionMarkerFunc(quickfixMarker),
565+
"quickfixerr": actionMarkerFunc(quickfixErrMarker),
566566
"symbol": actionMarkerFunc(symbolMarker),
567567
"token": actionMarkerFunc(tokenMarker),
568568
"typedef": actionMarkerFunc(typedefMarker),
@@ -932,7 +932,7 @@ type markerTestRun struct {
932932
settings map[string]any
933933

934934
// Collected information.
935-
// Each @diag/@suggestedfix marker eliminates an entry from diags.
935+
// Each @diag/@quickfix marker eliminates an entry from diags.
936936
values map[expect.Identifier]any
937937
diags map[protocol.Location][]protocol.Diagnostic // diagnostics by position; location end == start
938938

@@ -2047,13 +2047,11 @@ func (mark marker) consumeExtraNotes(name string, f func(marker)) {
20472047
}
20482048
}
20492049

2050-
// suggestedfixMarker implements the @suggestedfix(location, regexp,
2050+
// quickfixMarker implements the @quickfix(location, regexp,
20512051
// kind, golden) marker. It acts like @diag(location, regexp), to set
20522052
// the expectation of a diagnostic, but then it applies the "quickfix"
20532053
// code action (which must be unique) suggested by the matched diagnostic.
2054-
//
2055-
// TODO(adonovan): rename to @quickfix, since that's the LSP term.
2056-
func suggestedfixMarker(mark marker, loc protocol.Location, re *regexp.Regexp, golden *Golden) {
2054+
func quickfixMarker(mark marker, loc protocol.Location, re *regexp.Regexp, golden *Golden) {
20572055
loc.Range.End = loc.Range.Start // diagnostics ignore end position.
20582056
// Find and remove the matching diagnostic.
20592057
diag, ok := removeDiagnostic(mark, loc, re)
@@ -2065,15 +2063,15 @@ func suggestedfixMarker(mark marker, loc protocol.Location, re *regexp.Regexp, g
20652063
// Apply the fix it suggests.
20662064
changed, err := codeAction(mark.run.env, loc.URI, diag.Range, "quickfix", &diag)
20672065
if err != nil {
2068-
mark.errorf("suggestedfix failed: %v. (Use @suggestedfixerr for expected errors.)", err)
2066+
mark.errorf("quickfix failed: %v. (Use @quickfixerr for expected errors.)", err)
20692067
return
20702068
}
20712069

20722070
// Check the file state.
20732071
checkDiffs(mark, changed, golden)
20742072
}
20752073

2076-
func suggestedfixErrMarker(mark marker, loc protocol.Location, re *regexp.Regexp, wantErr stringMatcher) {
2074+
func quickfixErrMarker(mark marker, loc protocol.Location, re *regexp.Regexp, wantErr stringMatcher) {
20772075
loc.Range.End = loc.Range.Start // diagnostics ignore end position.
20782076
// Find and remove the matching diagnostic.
20792077
diag, ok := removeDiagnostic(mark, loc, re)
@@ -2188,7 +2186,7 @@ func codeActionChanges(env *integration.Env, uri protocol.DocumentURI, rng proto
21882186
//
21892187
// The client makes an ExecuteCommand RPC to the server,
21902188
// which dispatches it to the ApplyFix handler.
2191-
// ApplyFix dispatches to the "stub_methods" suggestedfix hook (the meat).
2189+
// ApplyFix dispatches to the "stub_methods" fixer (the meat).
21922190
// The server then makes an ApplyEdit RPC to the client,
21932191
// whose WorkspaceEditFunc hook temporarily gathers the edits
21942192
// instead of applying them.

gopls/internal/test/marker/testdata/diagnostics/typeerr.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ package a
1919
func f(x int) {
2020
append("") //@diag(re`""`, re"a slice")
2121

22-
x := 123 //@diag(re"x := 123", re"no new variables"), suggestedfix(re"():", re"no new variables", fix)
22+
x := 123 //@diag(re"x := 123", re"no new variables"), quickfix(re"():", re"no new variables", fix)
2323
}
2424

2525
-- @fix/typeerr.go --
2626
@@ -6 +6 @@
27-
- x := 123 //@diag(re"x := 123", re"no new variables"), suggestedfix(re"():", re"no new variables", fix)
28-
+ x = 123 //@diag(re"x := 123", re"no new variables"), suggestedfix(re"():", re"no new variables", fix)
27+
- x := 123 //@diag(re"x := 123", re"no new variables"), quickfix(re"():", re"no new variables", fix)
28+
+ x = 123 //@diag(re"x := 123", re"no new variables"), quickfix(re"():", re"no new variables", fix)

gopls/internal/test/marker/testdata/suggestedfix/embeddirective.txt renamed to gopls/internal/test/marker/testdata/quickfix/embeddirective.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"os"
1111
)
1212

13-
//go:embed embed.txt //@suggestedfix("//go:embed", re`must import "embed"`, fix_import)
13+
//go:embed embed.txt //@quickfix("//go:embed", re`must import "embed"`, fix_import)
1414
var t string
1515

1616
func unused() {

gopls/internal/test/marker/testdata/codeaction/infertypeargs.txt renamed to gopls/internal/test/marker/testdata/quickfix/infertypeargs.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ func app[S interface{ ~[]E }, E interface{}](s S, e E) S {
1515
func _() {
1616
_ = app[[]int]
1717
_ = app[[]int, int]
18-
_ = app[[]int]([]int{}, 0) //@suggestedfix("[[]int]", re"unnecessary type arguments", infer)
18+
_ = app[[]int]([]int{}, 0) //@quickfix("[[]int]", re"unnecessary type arguments", infer)
1919
_ = app([]int{}, 0)
2020
}
2121

2222
-- @infer/p.go --
2323
@@ -10 +10 @@
24-
- _ = app[[]int]([]int{}, 0) //@suggestedfix("[[]int]", re"unnecessary type arguments", infer)
25-
+ _ = app([]int{}, 0) //@suggestedfix("[[]int]", re"unnecessary type arguments", infer)
24+
- _ = app[[]int]([]int{}, 0) //@quickfix("[[]int]", re"unnecessary type arguments", infer)
25+
+ _ = app([]int{}, 0) //@quickfix("[[]int]", re"unnecessary type arguments", infer)

gopls/internal/test/marker/testdata/suggestedfix/issue65024.txt renamed to gopls/internal/test/marker/testdata/quickfix/issue65024.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import "example.com/a/v2"
2222

2323
type B struct{}
2424

25-
var _ a.I = &B{} //@ suggestedfix("&B{}", re"does not implement", out)
25+
var _ a.I = &B{} //@ quickfix("&B{}", re"does not implement", out)
2626

2727
// This line makes the diff tidier.
2828

@@ -55,7 +55,7 @@ package b
5555

5656
type B struct{}
5757

58-
var _ I = &B{} //@ suggestedfix("&B{}", re"does not implement", out2)
58+
var _ I = &B{} //@ quickfix("&B{}", re"does not implement", out2)
5959

6060
// This line makes the diff tidier.
6161

gopls/internal/test/marker/testdata/suggestedfix/missingfunction.txt renamed to gopls/internal/test/marker/testdata/quickfix/missingfunction.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This test checks the quick fix for undefined functions.
44
package missingfunction
55

66
func channels(s string) {
7-
undefinedChannels(c()) //@suggestedfix("undefinedChannels", re"(undeclared|undefined)", channels)
7+
undefinedChannels(c()) //@quickfix("undefinedChannels", re"(undeclared|undefined)", channels)
88
}
99

1010
func c() (<-chan string, chan string) {
@@ -21,7 +21,7 @@ package missingfunction
2121

2222
func consecutiveParams() {
2323
var s string
24-
undefinedConsecutiveParams(s, s) //@suggestedfix("undefinedConsecutiveParams", re"(undeclared|undefined)", consecutive)
24+
undefinedConsecutiveParams(s, s) //@quickfix("undefinedConsecutiveParams", re"(undeclared|undefined)", consecutive)
2525
}
2626
-- @consecutive/consecutive.go --
2727
@@ -7 +7,4 @@
@@ -34,7 +34,7 @@ package missingfunction
3434

3535
func errorParam() {
3636
var err error
37-
undefinedErrorParam(err) //@suggestedfix("undefinedErrorParam", re"(undeclared|undefined)", error)
37+
undefinedErrorParam(err) //@quickfix("undefinedErrorParam", re"(undeclared|undefined)", error)
3838
}
3939
-- @error/error.go --
4040
@@ -7 +7,4 @@
@@ -48,7 +48,7 @@ package missingfunction
4848
type T struct{}
4949

5050
func literals() {
51-
undefinedLiterals("hey compiler", T{}, &T{}) //@suggestedfix("undefinedLiterals", re"(undeclared|undefined)", literals)
51+
undefinedLiterals("hey compiler", T{}, &T{}) //@quickfix("undefinedLiterals", re"(undeclared|undefined)", literals)
5252
}
5353
-- @literals/literals.go --
5454
@@ -8 +8,4 @@
@@ -62,7 +62,7 @@ package missingfunction
6262
import "time"
6363

6464
func operation() {
65-
undefinedOperation(10 * time.Second) //@suggestedfix("undefinedOperation", re"(undeclared|undefined)", operation)
65+
undefinedOperation(10 * time.Second) //@quickfix("undefinedOperation", re"(undeclared|undefined)", operation)
6666
}
6767
-- @operation/operation.go --
6868
@@ -8 +8,4 @@
@@ -75,7 +75,7 @@ package missingfunction
7575

7676
func selector() {
7777
m := map[int]bool{}
78-
undefinedSelector(m[1]) //@suggestedfix("undefinedSelector", re"(undeclared|undefined)", selector)
78+
undefinedSelector(m[1]) //@quickfix("undefinedSelector", re"(undeclared|undefined)", selector)
7979
}
8080
-- @selector/selector.go --
8181
@@ -7 +7,4 @@
@@ -87,7 +87,7 @@ func selector() {
8787
package missingfunction
8888

8989
func slice() {
90-
undefinedSlice([]int{1, 2}) //@suggestedfix("undefinedSlice", re"(undeclared|undefined)", slice)
90+
undefinedSlice([]int{1, 2}) //@quickfix("undefinedSlice", re"(undeclared|undefined)", slice)
9191
}
9292
-- @slice/slice.go --
9393
@@ -6 +6,4 @@
@@ -99,7 +99,7 @@ func slice() {
9999
package missingfunction
100100

101101
func tuple() {
102-
undefinedTuple(b()) //@suggestedfix("undefinedTuple", re"(undeclared|undefined)", tuple)
102+
undefinedTuple(b()) //@quickfix("undefinedTuple", re"(undeclared|undefined)", tuple)
103103
}
104104

105105
func b() (string, error) {
@@ -117,7 +117,7 @@ package missingfunction
117117
func uniqueArguments() {
118118
var s string
119119
var i int
120-
undefinedUniqueArguments(s, i, s) //@suggestedfix("undefinedUniqueArguments", re"(undeclared|undefined)", unique)
120+
undefinedUniqueArguments(s, i, s) //@quickfix("undefinedUniqueArguments", re"(undeclared|undefined)", unique)
121121
}
122122
-- @unique/unique_params.go --
123123
@@ -8 +8,4 @@
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
This test checks the quick fix for removing extra return values.
2+
3+
Note: gopls should really discard unnecessary return statements.
4+
5+
-- noresultvalues.go --
6+
package typeerrors
7+
8+
func x() { return nil } //@quickfix("nil", re"too many return", x)
9+
10+
func y() { return nil, "hello" } //@quickfix("nil", re"too many return", y)
11+
-- @x/noresultvalues.go --
12+
@@ -3 +3 @@
13+
-func x() { return nil } //@quickfix("nil", re"too many return", x)
14+
+func x() { return } //@quickfix("nil", re"too many return", x)
15+
-- @y/noresultvalues.go --
16+
@@ -5 +5 @@
17+
-func y() { return nil, "hello" } //@quickfix("nil", re"too many return", y)
18+
+func y() { return } //@quickfix("nil", re"too many return", y)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Test of the suggested fix to remove unnecessary assignments.
2+
3+
-- a.go --
4+
package quickfix
5+
6+
import (
7+
"log"
8+
)
9+
10+
func goodbye() {
11+
s := "hiiiiiii"
12+
s = s //@quickfix("s = s", re"self-assignment", fix)
13+
log.Print(s)
14+
}
15+
16+
-- @fix/a.go --
17+
@@ -9 +9 @@
18+
- s = s //@quickfix("s = s", re"self-assignment", fix)
19+
+ //@quickfix("s = s", re"self-assignment", fix)

0 commit comments

Comments
 (0)