mirror of
https://github.com/golang/go
synced 2024-11-05 18:36:10 -07:00
e31b568ad1
Now that fillstruct is an analyzer, we can simplify the code that calls it in code_action.go. We introduce a new class of analyzer -- convenience analyzers, which are closer to commands. These represent suggestions that won't necessarily improve the quality or correctness of your code, but they offer small helper functions for the user. This CL also combines the refactor rewrite tests with the suggested fix tests, since they are effectively the same. For now, we only support convenience analyzers when a code action was requested on the same line as the fix. I'm not sure how to otherwise handle this without bothering the user with unnecessary diagnostics. Change-Id: I7f0aa198b5ee9964a907d709bae6380093d4ef21 Reviewed-on: https://go-review.googlesource.com/c/tools/+/237687 Run-TryBot: Rebecca Stambler <rstambler@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
33 lines
934 B
Go
33 lines
934 B
Go
// Copyright 2019 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package cmdtest
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"golang.org/x/tools/internal/lsp/tests"
|
|
"golang.org/x/tools/internal/span"
|
|
)
|
|
|
|
func (r *runner) SuggestedFix(t *testing.T, spn span.Span, actionKinds []string) {
|
|
uri := spn.URI()
|
|
filename := uri.Filename()
|
|
args := []string{"fix", "-a", fmt.Sprintf("%s", spn)}
|
|
for _, kind := range actionKinds {
|
|
if kind == "refactor.rewrite" {
|
|
t.Skip("refactor.rewrite is not yet supported on the command line")
|
|
}
|
|
}
|
|
args = append(args, actionKinds...)
|
|
got, _ := r.NormalizeGoplsCmd(t, args...)
|
|
want := string(r.data.Golden("suggestedfix_"+tests.SpanName(spn), filename, func() ([]byte, error) {
|
|
return []byte(got), nil
|
|
}))
|
|
if want != got {
|
|
t.Errorf("suggested fixes failed for %s: %s", filename, tests.Diff(want, got))
|
|
}
|
|
}
|