зеркало из https://github.com/golang/tools.git
gopls/internal/regtest/marker: port half of the suggestedfix markers
Port the fillstruct and self_assignment suggestedfix marker tests. The fillstruct marker test in particular had incredibly verbose golden content, which made the tests very difficult to read. To mitigate this, introduce a new 'codeactionedit' marker which only stores edits in the golden directory, rather than complete file content. Additionally, narrow the unified diff to have no edges, for brevity. Since none of the fillstruct tests require multi-line ranges, use a single location for the range. Furthermore, standardize on putting locations before action kind in code action markers. This is more consistent with other markers. For golang/go#54845 Change-Id: Id5d713b77fa751bfe8be473b19304376bc3bb139 Reviewed-on: https://go-review.googlesource.com/c/tools/+/539655 Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Родитель
e6864f1e20
Коммит
08edf75c4d
|
@ -485,11 +485,11 @@ func diff3Conflict(path string, xlabel, ylabel string, xedits, yedits []diff.Edi
|
||||||
}
|
}
|
||||||
oldlabel, old := "base", string(contents)
|
oldlabel, old := "base", string(contents)
|
||||||
|
|
||||||
xdiff, err := diff.ToUnified(oldlabel, xlabel, old, xedits)
|
xdiff, err := diff.ToUnified(oldlabel, xlabel, old, xedits, diff.DefaultContextLines)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
ydiff, err := diff.ToUnified(oldlabel, ylabel, old, yedits)
|
ydiff, err := diff.ToUnified(oldlabel, ylabel, old, yedits, diff.DefaultContextLines)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -357,7 +357,7 @@ func populateValue(f *ast.File, pkg *types.Package, typ types.Type) ast.Expr {
|
||||||
case u.Kind() == types.UnsafePointer:
|
case u.Kind() == types.UnsafePointer:
|
||||||
return ast.NewIdent("nil")
|
return ast.NewIdent("nil")
|
||||||
default:
|
default:
|
||||||
panic("unknown basic type")
|
panic(fmt.Sprintf("unknown basic type %v", u))
|
||||||
}
|
}
|
||||||
|
|
||||||
case *types.Map:
|
case *types.Map:
|
||||||
|
|
|
@ -610,7 +610,7 @@ func applyTextEdits(mapper *protocol.Mapper, edits []protocol.TextEdit, flags *E
|
||||||
}
|
}
|
||||||
|
|
||||||
if flags.Diff {
|
if flags.Diff {
|
||||||
unified, err := diff.ToUnified(filename+".orig", filename, string(mapper.Content), renameEdits)
|
unified, err := diff.ToUnified(filename+".orig", filename, string(mapper.Content), renameEdits, diff.DefaultContextLines)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ import (
|
||||||
"golang.org/x/tools/gopls/internal/lsp/source"
|
"golang.org/x/tools/gopls/internal/lsp/source"
|
||||||
"golang.org/x/tools/gopls/internal/lsp/tests"
|
"golang.org/x/tools/gopls/internal/lsp/tests"
|
||||||
"golang.org/x/tools/gopls/internal/lsp/tests/compare"
|
"golang.org/x/tools/gopls/internal/lsp/tests/compare"
|
||||||
|
"golang.org/x/tools/internal/diff"
|
||||||
"golang.org/x/tools/internal/jsonrpc2"
|
"golang.org/x/tools/internal/jsonrpc2"
|
||||||
"golang.org/x/tools/internal/jsonrpc2/servertest"
|
"golang.org/x/tools/internal/jsonrpc2/servertest"
|
||||||
"golang.org/x/tools/internal/testenv"
|
"golang.org/x/tools/internal/testenv"
|
||||||
|
@ -152,12 +153,17 @@ var update = flag.Bool("update", false, "if set, update test data during marker
|
||||||
// completion candidate produced at the given location with provided label
|
// completion candidate produced at the given location with provided label
|
||||||
// results in the given golden state.
|
// results in the given golden state.
|
||||||
//
|
//
|
||||||
// - codeaction(kind, start, end, golden): specifies a codeaction to request
|
// - codeaction(start, end, kind, golden): specifies a code action to request
|
||||||
// for the given range. To support multi-line ranges, the range is defined
|
// for the given range. To support multi-line ranges, the range is defined
|
||||||
// to be between start.Start and end.End. The golden directory contains
|
// to be between start.Start and end.End. The golden directory contains
|
||||||
// changed file content after the code action is applied.
|
// changed file content after the code action is applied.
|
||||||
//
|
//
|
||||||
// - codeactionerr(kind, start, end, wantError): specifies a codeaction that
|
// - codeactionedit(range, kind, golden): a shorter form of codeaction.
|
||||||
|
// Invokes a code action of the given kind for the given in-line range, and
|
||||||
|
// compares the resulting formatted unified *edits* (notably, not the full
|
||||||
|
// file content) with the golden directory.
|
||||||
|
//
|
||||||
|
// - codeactionerr(start, end, kind, wantError): specifies a codeaction that
|
||||||
// fails with an error that matches the expectation.
|
// fails with an error that matches the expectation.
|
||||||
//
|
//
|
||||||
// - codelens(location, title): specifies that a codelens is expected at the
|
// - codelens(location, title): specifies that a codelens is expected at the
|
||||||
|
@ -243,6 +249,9 @@ var update = flag.Bool("update", false, "if set, update test data during marker
|
||||||
// to have exactly one associated code action of the specified kind.
|
// to have exactly one associated code action of the specified kind.
|
||||||
// This action is executed for its editing effects on the source files.
|
// This action is executed for its editing effects on the source files.
|
||||||
// Like rename, the golden directory contains the expected transformed files.
|
// Like rename, the golden directory contains the expected transformed files.
|
||||||
|
// TODO(rfindley): we probably only need 'suggestedfix' for quick-fixes. All
|
||||||
|
// other actions should use codeaction markers. In that case, we can remove
|
||||||
|
// the 'kind' parameter.
|
||||||
//
|
//
|
||||||
// - rank(location, ...completionItem): executes a textDocument/completion
|
// - rank(location, ...completionItem): executes a textDocument/completion
|
||||||
// request at the given location, and verifies that each expected
|
// request at the given location, and verifies that each expected
|
||||||
|
@ -708,6 +717,7 @@ var valueMarkerFuncs = map[string]func(marker){
|
||||||
var actionMarkerFuncs = map[string]func(marker){
|
var actionMarkerFuncs = map[string]func(marker){
|
||||||
"acceptcompletion": actionMarkerFunc(acceptCompletionMarker),
|
"acceptcompletion": actionMarkerFunc(acceptCompletionMarker),
|
||||||
"codeaction": actionMarkerFunc(codeActionMarker),
|
"codeaction": actionMarkerFunc(codeActionMarker),
|
||||||
|
"codeactionedit": actionMarkerFunc(codeActionEditMarker),
|
||||||
"codeactionerr": actionMarkerFunc(codeActionErrMarker),
|
"codeactionerr": actionMarkerFunc(codeActionErrMarker),
|
||||||
"codelenses": actionMarkerFunc(codeLensesMarker),
|
"codelenses": actionMarkerFunc(codeLensesMarker),
|
||||||
"complete": actionMarkerFunc(completeMarker),
|
"complete": actionMarkerFunc(completeMarker),
|
||||||
|
@ -1420,6 +1430,41 @@ func checkChangedFiles(mark marker, changed map[string][]byte, golden *Golden) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// checkDiffs computes unified diffs for each changed file, and compares with
|
||||||
|
// the diff content stored in the given golden directory.
|
||||||
|
func checkDiffs(mark marker, changed map[string][]byte, golden *Golden) {
|
||||||
|
diffs := make(map[string]string)
|
||||||
|
for name, after := range changed {
|
||||||
|
before := mark.run.env.FileContent(name)
|
||||||
|
edits := diff.Strings(before, string(after))
|
||||||
|
d, err := diff.ToUnified("before", "after", before, edits, 0)
|
||||||
|
if err != nil {
|
||||||
|
// Can't happen: edits are consistent.
|
||||||
|
log.Fatalf("internal error in diff.ToUnified: %v", err)
|
||||||
|
}
|
||||||
|
diffs[name] = d
|
||||||
|
}
|
||||||
|
// Check changed files match expectations.
|
||||||
|
for filename, got := range diffs {
|
||||||
|
if want, ok := golden.Get(mark.run.env.T, filename, []byte(got)); !ok {
|
||||||
|
mark.errorf("%s: unexpected change to file %s; got diff:\n%s",
|
||||||
|
mark.note.Name, filename, got)
|
||||||
|
|
||||||
|
} else if got != string(want) {
|
||||||
|
mark.errorf("%s: wrong diff for %s:\n\ngot:\n%s\n\nwant:\n%s\n",
|
||||||
|
mark.note.Name, filename, got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Report unmet expectations.
|
||||||
|
for filename := range golden.data {
|
||||||
|
if _, ok := changed[filename]; !ok {
|
||||||
|
want, _ := golden.Get(mark.run.env.T, filename, nil)
|
||||||
|
mark.errorf("%s: missing change to file %s; want:\n%s",
|
||||||
|
mark.note.Name, filename, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ---- marker functions ----
|
// ---- marker functions ----
|
||||||
|
|
||||||
// TODO(rfindley): consolidate documentation of these markers. They are already
|
// TODO(rfindley): consolidate documentation of these markers. They are already
|
||||||
|
@ -1887,7 +1932,7 @@ func applyDocumentChanges(env *Env, changes []protocol.DocumentChanges, fileChan
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func codeActionMarker(mark marker, actionKind string, start, end protocol.Location, golden *Golden) {
|
func codeActionMarker(mark marker, start, end protocol.Location, actionKind string, g *Golden) {
|
||||||
// Request the range from start.Start to end.End.
|
// Request the range from start.Start to end.End.
|
||||||
loc := start
|
loc := start
|
||||||
loc.Range.End = end.Range.End
|
loc.Range.End = end.Range.End
|
||||||
|
@ -1900,10 +1945,20 @@ func codeActionMarker(mark marker, actionKind string, start, end protocol.Locati
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the file state.
|
// Check the file state.
|
||||||
checkChangedFiles(mark, changed, golden)
|
checkChangedFiles(mark, changed, g)
|
||||||
}
|
}
|
||||||
|
|
||||||
func codeActionErrMarker(mark marker, actionKind string, start, end protocol.Location, wantErr wantError) {
|
func codeActionEditMarker(mark marker, loc protocol.Location, actionKind string, g *Golden) {
|
||||||
|
changed, err := codeAction(mark.run.env, loc.URI, loc.Range, actionKind, nil)
|
||||||
|
if err != nil {
|
||||||
|
mark.errorf("codeAction failed: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
checkDiffs(mark, changed, g)
|
||||||
|
}
|
||||||
|
|
||||||
|
func codeActionErrMarker(mark marker, start, end protocol.Location, actionKind string, wantErr wantError) {
|
||||||
loc := start
|
loc := start
|
||||||
loc.Range.End = end.Range.End
|
loc.Range.End = end.Range.End
|
||||||
_, err := codeAction(mark.run.env, loc.URI, loc.Range, actionKind, nil)
|
_, err := codeAction(mark.run.env, loc.URI, loc.Range, actionKind, nil)
|
||||||
|
@ -2008,6 +2063,21 @@ func suggestedfixMarker(mark marker, loc protocol.Location, re *regexp.Regexp, a
|
||||||
// applied. Currently, this function does not support code actions that return
|
// applied. Currently, this function does not support code actions that return
|
||||||
// edits directly; it only supports code action commands.
|
// edits directly; it only supports code action commands.
|
||||||
func codeAction(env *Env, uri protocol.DocumentURI, rng protocol.Range, actionKind string, diag *protocol.Diagnostic) (map[string][]byte, error) {
|
func codeAction(env *Env, uri protocol.DocumentURI, rng protocol.Range, actionKind string, diag *protocol.Diagnostic) (map[string][]byte, error) {
|
||||||
|
changes, err := codeActionChanges(env, uri, rng, actionKind, diag)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
fileChanges := make(map[string][]byte)
|
||||||
|
if err := applyDocumentChanges(env, changes, fileChanges); err != nil {
|
||||||
|
return nil, fmt.Errorf("applying document changes: %v", err)
|
||||||
|
}
|
||||||
|
return fileChanges, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// codeActionChanges executes a textDocument/codeAction request for the
|
||||||
|
// specified location and kind, and captures the resulting document changes.
|
||||||
|
// If diag is non-nil, it is used as the code action context.
|
||||||
|
func codeActionChanges(env *Env, uri protocol.DocumentURI, rng protocol.Range, actionKind string, diag *protocol.Diagnostic) ([]protocol.DocumentChanges, error) {
|
||||||
// Request all code actions that apply to the diagnostic.
|
// Request all code actions that apply to the diagnostic.
|
||||||
// (The protocol supports filtering using Context.Only={actionKind}
|
// (The protocol supports filtering using Context.Only={actionKind}
|
||||||
// but we can give a better error if we don't filter.)
|
// but we can give a better error if we don't filter.)
|
||||||
|
@ -2047,20 +2117,19 @@ func codeAction(env *Env, uri protocol.DocumentURI, rng protocol.Range, actionKi
|
||||||
// Spec:
|
// Spec:
|
||||||
// "If a code action provides an edit and a command, first the edit is
|
// "If a code action provides an edit and a command, first the edit is
|
||||||
// executed and then the command."
|
// executed and then the command."
|
||||||
fileChanges := make(map[string][]byte)
|
|
||||||
// An action may specify an edit and/or a command, to be
|
// An action may specify an edit and/or a command, to be
|
||||||
// applied in that order. But since applyDocumentChanges(env,
|
// applied in that order. But since applyDocumentChanges(env,
|
||||||
// action.Edit.DocumentChanges) doesn't compose, for now we
|
// action.Edit.DocumentChanges) doesn't compose, for now we
|
||||||
// assert that all commands used in the @suggestedfix tests
|
// assert that actions return one or the other.
|
||||||
// return only a command.
|
|
||||||
if action.Edit != nil {
|
if action.Edit != nil {
|
||||||
if action.Edit.Changes != nil {
|
if action.Edit.Changes != nil {
|
||||||
env.T.Errorf("internal error: discarding unexpected CodeAction{Kind=%s, Title=%q}.Edit.Changes", action.Kind, action.Title)
|
env.T.Errorf("internal error: discarding unexpected CodeAction{Kind=%s, Title=%q}.Edit.Changes", action.Kind, action.Title)
|
||||||
}
|
}
|
||||||
if action.Edit.DocumentChanges != nil {
|
if action.Edit.DocumentChanges != nil {
|
||||||
if err := applyDocumentChanges(env, action.Edit.DocumentChanges, fileChanges); err != nil {
|
if action.Command != nil {
|
||||||
return nil, fmt.Errorf("applying document changes: %v", err)
|
env.T.Errorf("internal error: discarding unexpected CodeAction{Kind=%s, Title=%q}.Command", action.Kind, action.Title)
|
||||||
}
|
}
|
||||||
|
return action.Edit.DocumentChanges, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2085,13 +2154,10 @@ func codeAction(env *Env, uri protocol.DocumentURI, rng protocol.Range, actionKi
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
return env.Awaiter.takeDocumentChanges(), nil
|
||||||
if err := applyDocumentChanges(env, env.Awaiter.takeDocumentChanges(), fileChanges); err != nil {
|
|
||||||
return nil, fmt.Errorf("applying document changes from command: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return fileChanges, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(adonovan): suggestedfixerr
|
// TODO(adonovan): suggestedfixerr
|
||||||
|
|
|
@ -114,6 +114,18 @@ func (e *Env) SetBufferContent(name string, content string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReadFile returns the file content for name that applies to the current
|
||||||
|
// editing session: if the file is open, it returns its buffer content,
|
||||||
|
// otherwise it returns on disk content.
|
||||||
|
func (e *Env) FileContent(name string) string {
|
||||||
|
e.T.Helper()
|
||||||
|
text, ok := e.Editor.BufferText(name)
|
||||||
|
if ok {
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
return e.ReadWorkspaceFile(name)
|
||||||
|
}
|
||||||
|
|
||||||
// RegexpSearch returns the starting position of the first match for re in the
|
// RegexpSearch returns the starting position of the first match for re in the
|
||||||
// buffer specified by name, calling t.Fatal on any error. It first searches
|
// buffer specified by name, calling t.Fatal on any error. It first searches
|
||||||
// for the position in open buffers, then in workspace files.
|
// for the position in open buffers, then in workspace files.
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
import (
|
|
||||||
"golang.org/lsptests/fillstruct/data"
|
|
||||||
)
|
|
||||||
|
|
||||||
type basicStruct struct {
|
|
||||||
foo int
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = basicStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type twoArgStruct struct {
|
|
||||||
foo int
|
|
||||||
bar string
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = twoArgStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type nestedStruct struct {
|
|
||||||
bar string
|
|
||||||
basic basicStruct
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = nestedStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var _ = data.B{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
|
@ -1,126 +0,0 @@
|
||||||
-- suggestedfix_a_11_21 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
import (
|
|
||||||
"golang.org/lsptests/fillstruct/data"
|
|
||||||
)
|
|
||||||
|
|
||||||
type basicStruct struct {
|
|
||||||
foo int
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = basicStruct{
|
|
||||||
foo: 0,
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type twoArgStruct struct {
|
|
||||||
foo int
|
|
||||||
bar string
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = twoArgStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type nestedStruct struct {
|
|
||||||
bar string
|
|
||||||
basic basicStruct
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = nestedStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var _ = data.B{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
-- suggestedfix_a_18_22 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
import (
|
|
||||||
"golang.org/lsptests/fillstruct/data"
|
|
||||||
)
|
|
||||||
|
|
||||||
type basicStruct struct {
|
|
||||||
foo int
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = basicStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type twoArgStruct struct {
|
|
||||||
foo int
|
|
||||||
bar string
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = twoArgStruct{
|
|
||||||
foo: 0,
|
|
||||||
bar: "",
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type nestedStruct struct {
|
|
||||||
bar string
|
|
||||||
basic basicStruct
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = nestedStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var _ = data.B{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
-- suggestedfix_a_25_22 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
import (
|
|
||||||
"golang.org/lsptests/fillstruct/data"
|
|
||||||
)
|
|
||||||
|
|
||||||
type basicStruct struct {
|
|
||||||
foo int
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = basicStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type twoArgStruct struct {
|
|
||||||
foo int
|
|
||||||
bar string
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = twoArgStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type nestedStruct struct {
|
|
||||||
bar string
|
|
||||||
basic basicStruct
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = nestedStruct{
|
|
||||||
bar: "",
|
|
||||||
basic: basicStruct{},
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var _ = data.B{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
-- suggestedfix_a_27_16 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
import (
|
|
||||||
"golang.org/lsptests/fillstruct/data"
|
|
||||||
)
|
|
||||||
|
|
||||||
type basicStruct struct {
|
|
||||||
foo int
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = basicStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type twoArgStruct struct {
|
|
||||||
foo int
|
|
||||||
bar string
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = twoArgStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type nestedStruct struct {
|
|
||||||
bar string
|
|
||||||
basic basicStruct
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = nestedStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var _ = data.B{
|
|
||||||
ExportedInt: 0,
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
type typedStruct struct {
|
|
||||||
m map[string]int
|
|
||||||
s []int
|
|
||||||
c chan int
|
|
||||||
c1 <-chan int
|
|
||||||
a [2]string
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = typedStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type funStruct struct {
|
|
||||||
fn func(i int) int
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = funStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type funStructCompex struct {
|
|
||||||
fn func(i int, s string) (string, int)
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = funStructCompex{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type funStructEmpty struct {
|
|
||||||
fn func()
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = funStructEmpty{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
|
@ -1,139 +0,0 @@
|
||||||
-- suggestedfix_a2_11_21 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
type typedStruct struct {
|
|
||||||
m map[string]int
|
|
||||||
s []int
|
|
||||||
c chan int
|
|
||||||
c1 <-chan int
|
|
||||||
a [2]string
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = typedStruct{
|
|
||||||
m: map[string]int{},
|
|
||||||
s: []int{},
|
|
||||||
c: make(chan int),
|
|
||||||
c1: make(<-chan int),
|
|
||||||
a: [2]string{},
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type funStruct struct {
|
|
||||||
fn func(i int) int
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = funStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type funStructCompex struct {
|
|
||||||
fn func(i int, s string) (string, int)
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = funStructCompex{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type funStructEmpty struct {
|
|
||||||
fn func()
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = funStructEmpty{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
-- suggestedfix_a2_17_19 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
type typedStruct struct {
|
|
||||||
m map[string]int
|
|
||||||
s []int
|
|
||||||
c chan int
|
|
||||||
c1 <-chan int
|
|
||||||
a [2]string
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = typedStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type funStruct struct {
|
|
||||||
fn func(i int) int
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = funStruct{
|
|
||||||
fn: func(i int) int {
|
|
||||||
},
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type funStructCompex struct {
|
|
||||||
fn func(i int, s string) (string, int)
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = funStructCompex{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type funStructEmpty struct {
|
|
||||||
fn func()
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = funStructEmpty{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
-- suggestedfix_a2_23_25 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
type typedStruct struct {
|
|
||||||
m map[string]int
|
|
||||||
s []int
|
|
||||||
c chan int
|
|
||||||
c1 <-chan int
|
|
||||||
a [2]string
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = typedStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type funStruct struct {
|
|
||||||
fn func(i int) int
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = funStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type funStructCompex struct {
|
|
||||||
fn func(i int, s string) (string, int)
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = funStructCompex{
|
|
||||||
fn: func(i int, s string) (string, int) {
|
|
||||||
},
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type funStructEmpty struct {
|
|
||||||
fn func()
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = funStructEmpty{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
-- suggestedfix_a2_29_24 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
type typedStruct struct {
|
|
||||||
m map[string]int
|
|
||||||
s []int
|
|
||||||
c chan int
|
|
||||||
c1 <-chan int
|
|
||||||
a [2]string
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = typedStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type funStruct struct {
|
|
||||||
fn func(i int) int
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = funStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type funStructCompex struct {
|
|
||||||
fn func(i int, s string) (string, int)
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = funStructCompex{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type funStructEmpty struct {
|
|
||||||
fn func()
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = funStructEmpty{
|
|
||||||
fn: func() {
|
|
||||||
},
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go/ast"
|
|
||||||
"go/token"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Foo struct {
|
|
||||||
A int
|
|
||||||
}
|
|
||||||
|
|
||||||
type Bar struct {
|
|
||||||
X *Foo
|
|
||||||
Y *Foo
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = Bar{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type importedStruct struct {
|
|
||||||
m map[*ast.CompositeLit]ast.Field
|
|
||||||
s []ast.BadExpr
|
|
||||||
a [3]token.Token
|
|
||||||
c chan ast.EmptyStmt
|
|
||||||
fn func(ast_decl ast.DeclStmt) ast.Ellipsis
|
|
||||||
st ast.CompositeLit
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type pointerBuiltinStruct struct {
|
|
||||||
b *bool
|
|
||||||
s *string
|
|
||||||
i *int
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var _ = []ast.BasicLit{
|
|
||||||
{}, //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
|
@ -1,243 +0,0 @@
|
||||||
-- suggestedfix_a3_17_13 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go/ast"
|
|
||||||
"go/token"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Foo struct {
|
|
||||||
A int
|
|
||||||
}
|
|
||||||
|
|
||||||
type Bar struct {
|
|
||||||
X *Foo
|
|
||||||
Y *Foo
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = Bar{
|
|
||||||
X: &Foo{},
|
|
||||||
Y: &Foo{},
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type importedStruct struct {
|
|
||||||
m map[*ast.CompositeLit]ast.Field
|
|
||||||
s []ast.BadExpr
|
|
||||||
a [3]token.Token
|
|
||||||
c chan ast.EmptyStmt
|
|
||||||
fn func(ast_decl ast.DeclStmt) ast.Ellipsis
|
|
||||||
st ast.CompositeLit
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type pointerBuiltinStruct struct {
|
|
||||||
b *bool
|
|
||||||
s *string
|
|
||||||
i *int
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var _ = []ast.BasicLit{
|
|
||||||
{}, //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
-- suggestedfix_a3_28_24 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go/ast"
|
|
||||||
"go/token"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Foo struct {
|
|
||||||
A int
|
|
||||||
}
|
|
||||||
|
|
||||||
type Bar struct {
|
|
||||||
X *Foo
|
|
||||||
Y *Foo
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = Bar{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type importedStruct struct {
|
|
||||||
m map[*ast.CompositeLit]ast.Field
|
|
||||||
s []ast.BadExpr
|
|
||||||
a [3]token.Token
|
|
||||||
c chan ast.EmptyStmt
|
|
||||||
fn func(ast_decl ast.DeclStmt) ast.Ellipsis
|
|
||||||
st ast.CompositeLit
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = importedStruct{
|
|
||||||
m: map[*ast.CompositeLit]ast.Field{},
|
|
||||||
s: []ast.BadExpr{},
|
|
||||||
a: [3]token.Token{},
|
|
||||||
c: make(chan ast.EmptyStmt),
|
|
||||||
fn: func(ast_decl ast.DeclStmt) ast.Ellipsis {
|
|
||||||
},
|
|
||||||
st: ast.CompositeLit{},
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type pointerBuiltinStruct struct {
|
|
||||||
b *bool
|
|
||||||
s *string
|
|
||||||
i *int
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var _ = []ast.BasicLit{
|
|
||||||
{}, //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
-- suggestedfix_a3_36_30 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go/ast"
|
|
||||||
"go/token"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Foo struct {
|
|
||||||
A int
|
|
||||||
}
|
|
||||||
|
|
||||||
type Bar struct {
|
|
||||||
X *Foo
|
|
||||||
Y *Foo
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = Bar{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type importedStruct struct {
|
|
||||||
m map[*ast.CompositeLit]ast.Field
|
|
||||||
s []ast.BadExpr
|
|
||||||
a [3]token.Token
|
|
||||||
c chan ast.EmptyStmt
|
|
||||||
fn func(ast_decl ast.DeclStmt) ast.Ellipsis
|
|
||||||
st ast.CompositeLit
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type pointerBuiltinStruct struct {
|
|
||||||
b *bool
|
|
||||||
s *string
|
|
||||||
i *int
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = pointerBuiltinStruct{
|
|
||||||
b: new(bool),
|
|
||||||
s: new(string),
|
|
||||||
i: new(int),
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var _ = []ast.BasicLit{
|
|
||||||
{}, //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
-- suggestedfix_a3_39_3 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go/ast"
|
|
||||||
"go/token"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Foo struct {
|
|
||||||
A int
|
|
||||||
}
|
|
||||||
|
|
||||||
type Bar struct {
|
|
||||||
X *Foo
|
|
||||||
Y *Foo
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = Bar{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type importedStruct struct {
|
|
||||||
m map[*ast.CompositeLit]ast.Field
|
|
||||||
s []ast.BadExpr
|
|
||||||
a [3]token.Token
|
|
||||||
c chan ast.EmptyStmt
|
|
||||||
fn func(ast_decl ast.DeclStmt) ast.Ellipsis
|
|
||||||
st ast.CompositeLit
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type pointerBuiltinStruct struct {
|
|
||||||
b *bool
|
|
||||||
s *string
|
|
||||||
i *int
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var _ = []ast.BasicLit{
|
|
||||||
{
|
|
||||||
ValuePos: 0,
|
|
||||||
Kind: 0,
|
|
||||||
Value: "",
|
|
||||||
}, //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
-- suggestedfix_a3_42_25 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go/ast"
|
|
||||||
"go/token"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Foo struct {
|
|
||||||
A int
|
|
||||||
}
|
|
||||||
|
|
||||||
type Bar struct {
|
|
||||||
X *Foo
|
|
||||||
Y *Foo
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = Bar{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type importedStruct struct {
|
|
||||||
m map[*ast.CompositeLit]ast.Field
|
|
||||||
s []ast.BadExpr
|
|
||||||
a [3]token.Token
|
|
||||||
c chan ast.EmptyStmt
|
|
||||||
fn func(ast_decl ast.DeclStmt) ast.Ellipsis
|
|
||||||
st ast.CompositeLit
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type pointerBuiltinStruct struct {
|
|
||||||
b *bool
|
|
||||||
s *string
|
|
||||||
i *int
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var _ = []ast.BasicLit{
|
|
||||||
{}, //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = []ast.BasicLit{{
|
|
||||||
ValuePos: 0,
|
|
||||||
Kind: 0,
|
|
||||||
Value: "",
|
|
||||||
}} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
import "go/ast"
|
|
||||||
|
|
||||||
type iStruct struct {
|
|
||||||
X int
|
|
||||||
}
|
|
||||||
|
|
||||||
type sStruct struct {
|
|
||||||
str string
|
|
||||||
}
|
|
||||||
|
|
||||||
type multiFill struct {
|
|
||||||
num int
|
|
||||||
strin string
|
|
||||||
arr []int
|
|
||||||
}
|
|
||||||
|
|
||||||
type assignStruct struct {
|
|
||||||
n ast.Node
|
|
||||||
}
|
|
||||||
|
|
||||||
func fill() {
|
|
||||||
var x int
|
|
||||||
var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var s string
|
|
||||||
var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var n int
|
|
||||||
_ = []int{}
|
|
||||||
if true {
|
|
||||||
arr := []int{1, 2}
|
|
||||||
}
|
|
||||||
var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var node *ast.CompositeLit
|
|
||||||
var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
|
@ -1,174 +0,0 @@
|
||||||
-- suggestedfix_a4_25_18 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
import "go/ast"
|
|
||||||
|
|
||||||
type iStruct struct {
|
|
||||||
X int
|
|
||||||
}
|
|
||||||
|
|
||||||
type sStruct struct {
|
|
||||||
str string
|
|
||||||
}
|
|
||||||
|
|
||||||
type multiFill struct {
|
|
||||||
num int
|
|
||||||
strin string
|
|
||||||
arr []int
|
|
||||||
}
|
|
||||||
|
|
||||||
type assignStruct struct {
|
|
||||||
n ast.Node
|
|
||||||
}
|
|
||||||
|
|
||||||
func fill() {
|
|
||||||
var x int
|
|
||||||
var _ = iStruct{
|
|
||||||
X: x,
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var s string
|
|
||||||
var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var n int
|
|
||||||
_ = []int{}
|
|
||||||
if true {
|
|
||||||
arr := []int{1, 2}
|
|
||||||
}
|
|
||||||
var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var node *ast.CompositeLit
|
|
||||||
var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
|
|
||||||
-- suggestedfix_a4_28_18 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
import "go/ast"
|
|
||||||
|
|
||||||
type iStruct struct {
|
|
||||||
X int
|
|
||||||
}
|
|
||||||
|
|
||||||
type sStruct struct {
|
|
||||||
str string
|
|
||||||
}
|
|
||||||
|
|
||||||
type multiFill struct {
|
|
||||||
num int
|
|
||||||
strin string
|
|
||||||
arr []int
|
|
||||||
}
|
|
||||||
|
|
||||||
type assignStruct struct {
|
|
||||||
n ast.Node
|
|
||||||
}
|
|
||||||
|
|
||||||
func fill() {
|
|
||||||
var x int
|
|
||||||
var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var s string
|
|
||||||
var _ = sStruct{
|
|
||||||
str: s,
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var n int
|
|
||||||
_ = []int{}
|
|
||||||
if true {
|
|
||||||
arr := []int{1, 2}
|
|
||||||
}
|
|
||||||
var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var node *ast.CompositeLit
|
|
||||||
var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
|
|
||||||
-- suggestedfix_a4_35_20 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
import "go/ast"
|
|
||||||
|
|
||||||
type iStruct struct {
|
|
||||||
X int
|
|
||||||
}
|
|
||||||
|
|
||||||
type sStruct struct {
|
|
||||||
str string
|
|
||||||
}
|
|
||||||
|
|
||||||
type multiFill struct {
|
|
||||||
num int
|
|
||||||
strin string
|
|
||||||
arr []int
|
|
||||||
}
|
|
||||||
|
|
||||||
type assignStruct struct {
|
|
||||||
n ast.Node
|
|
||||||
}
|
|
||||||
|
|
||||||
func fill() {
|
|
||||||
var x int
|
|
||||||
var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var s string
|
|
||||||
var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var n int
|
|
||||||
_ = []int{}
|
|
||||||
if true {
|
|
||||||
arr := []int{1, 2}
|
|
||||||
}
|
|
||||||
var _ = multiFill{
|
|
||||||
num: n,
|
|
||||||
strin: s,
|
|
||||||
arr: []int{},
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var node *ast.CompositeLit
|
|
||||||
var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
|
|
||||||
-- suggestedfix_a4_38_23 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
import "go/ast"
|
|
||||||
|
|
||||||
type iStruct struct {
|
|
||||||
X int
|
|
||||||
}
|
|
||||||
|
|
||||||
type sStruct struct {
|
|
||||||
str string
|
|
||||||
}
|
|
||||||
|
|
||||||
type multiFill struct {
|
|
||||||
num int
|
|
||||||
strin string
|
|
||||||
arr []int
|
|
||||||
}
|
|
||||||
|
|
||||||
type assignStruct struct {
|
|
||||||
n ast.Node
|
|
||||||
}
|
|
||||||
|
|
||||||
func fill() {
|
|
||||||
var x int
|
|
||||||
var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var s string
|
|
||||||
var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var n int
|
|
||||||
_ = []int{}
|
|
||||||
if true {
|
|
||||||
arr := []int{1, 2}
|
|
||||||
}
|
|
||||||
var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var node *ast.CompositeLit
|
|
||||||
var _ = assignStruct{
|
|
||||||
n: node,
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
package data
|
|
||||||
|
|
||||||
type B struct {
|
|
||||||
ExportedInt int
|
|
||||||
unexportedInt int
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
type StructA struct {
|
|
||||||
unexportedIntField int
|
|
||||||
ExportedIntField int
|
|
||||||
MapA map[int]string
|
|
||||||
Array []int
|
|
||||||
StructB
|
|
||||||
}
|
|
||||||
|
|
||||||
type StructA2 struct {
|
|
||||||
B *StructB
|
|
||||||
}
|
|
||||||
|
|
||||||
type StructA3 struct {
|
|
||||||
B StructB
|
|
||||||
}
|
|
||||||
|
|
||||||
func fill() {
|
|
||||||
a := StructA{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
b := StructA2{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
c := StructA3{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
if true {
|
|
||||||
_ = StructA3{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,124 +0,0 @@
|
||||||
-- suggestedfix_fill_struct_20_15 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
type StructA struct {
|
|
||||||
unexportedIntField int
|
|
||||||
ExportedIntField int
|
|
||||||
MapA map[int]string
|
|
||||||
Array []int
|
|
||||||
StructB
|
|
||||||
}
|
|
||||||
|
|
||||||
type StructA2 struct {
|
|
||||||
B *StructB
|
|
||||||
}
|
|
||||||
|
|
||||||
type StructA3 struct {
|
|
||||||
B StructB
|
|
||||||
}
|
|
||||||
|
|
||||||
func fill() {
|
|
||||||
a := StructA{
|
|
||||||
unexportedIntField: 0,
|
|
||||||
ExportedIntField: 0,
|
|
||||||
MapA: map[int]string{},
|
|
||||||
Array: []int{},
|
|
||||||
StructB: StructB{},
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
b := StructA2{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
c := StructA3{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
if true {
|
|
||||||
_ = StructA3{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
-- suggestedfix_fill_struct_21_16 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
type StructA struct {
|
|
||||||
unexportedIntField int
|
|
||||||
ExportedIntField int
|
|
||||||
MapA map[int]string
|
|
||||||
Array []int
|
|
||||||
StructB
|
|
||||||
}
|
|
||||||
|
|
||||||
type StructA2 struct {
|
|
||||||
B *StructB
|
|
||||||
}
|
|
||||||
|
|
||||||
type StructA3 struct {
|
|
||||||
B StructB
|
|
||||||
}
|
|
||||||
|
|
||||||
func fill() {
|
|
||||||
a := StructA{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
b := StructA2{
|
|
||||||
B: &StructB{},
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
c := StructA3{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
if true {
|
|
||||||
_ = StructA3{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
-- suggestedfix_fill_struct_22_16 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
type StructA struct {
|
|
||||||
unexportedIntField int
|
|
||||||
ExportedIntField int
|
|
||||||
MapA map[int]string
|
|
||||||
Array []int
|
|
||||||
StructB
|
|
||||||
}
|
|
||||||
|
|
||||||
type StructA2 struct {
|
|
||||||
B *StructB
|
|
||||||
}
|
|
||||||
|
|
||||||
type StructA3 struct {
|
|
||||||
B StructB
|
|
||||||
}
|
|
||||||
|
|
||||||
func fill() {
|
|
||||||
a := StructA{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
b := StructA2{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
c := StructA3{
|
|
||||||
B: StructB{},
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
if true {
|
|
||||||
_ = StructA3{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
-- suggestedfix_fill_struct_24_16 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
type StructA struct {
|
|
||||||
unexportedIntField int
|
|
||||||
ExportedIntField int
|
|
||||||
MapA map[int]string
|
|
||||||
Array []int
|
|
||||||
StructB
|
|
||||||
}
|
|
||||||
|
|
||||||
type StructA2 struct {
|
|
||||||
B *StructB
|
|
||||||
}
|
|
||||||
|
|
||||||
type StructA3 struct {
|
|
||||||
B StructB
|
|
||||||
}
|
|
||||||
|
|
||||||
func fill() {
|
|
||||||
a := StructA{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
b := StructA2{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
c := StructA3{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
if true {
|
|
||||||
_ = StructA3{
|
|
||||||
B: StructB{},
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
type StructAnon struct {
|
|
||||||
a struct{}
|
|
||||||
b map[string]interface{}
|
|
||||||
c map[string]struct {
|
|
||||||
d int
|
|
||||||
e bool
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func fill() {
|
|
||||||
_ := StructAnon{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
-- suggestedfix_fill_struct_anon_13_18 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
type StructAnon struct {
|
|
||||||
a struct{}
|
|
||||||
b map[string]interface{}
|
|
||||||
c map[string]struct {
|
|
||||||
d int
|
|
||||||
e bool
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func fill() {
|
|
||||||
_ := StructAnon{
|
|
||||||
a: struct{}{},
|
|
||||||
b: map[string]interface{}{},
|
|
||||||
c: map[string]struct{d int; e bool}{},
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
type StructB struct {
|
|
||||||
StructC
|
|
||||||
}
|
|
||||||
|
|
||||||
type StructC struct {
|
|
||||||
unexportedInt int
|
|
||||||
}
|
|
||||||
|
|
||||||
func nested() {
|
|
||||||
c := StructB{
|
|
||||||
StructC: StructC{}, //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
-- suggestedfix_fill_struct_nested_13_20 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
type StructB struct {
|
|
||||||
StructC
|
|
||||||
}
|
|
||||||
|
|
||||||
type StructC struct {
|
|
||||||
unexportedInt int
|
|
||||||
}
|
|
||||||
|
|
||||||
func nested() {
|
|
||||||
c := StructB{
|
|
||||||
StructC: StructC{
|
|
||||||
unexportedInt: 0,
|
|
||||||
}, //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
import (
|
|
||||||
h2 "net/http"
|
|
||||||
|
|
||||||
"golang.org/lsptests/fillstruct/data"
|
|
||||||
)
|
|
||||||
|
|
||||||
func unexported() {
|
|
||||||
a := data.B{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
_ = h2.Client{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
-- suggestedfix_fill_struct_package_10_14 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
import (
|
|
||||||
h2 "net/http"
|
|
||||||
|
|
||||||
"golang.org/lsptests/fillstruct/data"
|
|
||||||
)
|
|
||||||
|
|
||||||
func unexported() {
|
|
||||||
a := data.B{
|
|
||||||
ExportedInt: 0,
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
_ = h2.Client{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
|
|
||||||
-- suggestedfix_fill_struct_package_11_16 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
import (
|
|
||||||
h2 "net/http"
|
|
||||||
|
|
||||||
"golang.org/lsptests/fillstruct/data"
|
|
||||||
)
|
|
||||||
|
|
||||||
func unexported() {
|
|
||||||
a := data.B{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
_ = h2.Client{
|
|
||||||
Transport: nil,
|
|
||||||
CheckRedirect: func(req *h2.Request, via []*h2.Request) error {
|
|
||||||
},
|
|
||||||
Jar: nil,
|
|
||||||
Timeout: 0,
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
type StructPartialA struct {
|
|
||||||
PrefilledInt int
|
|
||||||
UnfilledInt int
|
|
||||||
StructPartialB
|
|
||||||
}
|
|
||||||
|
|
||||||
type StructPartialB struct {
|
|
||||||
PrefilledInt int
|
|
||||||
UnfilledInt int
|
|
||||||
}
|
|
||||||
|
|
||||||
func fill() {
|
|
||||||
a := StructPartialA{
|
|
||||||
PrefilledInt: 5,
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
b := StructPartialB{
|
|
||||||
/* this comment should disappear */
|
|
||||||
PrefilledInt: 7, // This comment should be blown away.
|
|
||||||
/* As should
|
|
||||||
this one */
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
|
@ -1,52 +0,0 @@
|
||||||
-- suggestedfix_fill_struct_partial_17_2 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
type StructPartialA struct {
|
|
||||||
PrefilledInt int
|
|
||||||
UnfilledInt int
|
|
||||||
StructPartialB
|
|
||||||
}
|
|
||||||
|
|
||||||
type StructPartialB struct {
|
|
||||||
PrefilledInt int
|
|
||||||
UnfilledInt int
|
|
||||||
}
|
|
||||||
|
|
||||||
func fill() {
|
|
||||||
a := StructPartialA{
|
|
||||||
PrefilledInt: 5,
|
|
||||||
UnfilledInt: 0,
|
|
||||||
StructPartialB: StructPartialB{},
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
b := StructPartialB{
|
|
||||||
/* this comment should disappear */
|
|
||||||
PrefilledInt: 7, // This comment should be blown away.
|
|
||||||
/* As should
|
|
||||||
this one */
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
|
|
||||||
-- suggestedfix_fill_struct_partial_23_2 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
type StructPartialA struct {
|
|
||||||
PrefilledInt int
|
|
||||||
UnfilledInt int
|
|
||||||
StructPartialB
|
|
||||||
}
|
|
||||||
|
|
||||||
type StructPartialB struct {
|
|
||||||
PrefilledInt int
|
|
||||||
UnfilledInt int
|
|
||||||
}
|
|
||||||
|
|
||||||
func fill() {
|
|
||||||
a := StructPartialA{
|
|
||||||
PrefilledInt: 5,
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
b := StructPartialB{
|
|
||||||
PrefilledInt: 7,
|
|
||||||
UnfilledInt: 0,
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
type StructD struct {
|
|
||||||
ExportedIntField int
|
|
||||||
}
|
|
||||||
|
|
||||||
func spaces() {
|
|
||||||
d := StructD{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
-- suggestedfix_fill_struct_spaces_8_15 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
type StructD struct {
|
|
||||||
ExportedIntField int
|
|
||||||
}
|
|
||||||
|
|
||||||
func spaces() {
|
|
||||||
d := StructD{
|
|
||||||
ExportedIntField: 0,
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
type unsafeStruct struct {
|
|
||||||
x int
|
|
||||||
p unsafe.Pointer
|
|
||||||
}
|
|
||||||
|
|
||||||
func fill() {
|
|
||||||
_ := unsafeStruct{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
-- suggestedfix_fill_struct_unsafe_11_20 --
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
type unsafeStruct struct {
|
|
||||||
x int
|
|
||||||
p unsafe.Pointer
|
|
||||||
}
|
|
||||||
|
|
||||||
func fill() {
|
|
||||||
_ := unsafeStruct{
|
|
||||||
x: 0,
|
|
||||||
p: nil,
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
//go:build go1.18
|
|
||||||
// +build go1.18
|
|
||||||
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
type emptyStructWithTypeParams[A any] struct{}
|
|
||||||
|
|
||||||
var _ = emptyStructWithTypeParams[int]{} // no suggested fix
|
|
||||||
|
|
||||||
type basicStructWithTypeParams[T any] struct {
|
|
||||||
foo T
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = basicStructWithTypeParams[int]{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type twoArgStructWithTypeParams[F, B any] struct {
|
|
||||||
foo F
|
|
||||||
bar B
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = twoArgStructWithTypeParams[string, int]{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var _ = twoArgStructWithTypeParams[int, string]{
|
|
||||||
bar: "bar",
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type nestedStructWithTypeParams struct {
|
|
||||||
bar string
|
|
||||||
basic basicStructWithTypeParams[int]
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = nestedStructWithTypeParams{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
func _[T any]() {
|
|
||||||
type S struct{ t T }
|
|
||||||
_ = S{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
|
@ -1,206 +0,0 @@
|
||||||
-- suggestedfix_typeparams_14_40 --
|
|
||||||
//go:build go1.18
|
|
||||||
// +build go1.18
|
|
||||||
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
type emptyStructWithTypeParams[A any] struct{}
|
|
||||||
|
|
||||||
var _ = emptyStructWithTypeParams[int]{} // no suggested fix
|
|
||||||
|
|
||||||
type basicStructWithTypeParams[T any] struct {
|
|
||||||
foo T
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = basicStructWithTypeParams[int]{
|
|
||||||
foo: 0,
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type twoArgStructWithTypeParams[F, B any] struct {
|
|
||||||
foo F
|
|
||||||
bar B
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = twoArgStructWithTypeParams[string, int]{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var _ = twoArgStructWithTypeParams[int, string]{
|
|
||||||
bar: "bar",
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type nestedStructWithTypeParams struct {
|
|
||||||
bar string
|
|
||||||
basic basicStructWithTypeParams[int]
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = nestedStructWithTypeParams{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
func _[T any]() {
|
|
||||||
type S struct{ t T }
|
|
||||||
_ = S{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
|
|
||||||
-- suggestedfix_typeparams_21_49 --
|
|
||||||
//go:build go1.18
|
|
||||||
// +build go1.18
|
|
||||||
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
type emptyStructWithTypeParams[A any] struct{}
|
|
||||||
|
|
||||||
var _ = emptyStructWithTypeParams[int]{} // no suggested fix
|
|
||||||
|
|
||||||
type basicStructWithTypeParams[T any] struct {
|
|
||||||
foo T
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = basicStructWithTypeParams[int]{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type twoArgStructWithTypeParams[F, B any] struct {
|
|
||||||
foo F
|
|
||||||
bar B
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = twoArgStructWithTypeParams[string, int]{
|
|
||||||
foo: "",
|
|
||||||
bar: 0,
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var _ = twoArgStructWithTypeParams[int, string]{
|
|
||||||
bar: "bar",
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type nestedStructWithTypeParams struct {
|
|
||||||
bar string
|
|
||||||
basic basicStructWithTypeParams[int]
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = nestedStructWithTypeParams{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
func _[T any]() {
|
|
||||||
type S struct{ t T }
|
|
||||||
_ = S{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
|
|
||||||
-- suggestedfix_typeparams_25_1 --
|
|
||||||
//go:build go1.18
|
|
||||||
// +build go1.18
|
|
||||||
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
type emptyStructWithTypeParams[A any] struct{}
|
|
||||||
|
|
||||||
var _ = emptyStructWithTypeParams[int]{} // no suggested fix
|
|
||||||
|
|
||||||
type basicStructWithTypeParams[T any] struct {
|
|
||||||
foo T
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = basicStructWithTypeParams[int]{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type twoArgStructWithTypeParams[F, B any] struct {
|
|
||||||
foo F
|
|
||||||
bar B
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = twoArgStructWithTypeParams[string, int]{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var _ = twoArgStructWithTypeParams[int, string]{
|
|
||||||
foo: 0,
|
|
||||||
bar: "bar",
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type nestedStructWithTypeParams struct {
|
|
||||||
bar string
|
|
||||||
basic basicStructWithTypeParams[int]
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = nestedStructWithTypeParams{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
func _[T any]() {
|
|
||||||
type S struct{ t T }
|
|
||||||
_ = S{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
|
|
||||||
-- suggestedfix_typeparams_32_36 --
|
|
||||||
//go:build go1.18
|
|
||||||
// +build go1.18
|
|
||||||
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
type emptyStructWithTypeParams[A any] struct{}
|
|
||||||
|
|
||||||
var _ = emptyStructWithTypeParams[int]{} // no suggested fix
|
|
||||||
|
|
||||||
type basicStructWithTypeParams[T any] struct {
|
|
||||||
foo T
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = basicStructWithTypeParams[int]{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type twoArgStructWithTypeParams[F, B any] struct {
|
|
||||||
foo F
|
|
||||||
bar B
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = twoArgStructWithTypeParams[string, int]{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var _ = twoArgStructWithTypeParams[int, string]{
|
|
||||||
bar: "bar",
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type nestedStructWithTypeParams struct {
|
|
||||||
bar string
|
|
||||||
basic basicStructWithTypeParams[int]
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = nestedStructWithTypeParams{
|
|
||||||
bar: "",
|
|
||||||
basic: basicStructWithTypeParams{},
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
func _[T any]() {
|
|
||||||
type S struct{ t T }
|
|
||||||
_ = S{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
|
|
||||||
-- suggestedfix_typeparams_36_8 --
|
|
||||||
//go:build go1.18
|
|
||||||
// +build go1.18
|
|
||||||
|
|
||||||
package fillstruct
|
|
||||||
|
|
||||||
type emptyStructWithTypeParams[A any] struct{}
|
|
||||||
|
|
||||||
var _ = emptyStructWithTypeParams[int]{} // no suggested fix
|
|
||||||
|
|
||||||
type basicStructWithTypeParams[T any] struct {
|
|
||||||
foo T
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = basicStructWithTypeParams[int]{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type twoArgStructWithTypeParams[F, B any] struct {
|
|
||||||
foo F
|
|
||||||
bar B
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = twoArgStructWithTypeParams[string, int]{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
var _ = twoArgStructWithTypeParams[int, string]{
|
|
||||||
bar: "bar",
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
type nestedStructWithTypeParams struct {
|
|
||||||
bar string
|
|
||||||
basic basicStructWithTypeParams[int]
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ = nestedStructWithTypeParams{} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
|
|
||||||
func _[T any]() {
|
|
||||||
type S struct{ t T }
|
|
||||||
_ = S{
|
|
||||||
t: *new(T),
|
|
||||||
} //@suggestedfix("}", "refactor.rewrite", "Fill")
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
package suggestedfix
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log"
|
|
||||||
)
|
|
||||||
|
|
||||||
func goodbye() {
|
|
||||||
s := "hiiiiiii"
|
|
||||||
s = s //@suggestedfix("s = s", "quickfix", "")
|
|
||||||
log.Print(s)
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
-- suggestedfix_has_suggested_fix_9_2 --
|
|
||||||
package suggestedfix
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log"
|
|
||||||
)
|
|
||||||
|
|
||||||
func goodbye() {
|
|
||||||
s := "hiiiiiii"
|
|
||||||
//@suggestedfix("s = s", "quickfix", "")
|
|
||||||
log.Print(s)
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
-- summary --
|
-- summary --
|
||||||
CallHierarchyCount = 2
|
CallHierarchyCount = 2
|
||||||
SemanticTokenCount = 3
|
SemanticTokenCount = 3
|
||||||
SuggestedFixCount = 80
|
SuggestedFixCount = 45
|
||||||
MethodExtractionCount = 8
|
MethodExtractionCount = 8
|
||||||
InlayHintsCount = 5
|
InlayHintsCount = 5
|
||||||
RenamesCount = 45
|
RenamesCount = 45
|
||||||
|
|
|
@ -0,0 +1,630 @@
|
||||||
|
This test checks the behavior of the 'fill struct' code action.
|
||||||
|
|
||||||
|
-- flags --
|
||||||
|
-ignore_extra_diags
|
||||||
|
|
||||||
|
-- go.mod --
|
||||||
|
module golang.org/lsptests/fillstruct
|
||||||
|
|
||||||
|
go 1.18
|
||||||
|
|
||||||
|
-- data/data.go --
|
||||||
|
package data
|
||||||
|
|
||||||
|
type B struct {
|
||||||
|
ExportedInt int
|
||||||
|
unexportedInt int
|
||||||
|
}
|
||||||
|
|
||||||
|
-- a.go --
|
||||||
|
package fillstruct
|
||||||
|
|
||||||
|
import (
|
||||||
|
"golang.org/lsptests/fillstruct/data"
|
||||||
|
)
|
||||||
|
|
||||||
|
type basicStruct struct {
|
||||||
|
foo int
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = basicStruct{} //@codeactionedit("}", "refactor.rewrite", a1)
|
||||||
|
|
||||||
|
type twoArgStruct struct {
|
||||||
|
foo int
|
||||||
|
bar string
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = twoArgStruct{} //@codeactionedit("}", "refactor.rewrite", a2)
|
||||||
|
|
||||||
|
type nestedStruct struct {
|
||||||
|
bar string
|
||||||
|
basic basicStruct
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = nestedStruct{} //@codeactionedit("}", "refactor.rewrite", a3)
|
||||||
|
|
||||||
|
var _ = data.B{} //@codeactionedit("}", "refactor.rewrite", a4)
|
||||||
|
-- @a1/a.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -11 +11,3 @@
|
||||||
|
-var _ = basicStruct{} //@codeactionedit("}", "refactor.rewrite", a1)
|
||||||
|
+var _ = basicStruct{
|
||||||
|
+ foo: 0,
|
||||||
|
+} //@codeactionedit("}", "refactor.rewrite", a1)
|
||||||
|
-- @a2/a.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -18 +18,4 @@
|
||||||
|
-var _ = twoArgStruct{} //@codeactionedit("}", "refactor.rewrite", a2)
|
||||||
|
+var _ = twoArgStruct{
|
||||||
|
+ foo: 0,
|
||||||
|
+ bar: "",
|
||||||
|
+} //@codeactionedit("}", "refactor.rewrite", a2)
|
||||||
|
-- @a3/a.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -25 +25,4 @@
|
||||||
|
-var _ = nestedStruct{} //@codeactionedit("}", "refactor.rewrite", a3)
|
||||||
|
+var _ = nestedStruct{
|
||||||
|
+ bar: "",
|
||||||
|
+ basic: basicStruct{},
|
||||||
|
+} //@codeactionedit("}", "refactor.rewrite", a3)
|
||||||
|
-- @a4/a.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -27 +27,3 @@
|
||||||
|
-var _ = data.B{} //@codeactionedit("}", "refactor.rewrite", a4)
|
||||||
|
+var _ = data.B{
|
||||||
|
+ ExportedInt: 0,
|
||||||
|
+} //@codeactionedit("}", "refactor.rewrite", a4)
|
||||||
|
-- a2.go --
|
||||||
|
package fillstruct
|
||||||
|
|
||||||
|
type typedStruct struct {
|
||||||
|
m map[string]int
|
||||||
|
s []int
|
||||||
|
c chan int
|
||||||
|
c1 <-chan int
|
||||||
|
a [2]string
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = typedStruct{} //@codeactionedit("}", "refactor.rewrite", a21)
|
||||||
|
|
||||||
|
type funStruct struct {
|
||||||
|
fn func(i int) int
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = funStruct{} //@codeactionedit("}", "refactor.rewrite", a22)
|
||||||
|
|
||||||
|
type funStructCompex struct {
|
||||||
|
fn func(i int, s string) (string, int)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = funStructCompex{} //@codeactionedit("}", "refactor.rewrite", a23)
|
||||||
|
|
||||||
|
type funStructEmpty struct {
|
||||||
|
fn func()
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = funStructEmpty{} //@codeactionedit("}", "refactor.rewrite", a24)
|
||||||
|
|
||||||
|
-- @a21/a2.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -11 +11,7 @@
|
||||||
|
-var _ = typedStruct{} //@codeactionedit("}", "refactor.rewrite", a21)
|
||||||
|
+var _ = typedStruct{
|
||||||
|
+ m: map[string]int{},
|
||||||
|
+ s: []int{},
|
||||||
|
+ c: make(chan int),
|
||||||
|
+ c1: make(<-chan int),
|
||||||
|
+ a: [2]string{},
|
||||||
|
+} //@codeactionedit("}", "refactor.rewrite", a21)
|
||||||
|
-- @a22/a2.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -17 +17,4 @@
|
||||||
|
-var _ = funStruct{} //@codeactionedit("}", "refactor.rewrite", a22)
|
||||||
|
+var _ = funStruct{
|
||||||
|
+ fn: func(i int) int {
|
||||||
|
+ },
|
||||||
|
+} //@codeactionedit("}", "refactor.rewrite", a22)
|
||||||
|
-- @a23/a2.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -23 +23,4 @@
|
||||||
|
-var _ = funStructCompex{} //@codeactionedit("}", "refactor.rewrite", a23)
|
||||||
|
+var _ = funStructCompex{
|
||||||
|
+ fn: func(i int, s string) (string, int) {
|
||||||
|
+ },
|
||||||
|
+} //@codeactionedit("}", "refactor.rewrite", a23)
|
||||||
|
-- @a24/a2.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -29 +29,4 @@
|
||||||
|
-var _ = funStructEmpty{} //@codeactionedit("}", "refactor.rewrite", a24)
|
||||||
|
+var _ = funStructEmpty{
|
||||||
|
+ fn: func() {
|
||||||
|
+ },
|
||||||
|
+} //@codeactionedit("}", "refactor.rewrite", a24)
|
||||||
|
-- a3.go --
|
||||||
|
package fillstruct
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go/ast"
|
||||||
|
"go/token"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Foo struct {
|
||||||
|
A int
|
||||||
|
}
|
||||||
|
|
||||||
|
type Bar struct {
|
||||||
|
X *Foo
|
||||||
|
Y *Foo
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = Bar{} //@codeactionedit("}", "refactor.rewrite", a31)
|
||||||
|
|
||||||
|
type importedStruct struct {
|
||||||
|
m map[*ast.CompositeLit]ast.Field
|
||||||
|
s []ast.BadExpr
|
||||||
|
a [3]token.Token
|
||||||
|
c chan ast.EmptyStmt
|
||||||
|
fn func(ast_decl ast.DeclStmt) ast.Ellipsis
|
||||||
|
st ast.CompositeLit
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = importedStruct{} //@codeactionedit("}", "refactor.rewrite", a32)
|
||||||
|
|
||||||
|
type pointerBuiltinStruct struct {
|
||||||
|
b *bool
|
||||||
|
s *string
|
||||||
|
i *int
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = pointerBuiltinStruct{} //@codeactionedit("}", "refactor.rewrite", a33)
|
||||||
|
|
||||||
|
var _ = []ast.BasicLit{
|
||||||
|
{}, //@codeactionedit("}", "refactor.rewrite", a34)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = []ast.BasicLit{{}} //@codeactionedit("}", "refactor.rewrite", a35)
|
||||||
|
-- @a31/a3.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -17 +17,4 @@
|
||||||
|
-var _ = Bar{} //@codeactionedit("}", "refactor.rewrite", a31)
|
||||||
|
+var _ = Bar{
|
||||||
|
+ X: &Foo{},
|
||||||
|
+ Y: &Foo{},
|
||||||
|
+} //@codeactionedit("}", "refactor.rewrite", a31)
|
||||||
|
-- @a32/a3.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -28 +28,9 @@
|
||||||
|
-var _ = importedStruct{} //@codeactionedit("}", "refactor.rewrite", a32)
|
||||||
|
+var _ = importedStruct{
|
||||||
|
+ m: map[*ast.CompositeLit]ast.Field{},
|
||||||
|
+ s: []ast.BadExpr{},
|
||||||
|
+ a: [3]token.Token{},
|
||||||
|
+ c: make(chan ast.EmptyStmt),
|
||||||
|
+ fn: func(ast_decl ast.DeclStmt) ast.Ellipsis {
|
||||||
|
+ },
|
||||||
|
+ st: ast.CompositeLit{},
|
||||||
|
+} //@codeactionedit("}", "refactor.rewrite", a32)
|
||||||
|
-- @a33/a3.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -36 +36,5 @@
|
||||||
|
-var _ = pointerBuiltinStruct{} //@codeactionedit("}", "refactor.rewrite", a33)
|
||||||
|
+var _ = pointerBuiltinStruct{
|
||||||
|
+ b: new(bool),
|
||||||
|
+ s: new(string),
|
||||||
|
+ i: new(int),
|
||||||
|
+} //@codeactionedit("}", "refactor.rewrite", a33)
|
||||||
|
-- @a34/a3.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -39 +39,5 @@
|
||||||
|
- {}, //@codeactionedit("}", "refactor.rewrite", a34)
|
||||||
|
+ {
|
||||||
|
+ ValuePos: 0,
|
||||||
|
+ Kind: 0,
|
||||||
|
+ Value: "",
|
||||||
|
+ }, //@codeactionedit("}", "refactor.rewrite", a34)
|
||||||
|
-- @a35/a3.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -42 +42,5 @@
|
||||||
|
-var _ = []ast.BasicLit{{}} //@codeactionedit("}", "refactor.rewrite", a35)
|
||||||
|
+var _ = []ast.BasicLit{{
|
||||||
|
+ ValuePos: 0,
|
||||||
|
+ Kind: 0,
|
||||||
|
+ Value: "",
|
||||||
|
+}} //@codeactionedit("}", "refactor.rewrite", a35)
|
||||||
|
-- a4.go --
|
||||||
|
package fillstruct
|
||||||
|
|
||||||
|
import "go/ast"
|
||||||
|
|
||||||
|
type iStruct struct {
|
||||||
|
X int
|
||||||
|
}
|
||||||
|
|
||||||
|
type sStruct struct {
|
||||||
|
str string
|
||||||
|
}
|
||||||
|
|
||||||
|
type multiFill struct {
|
||||||
|
num int
|
||||||
|
strin string
|
||||||
|
arr []int
|
||||||
|
}
|
||||||
|
|
||||||
|
type assignStruct struct {
|
||||||
|
n ast.Node
|
||||||
|
}
|
||||||
|
|
||||||
|
func fill() {
|
||||||
|
var x int
|
||||||
|
var _ = iStruct{} //@codeactionedit("}", "refactor.rewrite", a41)
|
||||||
|
|
||||||
|
var s string
|
||||||
|
var _ = sStruct{} //@codeactionedit("}", "refactor.rewrite", a42)
|
||||||
|
|
||||||
|
var n int
|
||||||
|
_ = []int{}
|
||||||
|
if true {
|
||||||
|
arr := []int{1, 2}
|
||||||
|
}
|
||||||
|
var _ = multiFill{} //@codeactionedit("}", "refactor.rewrite", a43)
|
||||||
|
|
||||||
|
var node *ast.CompositeLit
|
||||||
|
var _ = assignStruct{} //@codeactionedit("}", "refactor.rewrite", a45)
|
||||||
|
}
|
||||||
|
|
||||||
|
-- @a41/a4.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -25 +25,3 @@
|
||||||
|
- var _ = iStruct{} //@codeactionedit("}", "refactor.rewrite", a41)
|
||||||
|
+ var _ = iStruct{
|
||||||
|
+ X: x,
|
||||||
|
+ } //@codeactionedit("}", "refactor.rewrite", a41)
|
||||||
|
-- @a42/a4.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -28 +28,3 @@
|
||||||
|
- var _ = sStruct{} //@codeactionedit("}", "refactor.rewrite", a42)
|
||||||
|
+ var _ = sStruct{
|
||||||
|
+ str: s,
|
||||||
|
+ } //@codeactionedit("}", "refactor.rewrite", a42)
|
||||||
|
-- @a43/a4.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -35 +35,5 @@
|
||||||
|
- var _ = multiFill{} //@codeactionedit("}", "refactor.rewrite", a43)
|
||||||
|
+ var _ = multiFill{
|
||||||
|
+ num: n,
|
||||||
|
+ strin: s,
|
||||||
|
+ arr: []int{},
|
||||||
|
+ } //@codeactionedit("}", "refactor.rewrite", a43)
|
||||||
|
-- @a45/a4.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -38 +38,3 @@
|
||||||
|
- var _ = assignStruct{} //@codeactionedit("}", "refactor.rewrite", a45)
|
||||||
|
+ var _ = assignStruct{
|
||||||
|
+ n: node,
|
||||||
|
+ } //@codeactionedit("}", "refactor.rewrite", a45)
|
||||||
|
-- fill_struct.go --
|
||||||
|
package fillstruct
|
||||||
|
|
||||||
|
type StructA struct {
|
||||||
|
unexportedIntField int
|
||||||
|
ExportedIntField int
|
||||||
|
MapA map[int]string
|
||||||
|
Array []int
|
||||||
|
StructB
|
||||||
|
}
|
||||||
|
|
||||||
|
type StructA2 struct {
|
||||||
|
B *StructB
|
||||||
|
}
|
||||||
|
|
||||||
|
type StructA3 struct {
|
||||||
|
B StructB
|
||||||
|
}
|
||||||
|
|
||||||
|
func fill() {
|
||||||
|
a := StructA{} //@codeactionedit("}", "refactor.rewrite", fill_struct1)
|
||||||
|
b := StructA2{} //@codeactionedit("}", "refactor.rewrite", fill_struct2)
|
||||||
|
c := StructA3{} //@codeactionedit("}", "refactor.rewrite", fill_struct3)
|
||||||
|
if true {
|
||||||
|
_ = StructA3{} //@codeactionedit("}", "refactor.rewrite", fill_struct4)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-- @fill_struct1/fill_struct.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -20 +20,7 @@
|
||||||
|
- a := StructA{} //@codeactionedit("}", "refactor.rewrite", fill_struct1)
|
||||||
|
+ a := StructA{
|
||||||
|
+ unexportedIntField: 0,
|
||||||
|
+ ExportedIntField: 0,
|
||||||
|
+ MapA: map[int]string{},
|
||||||
|
+ Array: []int{},
|
||||||
|
+ StructB: StructB{},
|
||||||
|
+ } //@codeactionedit("}", "refactor.rewrite", fill_struct1)
|
||||||
|
-- @fill_struct2/fill_struct.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -21 +21,3 @@
|
||||||
|
- b := StructA2{} //@codeactionedit("}", "refactor.rewrite", fill_struct2)
|
||||||
|
+ b := StructA2{
|
||||||
|
+ B: &StructB{},
|
||||||
|
+ } //@codeactionedit("}", "refactor.rewrite", fill_struct2)
|
||||||
|
-- @fill_struct3/fill_struct.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -22 +22,3 @@
|
||||||
|
- c := StructA3{} //@codeactionedit("}", "refactor.rewrite", fill_struct3)
|
||||||
|
+ c := StructA3{
|
||||||
|
+ B: StructB{},
|
||||||
|
+ } //@codeactionedit("}", "refactor.rewrite", fill_struct3)
|
||||||
|
-- @fill_struct4/fill_struct.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -24 +24,3 @@
|
||||||
|
- _ = StructA3{} //@codeactionedit("}", "refactor.rewrite", fill_struct4)
|
||||||
|
+ _ = StructA3{
|
||||||
|
+ B: StructB{},
|
||||||
|
+ } //@codeactionedit("}", "refactor.rewrite", fill_struct4)
|
||||||
|
-- fill_struct_anon.go --
|
||||||
|
package fillstruct
|
||||||
|
|
||||||
|
type StructAnon struct {
|
||||||
|
a struct{}
|
||||||
|
b map[string]interface{}
|
||||||
|
c map[string]struct {
|
||||||
|
d int
|
||||||
|
e bool
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func fill() {
|
||||||
|
_ := StructAnon{} //@codeactionedit("}", "refactor.rewrite", fill_struct_anon)
|
||||||
|
}
|
||||||
|
-- @fill_struct_anon/fill_struct_anon.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -13 +13,5 @@
|
||||||
|
- _ := StructAnon{} //@codeactionedit("}", "refactor.rewrite", fill_struct_anon)
|
||||||
|
+ _ := StructAnon{
|
||||||
|
+ a: struct{}{},
|
||||||
|
+ b: map[string]interface{}{},
|
||||||
|
+ c: map[string]struct{d int; e bool}{},
|
||||||
|
+ } //@codeactionedit("}", "refactor.rewrite", fill_struct_anon)
|
||||||
|
-- fill_struct_nested.go --
|
||||||
|
package fillstruct
|
||||||
|
|
||||||
|
type StructB struct {
|
||||||
|
StructC
|
||||||
|
}
|
||||||
|
|
||||||
|
type StructC struct {
|
||||||
|
unexportedInt int
|
||||||
|
}
|
||||||
|
|
||||||
|
func nested() {
|
||||||
|
c := StructB{
|
||||||
|
StructC: StructC{}, //@codeactionedit("}", "refactor.rewrite", fill_nested)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-- @fill_nested/fill_struct_nested.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -13 +13,3 @@
|
||||||
|
- StructC: StructC{}, //@codeactionedit("}", "refactor.rewrite", fill_nested)
|
||||||
|
+ StructC: StructC{
|
||||||
|
+ unexportedInt: 0,
|
||||||
|
+ }, //@codeactionedit("}", "refactor.rewrite", fill_nested)
|
||||||
|
-- fill_struct_package.go --
|
||||||
|
package fillstruct
|
||||||
|
|
||||||
|
import (
|
||||||
|
h2 "net/http"
|
||||||
|
|
||||||
|
"golang.org/lsptests/fillstruct/data"
|
||||||
|
)
|
||||||
|
|
||||||
|
func unexported() {
|
||||||
|
a := data.B{} //@codeactionedit("}", "refactor.rewrite", fill_struct_package1)
|
||||||
|
_ = h2.Client{} //@codeactionedit("}", "refactor.rewrite", fill_struct_package2)
|
||||||
|
}
|
||||||
|
-- @fill_struct_package1/fill_struct_package.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -10 +10,3 @@
|
||||||
|
- a := data.B{} //@codeactionedit("}", "refactor.rewrite", fill_struct_package1)
|
||||||
|
+ a := data.B{
|
||||||
|
+ ExportedInt: 0,
|
||||||
|
+ } //@codeactionedit("}", "refactor.rewrite", fill_struct_package1)
|
||||||
|
-- @fill_struct_package2/fill_struct_package.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -11 +11,7 @@
|
||||||
|
- _ = h2.Client{} //@codeactionedit("}", "refactor.rewrite", fill_struct_package2)
|
||||||
|
+ _ = h2.Client{
|
||||||
|
+ Transport: nil,
|
||||||
|
+ CheckRedirect: func(req *h2.Request, via []*h2.Request) error {
|
||||||
|
+ },
|
||||||
|
+ Jar: nil,
|
||||||
|
+ Timeout: 0,
|
||||||
|
+ } //@codeactionedit("}", "refactor.rewrite", fill_struct_package2)
|
||||||
|
-- fill_struct_partial.go --
|
||||||
|
package fillstruct
|
||||||
|
|
||||||
|
type StructPartialA struct {
|
||||||
|
PrefilledInt int
|
||||||
|
UnfilledInt int
|
||||||
|
StructPartialB
|
||||||
|
}
|
||||||
|
|
||||||
|
type StructPartialB struct {
|
||||||
|
PrefilledInt int
|
||||||
|
UnfilledInt int
|
||||||
|
}
|
||||||
|
|
||||||
|
func fill() {
|
||||||
|
a := StructPartialA{
|
||||||
|
PrefilledInt: 5,
|
||||||
|
} //@codeactionedit("}", "refactor.rewrite", fill_struct_partial1)
|
||||||
|
b := StructPartialB{
|
||||||
|
/* this comment should disappear */
|
||||||
|
PrefilledInt: 7, // This comment should be blown away.
|
||||||
|
/* As should
|
||||||
|
this one */
|
||||||
|
} //@codeactionedit("}", "refactor.rewrite", fill_struct_partial2)
|
||||||
|
}
|
||||||
|
|
||||||
|
-- @fill_struct_partial1/fill_struct_partial.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -16 +16,3 @@
|
||||||
|
- PrefilledInt: 5,
|
||||||
|
+ PrefilledInt: 5,
|
||||||
|
+ UnfilledInt: 0,
|
||||||
|
+ StructPartialB: StructPartialB{},
|
||||||
|
-- @fill_struct_partial2/fill_struct_partial.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -19,4 +19,2 @@
|
||||||
|
- /* this comment should disappear */
|
||||||
|
+ PrefilledInt: 7,
|
||||||
|
- PrefilledInt: 7, // This comment should be blown away.
|
||||||
|
- /* As should
|
||||||
|
- this one */
|
||||||
|
+ UnfilledInt: 0,
|
||||||
|
-- fill_struct_spaces.go --
|
||||||
|
package fillstruct
|
||||||
|
|
||||||
|
type StructD struct {
|
||||||
|
ExportedIntField int
|
||||||
|
}
|
||||||
|
|
||||||
|
func spaces() {
|
||||||
|
d := StructD{} //@codeactionedit("}", "refactor.rewrite", fill_struct_spaces)
|
||||||
|
}
|
||||||
|
|
||||||
|
-- @fill_struct_spaces/fill_struct_spaces.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -8 +8,3 @@
|
||||||
|
- d := StructD{} //@codeactionedit("}", "refactor.rewrite", fill_struct_spaces)
|
||||||
|
+ d := StructD{
|
||||||
|
+ ExportedIntField: 0,
|
||||||
|
+ } //@codeactionedit("}", "refactor.rewrite", fill_struct_spaces)
|
||||||
|
-- fill_struct_unsafe.go --
|
||||||
|
package fillstruct
|
||||||
|
|
||||||
|
import "unsafe"
|
||||||
|
|
||||||
|
type unsafeStruct struct {
|
||||||
|
x int
|
||||||
|
p unsafe.Pointer
|
||||||
|
}
|
||||||
|
|
||||||
|
func fill() {
|
||||||
|
_ := unsafeStruct{} //@codeactionedit("}", "refactor.rewrite", fill_struct_unsafe)
|
||||||
|
}
|
||||||
|
|
||||||
|
-- @fill_struct_unsafe/fill_struct_unsafe.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -11 +11,4 @@
|
||||||
|
- _ := unsafeStruct{} //@codeactionedit("}", "refactor.rewrite", fill_struct_unsafe)
|
||||||
|
+ _ := unsafeStruct{
|
||||||
|
+ x: 0,
|
||||||
|
+ p: nil,
|
||||||
|
+ } //@codeactionedit("}", "refactor.rewrite", fill_struct_unsafe)
|
||||||
|
-- typeparams.go --
|
||||||
|
package fillstruct
|
||||||
|
|
||||||
|
type emptyStructWithTypeParams[A any] struct{}
|
||||||
|
|
||||||
|
var _ = emptyStructWithTypeParams[int]{} // no suggested fix
|
||||||
|
|
||||||
|
type basicStructWithTypeParams[T any] struct {
|
||||||
|
foo T
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = basicStructWithTypeParams[int]{} //@codeactionedit("}", "refactor.rewrite", typeparams1)
|
||||||
|
|
||||||
|
type twoArgStructWithTypeParams[F, B any] struct {
|
||||||
|
foo F
|
||||||
|
bar B
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = twoArgStructWithTypeParams[string, int]{} //@codeactionedit("}", "refactor.rewrite", typeparams2)
|
||||||
|
|
||||||
|
var _ = twoArgStructWithTypeParams[int, string]{
|
||||||
|
bar: "bar",
|
||||||
|
} //@codeactionedit("}", "refactor.rewrite", typeparams3)
|
||||||
|
|
||||||
|
type nestedStructWithTypeParams struct {
|
||||||
|
bar string
|
||||||
|
basic basicStructWithTypeParams[int]
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = nestedStructWithTypeParams{} //@codeactionedit("}", "refactor.rewrite", typeparams4)
|
||||||
|
|
||||||
|
func _[T any]() {
|
||||||
|
type S struct{ t T }
|
||||||
|
_ = S{} //@codeactionedit("}", "refactor.rewrite", typeparams5)
|
||||||
|
}
|
||||||
|
-- @typeparams1/typeparams.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -11 +11,3 @@
|
||||||
|
-var _ = basicStructWithTypeParams[int]{} //@codeactionedit("}", "refactor.rewrite", typeparams1)
|
||||||
|
+var _ = basicStructWithTypeParams[int]{
|
||||||
|
+ foo: 0,
|
||||||
|
+} //@codeactionedit("}", "refactor.rewrite", typeparams1)
|
||||||
|
-- @typeparams2/typeparams.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -18 +18,4 @@
|
||||||
|
-var _ = twoArgStructWithTypeParams[string, int]{} //@codeactionedit("}", "refactor.rewrite", typeparams2)
|
||||||
|
+var _ = twoArgStructWithTypeParams[string, int]{
|
||||||
|
+ foo: "",
|
||||||
|
+ bar: 0,
|
||||||
|
+} //@codeactionedit("}", "refactor.rewrite", typeparams2)
|
||||||
|
-- @typeparams3/typeparams.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -20 +20,2 @@
|
||||||
|
-var _ = twoArgStructWithTypeParams[int, string]{
|
||||||
|
+var _ = twoArgStructWithTypeParams[int, string]{
|
||||||
|
+ foo: 0,
|
||||||
|
-- @typeparams4/typeparams.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -29 +29,4 @@
|
||||||
|
-var _ = nestedStructWithTypeParams{} //@codeactionedit("}", "refactor.rewrite", typeparams4)
|
||||||
|
+var _ = nestedStructWithTypeParams{
|
||||||
|
+ bar: "",
|
||||||
|
+ basic: basicStructWithTypeParams{},
|
||||||
|
+} //@codeactionedit("}", "refactor.rewrite", typeparams4)
|
||||||
|
-- @typeparams5/typeparams.go --
|
||||||
|
--- before
|
||||||
|
+++ after
|
||||||
|
@@ -33 +33,3 @@
|
||||||
|
- _ = S{} //@codeactionedit("}", "refactor.rewrite", typeparams5)
|
||||||
|
+ _ = S{
|
||||||
|
+ t: *new(T),
|
||||||
|
+ } //@codeactionedit("}", "refactor.rewrite", typeparams5)
|
|
@ -8,16 +8,16 @@ go 1.18
|
||||||
-- basic.go --
|
-- basic.go --
|
||||||
package extract
|
package extract
|
||||||
|
|
||||||
func _() { //@codeaction("refactor.extract", "{", closeBracket, outer)
|
func _() { //@codeaction("{", closeBracket, "refactor.extract", outer)
|
||||||
a := 1 //@codeaction("refactor.extract", "a", end, inner)
|
a := 1 //@codeaction("a", end, "refactor.extract", inner)
|
||||||
_ = a + 4 //@loc(end, "4")
|
_ = a + 4 //@loc(end, "4")
|
||||||
} //@loc(closeBracket, "}")
|
} //@loc(closeBracket, "}")
|
||||||
|
|
||||||
-- @inner/basic.go --
|
-- @inner/basic.go --
|
||||||
package extract
|
package extract
|
||||||
|
|
||||||
func _() { //@codeaction("refactor.extract", "{", closeBracket, outer)
|
func _() { //@codeaction("{", closeBracket, "refactor.extract", outer)
|
||||||
//@codeaction("refactor.extract", "a", end, inner)
|
//@codeaction("a", end, "refactor.extract", inner)
|
||||||
newFunction() //@loc(end, "4")
|
newFunction() //@loc(end, "4")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@ func newFunction() {
|
||||||
-- @outer/basic.go --
|
-- @outer/basic.go --
|
||||||
package extract
|
package extract
|
||||||
|
|
||||||
func _() { //@codeaction("refactor.extract", "{", closeBracket, outer)
|
func _() { //@codeaction("{", closeBracket, "refactor.extract", outer)
|
||||||
//@codeaction("refactor.extract", "a", end, inner)
|
//@codeaction("a", end, "refactor.extract", inner)
|
||||||
newFunction() //@loc(end, "4")
|
newFunction() //@loc(end, "4")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ package extract
|
||||||
|
|
||||||
func _() bool {
|
func _() bool {
|
||||||
x := 1
|
x := 1
|
||||||
if x == 0 { //@codeaction("refactor.extract", "if", ifend, return)
|
if x == 0 { //@codeaction("if", ifend, "refactor.extract", return)
|
||||||
return true
|
return true
|
||||||
} //@loc(ifend, "}")
|
} //@loc(ifend, "}")
|
||||||
return false
|
return false
|
||||||
|
@ -55,7 +55,7 @@ package extract
|
||||||
|
|
||||||
func _() bool {
|
func _() bool {
|
||||||
x := 1
|
x := 1
|
||||||
//@codeaction("refactor.extract", "if", ifend, return)
|
//@codeaction("if", ifend, "refactor.extract", return)
|
||||||
shouldReturn, returnValue := newFunction(x)
|
shouldReturn, returnValue := newFunction(x)
|
||||||
if shouldReturn {
|
if shouldReturn {
|
||||||
return returnValue
|
return returnValue
|
||||||
|
@ -74,7 +74,7 @@ func newFunction(x int) (bool, bool) {
|
||||||
package extract
|
package extract
|
||||||
|
|
||||||
func _() bool {
|
func _() bool {
|
||||||
x := 1 //@codeaction("refactor.extract", "x", rnnEnd, rnn)
|
x := 1 //@codeaction("x", rnnEnd, "refactor.extract", rnn)
|
||||||
if x == 0 {
|
if x == 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ func _() bool {
|
||||||
package extract
|
package extract
|
||||||
|
|
||||||
func _() bool {
|
func _() bool {
|
||||||
//@codeaction("refactor.extract", "x", rnnEnd, rnn)
|
//@codeaction("x", rnnEnd, "refactor.extract", rnn)
|
||||||
return newFunction() //@loc(rnnEnd, "false")
|
return newFunction() //@loc(rnnEnd, "false")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ import "fmt"
|
||||||
func _() (int, string, error) {
|
func _() (int, string, error) {
|
||||||
x := 1
|
x := 1
|
||||||
y := "hello"
|
y := "hello"
|
||||||
z := "bye" //@codeaction("refactor.extract", "z", rcEnd, rc)
|
z := "bye" //@codeaction("z", rcEnd, "refactor.extract", rc)
|
||||||
if y == z {
|
if y == z {
|
||||||
return x, y, fmt.Errorf("same")
|
return x, y, fmt.Errorf("same")
|
||||||
} else if false {
|
} else if false {
|
||||||
|
@ -123,7 +123,7 @@ import "fmt"
|
||||||
func _() (int, string, error) {
|
func _() (int, string, error) {
|
||||||
x := 1
|
x := 1
|
||||||
y := "hello"
|
y := "hello"
|
||||||
//@codeaction("refactor.extract", "z", rcEnd, rc)
|
//@codeaction("z", rcEnd, "refactor.extract", rc)
|
||||||
z, shouldReturn, returnValue, returnValue1, returnValue2 := newFunction(y, x)
|
z, shouldReturn, returnValue, returnValue1, returnValue2 := newFunction(y, x)
|
||||||
if shouldReturn {
|
if shouldReturn {
|
||||||
return returnValue, returnValue1, returnValue2
|
return returnValue, returnValue1, returnValue2
|
||||||
|
@ -150,7 +150,7 @@ import "fmt"
|
||||||
func _() (int, string, error) {
|
func _() (int, string, error) {
|
||||||
x := 1
|
x := 1
|
||||||
y := "hello"
|
y := "hello"
|
||||||
z := "bye" //@codeaction("refactor.extract", "z", rcnnEnd, rcnn)
|
z := "bye" //@codeaction("z", rcnnEnd, "refactor.extract", rcnn)
|
||||||
if y == z {
|
if y == z {
|
||||||
return x, y, fmt.Errorf("same")
|
return x, y, fmt.Errorf("same")
|
||||||
} else if false {
|
} else if false {
|
||||||
|
@ -168,7 +168,7 @@ import "fmt"
|
||||||
func _() (int, string, error) {
|
func _() (int, string, error) {
|
||||||
x := 1
|
x := 1
|
||||||
y := "hello"
|
y := "hello"
|
||||||
//@codeaction("refactor.extract", "z", rcnnEnd, rcnn)
|
//@codeaction("z", rcnnEnd, "refactor.extract", rcnn)
|
||||||
return newFunction(y, x) //@loc(rcnnEnd, "nil")
|
return newFunction(y, x) //@loc(rcnnEnd, "nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ import "go/ast"
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
ast.Inspect(ast.NewIdent("a"), func(n ast.Node) bool {
|
ast.Inspect(ast.NewIdent("a"), func(n ast.Node) bool {
|
||||||
if n == nil { //@codeaction("refactor.extract", "if", rflEnd, rfl)
|
if n == nil { //@codeaction("if", rflEnd, "refactor.extract", rfl)
|
||||||
return true
|
return true
|
||||||
} //@loc(rflEnd, "}")
|
} //@loc(rflEnd, "}")
|
||||||
return false
|
return false
|
||||||
|
@ -204,7 +204,7 @@ import "go/ast"
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
ast.Inspect(ast.NewIdent("a"), func(n ast.Node) bool {
|
ast.Inspect(ast.NewIdent("a"), func(n ast.Node) bool {
|
||||||
//@codeaction("refactor.extract", "if", rflEnd, rfl)
|
//@codeaction("if", rflEnd, "refactor.extract", rfl)
|
||||||
shouldReturn, returnValue := newFunction(n)
|
shouldReturn, returnValue := newFunction(n)
|
||||||
if shouldReturn {
|
if shouldReturn {
|
||||||
return returnValue
|
return returnValue
|
||||||
|
@ -227,7 +227,7 @@ import "go/ast"
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
ast.Inspect(ast.NewIdent("a"), func(n ast.Node) bool {
|
ast.Inspect(ast.NewIdent("a"), func(n ast.Node) bool {
|
||||||
if n == nil { //@codeaction("refactor.extract", "if", rflnnEnd, rflnn)
|
if n == nil { //@codeaction("if", rflnnEnd, "refactor.extract", rflnn)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false //@loc(rflnnEnd, "false")
|
return false //@loc(rflnnEnd, "false")
|
||||||
|
@ -241,7 +241,7 @@ import "go/ast"
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
ast.Inspect(ast.NewIdent("a"), func(n ast.Node) bool {
|
ast.Inspect(ast.NewIdent("a"), func(n ast.Node) bool {
|
||||||
//@codeaction("refactor.extract", "if", rflnnEnd, rflnn)
|
//@codeaction("if", rflnnEnd, "refactor.extract", rflnn)
|
||||||
return newFunction(n) //@loc(rflnnEnd, "false")
|
return newFunction(n) //@loc(rflnnEnd, "false")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -258,7 +258,7 @@ package extract
|
||||||
|
|
||||||
func _() string {
|
func _() string {
|
||||||
x := 1
|
x := 1
|
||||||
if x == 0 { //@codeaction("refactor.extract", "if", riEnd, ri)
|
if x == 0 { //@codeaction("if", riEnd, "refactor.extract", ri)
|
||||||
x = 3
|
x = 3
|
||||||
return "a"
|
return "a"
|
||||||
} //@loc(riEnd, "}")
|
} //@loc(riEnd, "}")
|
||||||
|
@ -271,7 +271,7 @@ package extract
|
||||||
|
|
||||||
func _() string {
|
func _() string {
|
||||||
x := 1
|
x := 1
|
||||||
//@codeaction("refactor.extract", "if", riEnd, ri)
|
//@codeaction("if", riEnd, "refactor.extract", ri)
|
||||||
shouldReturn, returnValue := newFunction(x)
|
shouldReturn, returnValue := newFunction(x)
|
||||||
if shouldReturn {
|
if shouldReturn {
|
||||||
return returnValue
|
return returnValue
|
||||||
|
@ -293,7 +293,7 @@ package extract
|
||||||
|
|
||||||
func _() string {
|
func _() string {
|
||||||
x := 1
|
x := 1
|
||||||
if x == 0 { //@codeaction("refactor.extract", "if", rinnEnd, rinn)
|
if x == 0 { //@codeaction("if", rinnEnd, "refactor.extract", rinn)
|
||||||
x = 3
|
x = 3
|
||||||
return "a"
|
return "a"
|
||||||
}
|
}
|
||||||
|
@ -306,7 +306,7 @@ package extract
|
||||||
|
|
||||||
func _() string {
|
func _() string {
|
||||||
x := 1
|
x := 1
|
||||||
//@codeaction("refactor.extract", "if", rinnEnd, rinn)
|
//@codeaction("if", rinnEnd, "refactor.extract", rinn)
|
||||||
return newFunction(x) //@loc(rinnEnd, "\"b\"")
|
return newFunction(x) //@loc(rinnEnd, "\"b\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,10 +324,10 @@ package extract
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
a := 1
|
a := 1
|
||||||
a = 5 //@codeaction("refactor.extract", "a", araend, ara)
|
a = 5 //@codeaction("a", araend, "refactor.extract", ara)
|
||||||
a = a + 2 //@loc(araend, "2")
|
a = a + 2 //@loc(araend, "2")
|
||||||
|
|
||||||
b := a * 2 //@codeaction("refactor.extract", "b", arbend, arb)
|
b := a * 2 //@codeaction("b", arbend, "refactor.extract", arb)
|
||||||
_ = b + 4 //@loc(arbend, "4")
|
_ = b + 4 //@loc(arbend, "4")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,10 +336,10 @@ package extract
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
a := 1
|
a := 1
|
||||||
//@codeaction("refactor.extract", "a", araend, ara)
|
//@codeaction("a", araend, "refactor.extract", ara)
|
||||||
a = newFunction(a) //@loc(araend, "2")
|
a = newFunction(a) //@loc(araend, "2")
|
||||||
|
|
||||||
b := a * 2 //@codeaction("refactor.extract", "b", arbend, arb)
|
b := a * 2 //@codeaction("b", arbend, "refactor.extract", arb)
|
||||||
_ = b + 4 //@loc(arbend, "4")
|
_ = b + 4 //@loc(arbend, "4")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,10 +354,10 @@ package extract
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
a := 1
|
a := 1
|
||||||
a = 5 //@codeaction("refactor.extract", "a", araend, ara)
|
a = 5 //@codeaction("a", araend, "refactor.extract", ara)
|
||||||
a = a + 2 //@loc(araend, "2")
|
a = a + 2 //@loc(araend, "2")
|
||||||
|
|
||||||
//@codeaction("refactor.extract", "b", arbend, arb)
|
//@codeaction("b", arbend, "refactor.extract", arb)
|
||||||
newFunction(a) //@loc(arbend, "4")
|
newFunction(a) //@loc(arbend, "4")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,7 +371,7 @@ package extract
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
newFunction := 1
|
newFunction := 1
|
||||||
a := newFunction //@codeaction("refactor.extract", "a", "newFunction", scope)
|
a := newFunction //@codeaction("a", "newFunction", "refactor.extract", scope)
|
||||||
_ = a // avoid diagnostic
|
_ = a // avoid diagnostic
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,7 +384,7 @@ package extract
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
newFunction := 1
|
newFunction := 1
|
||||||
a := newFunction2(newFunction) //@codeaction("refactor.extract", "a", "newFunction", scope)
|
a := newFunction2(newFunction) //@codeaction("a", "newFunction", "refactor.extract", scope)
|
||||||
_ = a // avoid diagnostic
|
_ = a // avoid diagnostic
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,7 +402,7 @@ package extract
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
var a []int
|
var a []int
|
||||||
a = append(a, 2) //@codeaction("refactor.extract", "a", siEnd, si)
|
a = append(a, 2) //@codeaction("a", siEnd, "refactor.extract", si)
|
||||||
b := 4 //@loc(siEnd, "4")
|
b := 4 //@loc(siEnd, "4")
|
||||||
a = append(a, b)
|
a = append(a, b)
|
||||||
}
|
}
|
||||||
|
@ -412,7 +412,7 @@ package extract
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
var a []int
|
var a []int
|
||||||
//@codeaction("refactor.extract", "a", siEnd, si)
|
//@codeaction("a", siEnd, "refactor.extract", si)
|
||||||
a, b := newFunction(a) //@loc(siEnd, "4")
|
a, b := newFunction(a) //@loc(siEnd, "4")
|
||||||
a = append(a, b)
|
a = append(a, b)
|
||||||
}
|
}
|
||||||
|
@ -429,7 +429,7 @@ package extract
|
||||||
func _() {
|
func _() {
|
||||||
var b []int
|
var b []int
|
||||||
var a int
|
var a int
|
||||||
a = 2 //@codeaction("refactor.extract", "a", srEnd, sr)
|
a = 2 //@codeaction("a", srEnd, "refactor.extract", sr)
|
||||||
b = []int{}
|
b = []int{}
|
||||||
b = append(b, a) //@loc(srEnd, ")")
|
b = append(b, a) //@loc(srEnd, ")")
|
||||||
b[0] = 1
|
b[0] = 1
|
||||||
|
@ -441,7 +441,7 @@ package extract
|
||||||
func _() {
|
func _() {
|
||||||
var b []int
|
var b []int
|
||||||
var a int
|
var a int
|
||||||
//@codeaction("refactor.extract", "a", srEnd, sr)
|
//@codeaction("a", srEnd, "refactor.extract", sr)
|
||||||
b = newFunction(a, b) //@loc(srEnd, ")")
|
b = newFunction(a, b) //@loc(srEnd, ")")
|
||||||
b[0] = 1
|
b[0] = 1
|
||||||
}
|
}
|
||||||
|
@ -458,7 +458,7 @@ package extract
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
var b []int
|
var b []int
|
||||||
a := 2 //@codeaction("refactor.extract", "a", upEnd, up)
|
a := 2 //@codeaction("a", upEnd, "refactor.extract", up)
|
||||||
b = []int{}
|
b = []int{}
|
||||||
b = append(b, a) //@loc(upEnd, ")")
|
b = append(b, a) //@loc(upEnd, ")")
|
||||||
b[0] = 1
|
b[0] = 1
|
||||||
|
@ -472,7 +472,7 @@ package extract
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
var b []int
|
var b []int
|
||||||
//@codeaction("refactor.extract", "a", upEnd, up)
|
//@codeaction("a", upEnd, "refactor.extract", up)
|
||||||
a, b := newFunction(b) //@loc(upEnd, ")")
|
a, b := newFunction(b) //@loc(upEnd, ")")
|
||||||
b[0] = 1
|
b[0] = 1
|
||||||
if a == 2 {
|
if a == 2 {
|
||||||
|
@ -491,9 +491,9 @@ func newFunction(b []int) (int, []int) {
|
||||||
package extract
|
package extract
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
a := /* comment in the middle of a line */ 1 //@codeaction("refactor.extract", "a", commentEnd, comment1)
|
a := /* comment in the middle of a line */ 1 //@codeaction("a", commentEnd, "refactor.extract", comment1)
|
||||||
// Comment on its own line //@codeaction("refactor.extract", "Comment", commentEnd, comment2)
|
// Comment on its own line //@codeaction("Comment", commentEnd, "refactor.extract", comment2)
|
||||||
_ = a + 4 //@loc(commentEnd, "4"),codeaction("refactor.extract", "_", lastComment, comment3)
|
_ = a + 4 //@loc(commentEnd, "4"),codeaction("_", lastComment, "refactor.extract", comment3)
|
||||||
// Comment right after 3 + 4
|
// Comment right after 3 + 4
|
||||||
|
|
||||||
// Comment after with space //@loc(lastComment, "Comment")
|
// Comment after with space //@loc(lastComment, "Comment")
|
||||||
|
@ -504,9 +504,9 @@ package extract
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
/* comment in the middle of a line */
|
/* comment in the middle of a line */
|
||||||
//@codeaction("refactor.extract", "a", commentEnd, comment1)
|
//@codeaction("a", commentEnd, "refactor.extract", comment1)
|
||||||
// Comment on its own line //@codeaction("refactor.extract", "Comment", commentEnd, comment2)
|
// Comment on its own line //@codeaction("Comment", commentEnd, "refactor.extract", comment2)
|
||||||
newFunction() //@loc(commentEnd, "4"),codeaction("refactor.extract", "_", lastComment, comment3)
|
newFunction() //@loc(commentEnd, "4"),codeaction("_", lastComment, "refactor.extract", comment3)
|
||||||
// Comment right after 3 + 4
|
// Comment right after 3 + 4
|
||||||
|
|
||||||
// Comment after with space //@loc(lastComment, "Comment")
|
// Comment after with space //@loc(lastComment, "Comment")
|
||||||
|
@ -522,9 +522,9 @@ func newFunction() {
|
||||||
package extract
|
package extract
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
a := /* comment in the middle of a line */ 1 //@codeaction("refactor.extract", "a", commentEnd, comment1)
|
a := /* comment in the middle of a line */ 1 //@codeaction("a", commentEnd, "refactor.extract", comment1)
|
||||||
// Comment on its own line //@codeaction("refactor.extract", "Comment", commentEnd, comment2)
|
// Comment on its own line //@codeaction("Comment", commentEnd, "refactor.extract", comment2)
|
||||||
newFunction(a) //@loc(commentEnd, "4"),codeaction("refactor.extract", "_", lastComment, comment3)
|
newFunction(a) //@loc(commentEnd, "4"),codeaction("_", lastComment, "refactor.extract", comment3)
|
||||||
// Comment right after 3 + 4
|
// Comment right after 3 + 4
|
||||||
|
|
||||||
// Comment after with space //@loc(lastComment, "Comment")
|
// Comment after with space //@loc(lastComment, "Comment")
|
||||||
|
@ -538,9 +538,9 @@ func newFunction(a int) {
|
||||||
package extract
|
package extract
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
a := /* comment in the middle of a line */ 1 //@codeaction("refactor.extract", "a", commentEnd, comment1)
|
a := /* comment in the middle of a line */ 1 //@codeaction("a", commentEnd, "refactor.extract", comment1)
|
||||||
// Comment on its own line //@codeaction("refactor.extract", "Comment", commentEnd, comment2)
|
// Comment on its own line //@codeaction("Comment", commentEnd, "refactor.extract", comment2)
|
||||||
newFunction(a) //@loc(commentEnd, "4"),codeaction("refactor.extract", "_", lastComment, comment3)
|
newFunction(a) //@loc(commentEnd, "4"),codeaction("_", lastComment, "refactor.extract", comment3)
|
||||||
// Comment right after 3 + 4
|
// Comment right after 3 + 4
|
||||||
|
|
||||||
// Comment after with space //@loc(lastComment, "Comment")
|
// Comment after with space //@loc(lastComment, "Comment")
|
||||||
|
@ -557,7 +557,7 @@ import "strconv"
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
i, err := strconv.Atoi("1")
|
i, err := strconv.Atoi("1")
|
||||||
u, err := strconv.Atoi("2") //@codeaction("refactor.extract", "u", ")", redefine)
|
u, err := strconv.Atoi("2") //@codeaction("u", ")", "refactor.extract", redefine)
|
||||||
if i == u || err == nil {
|
if i == u || err == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -570,7 +570,7 @@ import "strconv"
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
i, err := strconv.Atoi("1")
|
i, err := strconv.Atoi("1")
|
||||||
u, err := newFunction() //@codeaction("refactor.extract", "u", ")", redefine)
|
u, err := newFunction() //@codeaction("u", ")", "refactor.extract", redefine)
|
||||||
if i == u || err == nil {
|
if i == u || err == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ package extract
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
x := []rune{} //@codeaction("refactor.extract", "x", end, ext)
|
x := []rune{} //@codeaction("x", end, "refactor.extract", ext)
|
||||||
s := "HELLO"
|
s := "HELLO"
|
||||||
for _, c := range s {
|
for _, c := range s {
|
||||||
x = append(x, c)
|
x = append(x, c)
|
||||||
|
@ -26,7 +26,7 @@ package extract
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
//@codeaction("refactor.extract", "x", end, ext)
|
//@codeaction("x", end, "refactor.extract", ext)
|
||||||
x := newFunction() //@loc(end, "}")
|
x := newFunction() //@loc(end, "}")
|
||||||
fmt.Printf("%x\n", x)
|
fmt.Printf("%x\n", x)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ module mod.test/imports
|
||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
-- add.go --
|
-- add.go --
|
||||||
package imports //@codeaction("source.organizeImports", "imports", "", add)
|
package imports //@codeaction("imports", "", "source.organizeImports", add)
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -18,7 +18,7 @@ func _() {
|
||||||
}
|
}
|
||||||
|
|
||||||
-- @add/add.go --
|
-- @add/add.go --
|
||||||
package imports //@codeaction("source.organizeImports", "imports", "", add)
|
package imports //@codeaction("imports", "", "source.organizeImports", add)
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -31,7 +31,7 @@ func _() {
|
||||||
}
|
}
|
||||||
|
|
||||||
-- good.go --
|
-- good.go --
|
||||||
package imports //@codeactionerr("source.organizeImports", "imports", "", re"found 0 CodeActions")
|
package imports //@codeactionerr("imports", "", "source.organizeImports", re"found 0 CodeActions")
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ fmt.Println("")
|
||||||
|
|
||||||
|
|
||||||
// package doc
|
// package doc
|
||||||
package imports //@codeaction("source.organizeImports", "imports", "", issue35458)
|
package imports //@codeaction("imports", "", "source.organizeImports", issue35458)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ func _() {
|
||||||
|
|
||||||
-- @issue35458/issue35458.go --
|
-- @issue35458/issue35458.go --
|
||||||
// package doc
|
// package doc
|
||||||
package imports //@codeaction("source.organizeImports", "imports", "", issue35458)
|
package imports //@codeaction("imports", "", "source.organizeImports", issue35458)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ func _() {
|
||||||
|
|
||||||
|
|
||||||
-- multi.go --
|
-- multi.go --
|
||||||
package imports //@codeaction("source.organizeImports", "imports", "", multi)
|
package imports //@codeaction("imports", "", "source.organizeImports", multi)
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ func _() {
|
||||||
}
|
}
|
||||||
|
|
||||||
-- @multi/multi.go --
|
-- @multi/multi.go --
|
||||||
package imports //@codeaction("source.organizeImports", "imports", "", multi)
|
package imports //@codeaction("imports", "", "source.organizeImports", multi)
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ func _() {
|
||||||
}
|
}
|
||||||
|
|
||||||
-- needs.go --
|
-- needs.go --
|
||||||
package imports //@codeaction("source.organizeImports", "package", "", needs)
|
package imports //@codeaction("package", "", "source.organizeImports", needs)
|
||||||
|
|
||||||
func goodbye() {
|
func goodbye() {
|
||||||
fmt.Printf("HI") //@diag("fmt", re"(undeclared|undefined)")
|
fmt.Printf("HI") //@diag("fmt", re"(undeclared|undefined)")
|
||||||
|
@ -115,7 +115,7 @@ func goodbye() {
|
||||||
}
|
}
|
||||||
|
|
||||||
-- @needs/needs.go --
|
-- @needs/needs.go --
|
||||||
package imports //@codeaction("source.organizeImports", "package", "", needs)
|
package imports //@codeaction("package", "", "source.organizeImports", needs)
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -128,7 +128,7 @@ func goodbye() {
|
||||||
}
|
}
|
||||||
|
|
||||||
-- remove.go --
|
-- remove.go --
|
||||||
package imports //@codeaction("source.organizeImports", "package", "", remove)
|
package imports //@codeaction("package", "", "source.organizeImports", remove)
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes" //@diag("\"bytes\"", re"not used")
|
"bytes" //@diag("\"bytes\"", re"not used")
|
||||||
|
@ -140,7 +140,7 @@ func _() {
|
||||||
}
|
}
|
||||||
|
|
||||||
-- @remove/remove.go --
|
-- @remove/remove.go --
|
||||||
package imports //@codeaction("source.organizeImports", "package", "", remove)
|
package imports //@codeaction("package", "", "source.organizeImports", remove)
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -151,7 +151,7 @@ func _() {
|
||||||
}
|
}
|
||||||
|
|
||||||
-- removeall.go --
|
-- removeall.go --
|
||||||
package imports //@codeaction("source.organizeImports", "package", "", removeall)
|
package imports //@codeaction("package", "", "source.organizeImports", removeall)
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes" //@diag("\"bytes\"", re"not used")
|
"bytes" //@diag("\"bytes\"", re"not used")
|
||||||
|
@ -163,7 +163,7 @@ func _() {
|
||||||
}
|
}
|
||||||
|
|
||||||
-- @removeall/removeall.go --
|
-- @removeall/removeall.go --
|
||||||
package imports //@codeaction("source.organizeImports", "package", "", removeall)
|
package imports //@codeaction("package", "", "source.organizeImports", removeall)
|
||||||
|
|
||||||
//@diag("\"fmt\"", re"not used")
|
//@diag("\"fmt\"", re"not used")
|
||||||
|
|
||||||
|
@ -172,4 +172,4 @@ func _() {
|
||||||
|
|
||||||
-- twolines.go --
|
-- twolines.go --
|
||||||
package imports
|
package imports
|
||||||
func main() {} //@codeactionerr("source.organizeImports", "main", "", re"found 0")
|
func main() {} //@codeactionerr("main", "", "source.organizeImports", re"found 0")
|
||||||
|
|
|
@ -18,7 +18,7 @@ func app[S interface{ ~[]E }, E interface{}](s S, e E) S {
|
||||||
func _() {
|
func _() {
|
||||||
_ = app[[]int]
|
_ = app[[]int]
|
||||||
_ = app[[]int, int]
|
_ = app[[]int, int]
|
||||||
_ = app[[]int]([]int{}, 0) //@codeaction("refactor.rewrite", "app", ")", infer)
|
_ = app[[]int]([]int{}, 0) //@codeaction("app", ")", "refactor.rewrite", infer)
|
||||||
_ = app([]int{}, 0)
|
_ = app([]int{}, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ func app[S interface{ ~[]E }, E interface{}](s S, e E) S {
|
||||||
func _() {
|
func _() {
|
||||||
_ = app[[]int]
|
_ = app[[]int]
|
||||||
_ = app[[]int, int]
|
_ = app[[]int, int]
|
||||||
_ = app([]int{}, 0) //@codeaction("refactor.rewrite", "app", ")", infer)
|
_ = app([]int{}, 0) //@codeaction("app", ")", "refactor.rewrite", infer)
|
||||||
_ = app([]int{}, 0)
|
_ = app([]int{}, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ go 1.18
|
||||||
package a
|
package a
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
println(add(1, 2)) //@codeaction("refactor.inline", "add", ")", inline)
|
println(add(1, 2)) //@codeaction("add", ")", "refactor.inline", inline)
|
||||||
}
|
}
|
||||||
|
|
||||||
func add(x, y int) int { return x + y }
|
func add(x, y int) int { return x + y }
|
||||||
|
@ -17,7 +17,7 @@ func add(x, y int) int { return x + y }
|
||||||
package a
|
package a
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
println(1 + 2) //@codeaction("refactor.inline", "add", ")", inline)
|
println(1 + 2) //@codeaction("add", ")", "refactor.inline", inline)
|
||||||
}
|
}
|
||||||
|
|
||||||
func add(x, y int) int { return x + y }
|
func add(x, y int) int { return x + y }
|
||||||
|
|
|
@ -8,14 +8,14 @@ go 1.18
|
||||||
-- a/a.go --
|
-- a/a.go --
|
||||||
package a
|
package a
|
||||||
|
|
||||||
func A(x, unused int) int { //@codeaction("refactor.rewrite", "unused", "unused", a)
|
func A(x, unused int) int { //@codeaction("unused", "unused", "refactor.rewrite", a)
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
-- @a/a/a.go --
|
-- @a/a/a.go --
|
||||||
package a
|
package a
|
||||||
|
|
||||||
func A(x int) int { //@codeaction("refactor.rewrite", "unused", "unused", a)
|
func A(x int) int { //@codeaction("unused", "unused", "refactor.rewrite", a)
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ func _() {
|
||||||
-- field/field.go --
|
-- field/field.go --
|
||||||
package field
|
package field
|
||||||
|
|
||||||
func Field(x int, field int) { //@codeaction("refactor.rewrite", "int", "int", field)
|
func Field(x int, field int) { //@codeaction("int", "int", "refactor.rewrite", field)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
|
@ -107,7 +107,7 @@ func _() {
|
||||||
-- @field/field/field.go --
|
-- @field/field/field.go --
|
||||||
package field
|
package field
|
||||||
|
|
||||||
func Field(field int) { //@codeaction("refactor.rewrite", "int", "int", field)
|
func Field(field int) { //@codeaction("int", "int", "refactor.rewrite", field)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
|
@ -116,7 +116,7 @@ func _() {
|
||||||
-- ellipsis/ellipsis.go --
|
-- ellipsis/ellipsis.go --
|
||||||
package ellipsis
|
package ellipsis
|
||||||
|
|
||||||
func Ellipsis(...any) { //@codeaction("refactor.rewrite", "any", "any", ellipsis)
|
func Ellipsis(...any) { //@codeaction("any", "any", "refactor.rewrite", ellipsis)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
|
@ -137,7 +137,7 @@ func i() []any
|
||||||
-- @ellipsis/ellipsis/ellipsis.go --
|
-- @ellipsis/ellipsis/ellipsis.go --
|
||||||
package ellipsis
|
package ellipsis
|
||||||
|
|
||||||
func Ellipsis() { //@codeaction("refactor.rewrite", "any", "any", ellipsis)
|
func Ellipsis() { //@codeaction("any", "any", "refactor.rewrite", ellipsis)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
|
@ -161,7 +161,7 @@ func i() []any
|
||||||
-- ellipsis2/ellipsis2.go --
|
-- ellipsis2/ellipsis2.go --
|
||||||
package ellipsis2
|
package ellipsis2
|
||||||
|
|
||||||
func Ellipsis2(_, _ int, rest ...int) { //@codeaction("refactor.rewrite", "_", "_", ellipsis2)
|
func Ellipsis2(_, _ int, rest ...int) { //@codeaction("_", "_", "refactor.rewrite", ellipsis2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
|
@ -175,7 +175,7 @@ func h() (int, int)
|
||||||
-- @ellipsis2/ellipsis2/ellipsis2.go --
|
-- @ellipsis2/ellipsis2/ellipsis2.go --
|
||||||
package ellipsis2
|
package ellipsis2
|
||||||
|
|
||||||
func Ellipsis2(_ int, rest ...int) { //@codeaction("refactor.rewrite", "_", "_", ellipsis2)
|
func Ellipsis2(_ int, rest ...int) { //@codeaction("_", "_", "refactor.rewrite", ellipsis2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
|
@ -190,7 +190,7 @@ func h() (int, int)
|
||||||
-- overlapping/overlapping.go --
|
-- overlapping/overlapping.go --
|
||||||
package overlapping
|
package overlapping
|
||||||
|
|
||||||
func Overlapping(i int) int { //@codeactionerr("refactor.rewrite", re"(i) int", re"(i) int", re"overlapping")
|
func Overlapping(i int) int { //@codeactionerr(re"(i) int", re"(i) int", "refactor.rewrite", re"overlapping")
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ func _() {
|
||||||
-- effects/effects.go --
|
-- effects/effects.go --
|
||||||
package effects
|
package effects
|
||||||
|
|
||||||
func effects(x, y int) int { //@codeaction("refactor.rewrite", "y", "y", effects)
|
func effects(x, y int) int { //@codeaction("y", "y", "refactor.rewrite", effects)
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,7 +216,7 @@ func _() {
|
||||||
-- @effects/effects/effects.go --
|
-- @effects/effects/effects.go --
|
||||||
package effects
|
package effects
|
||||||
|
|
||||||
func effects(x int) int { //@codeaction("refactor.rewrite", "y", "y", effects)
|
func effects(x int) int { //@codeaction("y", "y", "refactor.rewrite", effects)
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,13 +234,13 @@ func _() {
|
||||||
-- recursive/recursive.go --
|
-- recursive/recursive.go --
|
||||||
package recursive
|
package recursive
|
||||||
|
|
||||||
func Recursive(x int) int { //@codeaction("refactor.rewrite", "x", "x", recursive)
|
func Recursive(x int) int { //@codeaction("x", "x", "refactor.rewrite", recursive)
|
||||||
return Recursive(1)
|
return Recursive(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
-- @recursive/recursive/recursive.go --
|
-- @recursive/recursive/recursive.go --
|
||||||
package recursive
|
package recursive
|
||||||
|
|
||||||
func Recursive() int { //@codeaction("refactor.rewrite", "x", "x", recursive)
|
func Recursive() int { //@codeaction("x", "x", "refactor.rewrite", recursive)
|
||||||
return Recursive()
|
return Recursive()
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ go 1.18
|
||||||
package a
|
package a
|
||||||
|
|
||||||
// A doc comment.
|
// A doc comment.
|
||||||
func A(x /* used parameter */, unused int /* unused parameter */ ) int { //@codeaction("refactor.rewrite", "unused", "unused", a)
|
func A(x /* used parameter */, unused int /* unused parameter */ ) int { //@codeaction("unused", "unused", "refactor.rewrite", a)
|
||||||
// about to return
|
// about to return
|
||||||
return x // returning
|
return x // returning
|
||||||
// just returned
|
// just returned
|
||||||
|
@ -36,7 +36,7 @@ func one() int {
|
||||||
package a
|
package a
|
||||||
|
|
||||||
// A doc comment.
|
// A doc comment.
|
||||||
func A(x int) int { //@codeaction("refactor.rewrite", "unused", "unused", a)
|
func A(x int) int { //@codeaction("unused", "unused", "refactor.rewrite", a)
|
||||||
// about to return
|
// about to return
|
||||||
return x // returning
|
return x // returning
|
||||||
// just returned
|
// just returned
|
||||||
|
|
|
@ -10,7 +10,7 @@ go 1.18
|
||||||
-- a/a.go --
|
-- a/a.go --
|
||||||
package a
|
package a
|
||||||
|
|
||||||
func A(x, unused int) int { //@codeactionerr("refactor.rewrite", "unused", "unused", re"non-call function reference")
|
func A(x, unused int) int { //@codeactionerr("unused", "unused", "refactor.rewrite", re"non-call function reference")
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ import "mod.test/c"
|
||||||
|
|
||||||
var Chan chan c.C
|
var Chan chan c.C
|
||||||
|
|
||||||
func B(x, y c.C) { //@codeaction("refactor.rewrite", "x", "x", b)
|
func B(x, y c.C) { //@codeaction("x", "x", "refactor.rewrite", b)
|
||||||
}
|
}
|
||||||
|
|
||||||
-- c/c.go --
|
-- c/c.go --
|
||||||
|
@ -73,7 +73,7 @@ package d
|
||||||
// Removing the parameter should remove this import.
|
// Removing the parameter should remove this import.
|
||||||
import "mod.test/c"
|
import "mod.test/c"
|
||||||
|
|
||||||
func D(x c.C) { //@codeaction("refactor.rewrite", "x", "x", d)
|
func D(x c.C) { //@codeaction("x", "x", "refactor.rewrite", d)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
|
@ -145,14 +145,14 @@ import "mod.test/c"
|
||||||
|
|
||||||
var Chan chan c.C
|
var Chan chan c.C
|
||||||
|
|
||||||
func B(y c.C) { //@codeaction("refactor.rewrite", "x", "x", b)
|
func B(y c.C) { //@codeaction("x", "x", "refactor.rewrite", b)
|
||||||
}
|
}
|
||||||
-- @d/d/d.go --
|
-- @d/d/d.go --
|
||||||
package d
|
package d
|
||||||
|
|
||||||
// Removing the parameter should remove this import.
|
// Removing the parameter should remove this import.
|
||||||
|
|
||||||
func D() { //@codeaction("refactor.rewrite", "x", "x", d)
|
func D() { //@codeaction("x", "x", "refactor.rewrite", d)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
Test of the suggested fix to remove unnecessary assignments.
|
||||||
|
|
||||||
|
-- a.go --
|
||||||
|
package suggestedfix
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func goodbye() {
|
||||||
|
s := "hiiiiiii"
|
||||||
|
s = s //@suggestedfix("s = s", re"self-assignment", "quickfix", fix)
|
||||||
|
log.Print(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
-- @fix/a.go --
|
||||||
|
package suggestedfix
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func goodbye() {
|
||||||
|
s := "hiiiiiii"
|
||||||
|
//@suggestedfix("s = s", re"self-assignment", "quickfix", fix)
|
||||||
|
log.Print(s)
|
||||||
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ func ZeroValue(f *ast.File, pkg *types.Package, typ types.Type) ast.Expr {
|
||||||
case u.Info()&types.IsString != 0:
|
case u.Info()&types.IsString != 0:
|
||||||
return &ast.BasicLit{Kind: token.STRING, Value: `""`}
|
return &ast.BasicLit{Kind: token.STRING, Value: `""`}
|
||||||
default:
|
default:
|
||||||
panic("unknown basic type")
|
panic(fmt.Sprintf("unknown basic type %v", u))
|
||||||
}
|
}
|
||||||
case *types.Chan, *types.Interface, *types.Map, *types.Pointer, *types.Signature, *types.Slice, *types.Array:
|
case *types.Chan, *types.Interface, *types.Map, *types.Pointer, *types.Signature, *types.Slice, *types.Array:
|
||||||
return ast.NewIdent("nil")
|
return ast.NewIdent("nil")
|
||||||
|
|
|
@ -123,7 +123,7 @@ func TestToUnified(t *testing.T) {
|
||||||
testenv.NeedsTool(t, "patch")
|
testenv.NeedsTool(t, "patch")
|
||||||
for _, tc := range difftest.TestCases {
|
for _, tc := range difftest.TestCases {
|
||||||
t.Run(tc.Name, func(t *testing.T) {
|
t.Run(tc.Name, func(t *testing.T) {
|
||||||
unified, err := diff.ToUnified(difftest.FileA, difftest.FileB, tc.In, tc.Edits)
|
unified, err := diff.ToUnified(difftest.FileA, difftest.FileB, tc.In, tc.Edits, diff.DefaultContextLines)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -307,7 +307,7 @@ func DiffTest(t *testing.T, compute func(before, after string) []diff.Edit) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Apply failed: %v", err)
|
t.Fatalf("Apply failed: %v", err)
|
||||||
}
|
}
|
||||||
unified, err := diff.ToUnified(FileA, FileB, test.In, edits)
|
unified, err := diff.ToUnified(FileA, FileB, test.In, edits, diff.DefaultContextLines)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("ToUnified: %v", err)
|
t.Fatalf("ToUnified: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,12 +10,16 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// DefaultContextLines is the number of unchanged lines of surrounding
|
||||||
|
// context displayed by Unified. Use ToUnified to specify a different value.
|
||||||
|
const DefaultContextLines = 3
|
||||||
|
|
||||||
// Unified returns a unified diff of the old and new strings.
|
// Unified returns a unified diff of the old and new strings.
|
||||||
// The old and new labels are the names of the old and new files.
|
// The old and new labels are the names of the old and new files.
|
||||||
// If the strings are equal, it returns the empty string.
|
// If the strings are equal, it returns the empty string.
|
||||||
func Unified(oldLabel, newLabel, old, new string) string {
|
func Unified(oldLabel, newLabel, old, new string) string {
|
||||||
edits := Strings(old, new)
|
edits := Strings(old, new)
|
||||||
unified, err := ToUnified(oldLabel, newLabel, old, edits)
|
unified, err := ToUnified(oldLabel, newLabel, old, edits, DefaultContextLines)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Can't happen: edits are consistent.
|
// Can't happen: edits are consistent.
|
||||||
log.Fatalf("internal error in diff.Unified: %v", err)
|
log.Fatalf("internal error in diff.Unified: %v", err)
|
||||||
|
@ -23,11 +27,12 @@ func Unified(oldLabel, newLabel, old, new string) string {
|
||||||
return unified
|
return unified
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToUnified applies the edits to content and returns a unified diff.
|
// ToUnified applies the edits to content and returns a unified diff,
|
||||||
|
// with contextLines lines of (unchanged) context around each diff hunk.
|
||||||
// The old and new labels are the names of the content and result files.
|
// The old and new labels are the names of the content and result files.
|
||||||
// It returns an error if the edits are inconsistent; see ApplyEdits.
|
// It returns an error if the edits are inconsistent; see ApplyEdits.
|
||||||
func ToUnified(oldLabel, newLabel, content string, edits []Edit) (string, error) {
|
func ToUnified(oldLabel, newLabel, content string, edits []Edit, contextLines int) (string, error) {
|
||||||
u, err := toUnified(oldLabel, newLabel, content, edits)
|
u, err := toUnified(oldLabel, newLabel, content, edits, contextLines)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -93,14 +98,10 @@ func (k opKind) String() string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
edge = 3
|
|
||||||
gap = edge * 2
|
|
||||||
)
|
|
||||||
|
|
||||||
// toUnified takes a file contents and a sequence of edits, and calculates
|
// toUnified takes a file contents and a sequence of edits, and calculates
|
||||||
// a unified diff that represents those edits.
|
// a unified diff that represents those edits.
|
||||||
func toUnified(fromName, toName string, content string, edits []Edit) (unified, error) {
|
func toUnified(fromName, toName string, content string, edits []Edit, contextLines int) (unified, error) {
|
||||||
|
gap := contextLines * 2
|
||||||
u := unified{
|
u := unified{
|
||||||
from: fromName,
|
from: fromName,
|
||||||
to: toName,
|
to: toName,
|
||||||
|
@ -136,7 +137,7 @@ func toUnified(fromName, toName string, content string, edits []Edit) (unified,
|
||||||
//need to start a new hunk
|
//need to start a new hunk
|
||||||
if h != nil {
|
if h != nil {
|
||||||
// add the edge to the previous hunk
|
// add the edge to the previous hunk
|
||||||
addEqualLines(h, lines, last, last+edge)
|
addEqualLines(h, lines, last, last+contextLines)
|
||||||
u.hunks = append(u.hunks, h)
|
u.hunks = append(u.hunks, h)
|
||||||
}
|
}
|
||||||
toLine += start - last
|
toLine += start - last
|
||||||
|
@ -145,7 +146,7 @@ func toUnified(fromName, toName string, content string, edits []Edit) (unified,
|
||||||
toLine: toLine + 1,
|
toLine: toLine + 1,
|
||||||
}
|
}
|
||||||
// add the edge to the new hunk
|
// add the edge to the new hunk
|
||||||
delta := addEqualLines(h, lines, start-edge, start)
|
delta := addEqualLines(h, lines, start-contextLines, start)
|
||||||
h.fromLine -= delta
|
h.fromLine -= delta
|
||||||
h.toLine -= delta
|
h.toLine -= delta
|
||||||
}
|
}
|
||||||
|
@ -163,7 +164,7 @@ func toUnified(fromName, toName string, content string, edits []Edit) (unified,
|
||||||
}
|
}
|
||||||
if h != nil {
|
if h != nil {
|
||||||
// add the edge to the final hunk
|
// add the edge to the final hunk
|
||||||
addEqualLines(h, lines, last, last+edge)
|
addEqualLines(h, lines, last, last+contextLines)
|
||||||
u.hunks = append(u.hunks, h)
|
u.hunks = append(u.hunks, h)
|
||||||
}
|
}
|
||||||
return u, nil
|
return u, nil
|
||||||
|
|
Загрузка…
Ссылка в новой задаче