gopls/internal/settings: use CodeActionKind hierarchy

This change causes all CodeActions returned by gopls to use a
specific leaf type such as refactor.inline.call, instead of a
general category such as refactor or refactor.inline. The
categories may continue to be specified in the "Only" parameter
of a CodeActions request, and they apply hierarchically.
This allows clients to be more specific in requesting a
particular Code Action.

Details of golang/codeaction.go (messy diff):
- don't separate "typed" from "syntax only" operations;
  in practice we always need types.
- enabled (func) replaces want (map). It is computed
  in server.CodeAction and plumbed down.
- the "add" helper wraps a Command in a CodeAction
  and adds it to the result.

Also:
- use camelCase names, following LSP's source.organizeImports.
- document the specific kinds in the user manual
  and add a release note.
- remove the CodeAction title regexp parameter from
  @codeaction{,err} marker tests since the kind is
  now sufficiently expressive.

Fixes golang/go#40438
Updates golang/go#68791
Updates golang/go#68783

Change-Id: I1898f79d8af441a0376ad5067d05e0621840d987
Reviewed-on: https://go-review.googlesource.com/c/tools/+/604818
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Alan Donovan 2024-08-12 15:09:16 -04:00 коммит произвёл Gopher Robot
Родитель 15b8886a84
Коммит beed481fb5
46 изменённых файлов: 1102 добавлений и 982 удалений

Просмотреть файл

@ -50,12 +50,12 @@ The main difference between code lenses and code actions is this:
All the commands are presented together in a menu at that location.
Each action has a _kind_,
which is a hierarchical identifier such as `refactor.inline`.
which is a hierarchical identifier such as `refactor.inline.call`.
Clients may filter actions based on their kind.
For example, VS Code has:
two menus, "Refactor..." and "Source action...", each populated by
different kinds of code actions (`refactor.*` and `source.*`);
a lightbulb icon that triggers a menu of "quick fixes" (of kind `quickfix.*`);
different kinds of code actions (`refactor` and `source`);
a lightbulb icon that triggers a menu of "quick fixes" (of kind `quickfix`);
and a "Fix All" command that executes all code actions of
kind `source.fixAll`, which are those deemed unambiguously safe to apply.
@ -187,7 +187,7 @@ Client support:
- **CLI**: `gopls fix -a file.go:#offset source.organizeImports`
## Rename
## `refactor.rename`: Rename
The LSP
[`textDocument/rename`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_rename)
@ -269,7 +269,7 @@ Client support:
<a name='extract'></a>
## Extract function/method/variable
## `refactor.extract`: Extract function/method/variable
The `refactor.extract` family of code actions all return commands that
replace the selected expression or statements with a reference to a
@ -278,7 +278,7 @@ newly created declaration that contains the selected code:
<!-- See TODO comments in settings/codeactionkind.go about splitting
up "refactor.extract" into finer grained categories. -->
- **Extract function** replaces one or more complete statements by a
- **`refactor.extract.function`** replaces one or more complete statements by a
call to a new function named `newFunction` whose body contains the
statements. The selection must enclose fewer statements than the
entire body of the existing function.
@ -286,11 +286,11 @@ newly created declaration that contains the selected code:
![Before extracting a function](../assets/extract-function-before.png)
![After extracting a function](../assets/extract-function-after.png)
- **Extract method** is a variant of "Extract function" offered when
- **`refactor.extract.method`** is a variant of "Extract function" offered when
the selected statements belong to a method. The newly created function
will be a method of the same receiver type.
- **Extract variable** replaces an expression by a reference to a new
- **`refactor.extract.variable`** replaces an expression by a reference to a new
local variable named `x` initialized by the expression:
![Before extracting a var](../assets/extract-var-before.png)
@ -330,7 +330,7 @@ The following Extract features are planned for 2024 but not yet supported:
<a name='extract-to-new-file'></a>
## Extract declarations to new file
## `refactor.extract.toNewFile`: Extract declarations to new file
(Available from gopls/v0.17.0)
@ -347,11 +347,11 @@ first token of the declaration, such as `func` or `type`.
<a name='inline'></a>
## Inline call to function
## `refactor.inline.call`: Inline call to function
For a `codeActions` request where the selection is (or is within) a
call of a function or method, gopls will return a command of kind
`refactor.inline`, whose effect is to inline the function call.
`refactor.inline.call`, whose effect is to inline the function call.
The screenshots below show a call to `sum` before and after inlining:
<!-- source code used for images:
@ -501,15 +501,12 @@ more detail. All of this is to say, it's a complex problem, and we aim
for correctness first of all. We've already implemented a number of
important "tidiness optimizations" and we expect more to follow.
## Miscellaneous rewrites
## `refactor.rewrite`: Miscellaneous rewrites
This section covers a number of transformations that are accessible as
code actions of kind `refactor.rewrite`.
code actions whose kinds are children of `refactor.rewrite`.
<!-- See TODO comments in settings/codeactionkind.go about splitting
up "refactor.extract" into finer grained categories. -->
### Remove unused parameter
### `refactor.rewrite.removeUnusedParam`: Remove unused parameter
The [`unusedparams` analyzer](../analyzers.md#unusedparams) reports a
diagnostic for each parameter that is not used within the function body.
@ -544,7 +541,7 @@ Observe that in the first call, the argument `chargeCreditCard()` was
not deleted because of potential side effects, whereas in the second
call, the argument 2, a constant, was safely deleted.
### Convert string literal between raw and interpreted
### `refactor.rewrite.changeQuote`: Convert string literal between raw and interpreted
When the selection is a string literal, gopls offers a code action
to convert the string between raw form (`` `abc` ``) and interpreted
@ -556,7 +553,7 @@ form (`"abc"`) where this is possible:
Applying the code action a second time reverts back to the original
form.
### Invert 'if' condition
### `refactor.rewrite.invertIf`: Invert 'if' condition
When the selection is within an `if`/`else` statement that is not
followed by `else if`, gopls offers a code action to invert the
@ -571,7 +568,7 @@ blocks.
if the else block ends with a return statement; and thus applying
the operation twice does not get you back to where you started. -->
### Split elements into separate lines
### `refactor.rewrite.{split,join}Lines`: Split elements into separate lines
When the selection is within a bracketed list of items such as:
@ -619,7 +616,7 @@ comments, which run to the end of the line.
<!-- Strictly, line comments make only "join" (but not "split") infeasible. -->
### Fill struct literal
### `refactor.rewrite.fillStruct`: Fill struct literal
When the cursor is within a struct literal `S{}`, gopls offers the
"Fill S" code action, which populates each missing field of the
@ -651,7 +648,7 @@ Caveats:
or in other files in the package, are not considered; see
golang/go#68224.
### Fill switch
### `refactor.rewrite.fillSwitch`: Fill switch
When the cursor is within a switch statement whose operand type is an
_enum_ (a finite set of named constants), or within a type switch,

Просмотреть файл

@ -49,7 +49,7 @@ your source code has been modified but not saved.
like your editor to raise its window when handling this event.)
<a name='doc'></a>
## Browse package documentation
## `source.doc`: Browse package documentation
In any Go source file, a code action request returns a command to
"Browse package documentation". This command opens a browser window
@ -75,7 +75,7 @@ Client support:
<a name='freesymbols'></a>
## Browse free symbols
## `source.freesymbols`: Browse free symbols
When studying code, either to understand it or to evaluate a different
organization or factoring, it is common to need to know what the
@ -108,7 +108,7 @@ Client support:
<a name='assembly'></a>
## Browse assembly
## `source.assembly`: Browse assembly
When you're optimizing the performance of your code or investigating
an unexpected crash, it may sometimes be helpful to inspect the

Просмотреть файл

@ -6,11 +6,18 @@ The `fieldalignment` analyzer, previously disabled by default, has
been removed: it is redundant with the hover size/offset information
displayed by v0.16.0 and its diagnostics were confusing.
The kind (identifiers) of all of gopls' code actions have changed
to use more specific hierarchical names. For example, "Inline call"
has changed from `refactor.inline` to `refactor.inline.call`.
This allows clients to request particular code actions more precisely.
The user manual now includes the identifier in the documentation for each code action.
# New features
## Extract declarations to new file
Gopls now offers another code action, "Extract declarations to new file",
Gopls now offers another code action,
"Extract declarations to new file" (`refactor.extract.toNewFile`),
which moves selected code sections to a newly created file within the
same package. The created filename is chosen as the first {function, type,
const, var} name encountered. In addition, import declarations are added or

Просмотреть файл

@ -47,21 +47,34 @@ The -kind flag specifies a comma-separated list of LSP CodeAction kinds.
Only actions of these kinds will be requested from the server.
Valid kinds include:
gopls.doc.features
quickfix
refactor
refactor.extract
refactor.extract.function
refactor.extract.method
refactor.extract.toNewFile
refactor.extract.variable
refactor.inline
refactor.inline.call
refactor.rewrite
source.organizeImports
source.fixAll
refactor.rewrite.changeQuote
refactor.rewrite.fillStruct
refactor.rewrite.fillSwitch
refactor.rewrite.invertIf
refactor.rewrite.joinLines
refactor.rewrite.removeUnusedParam
refactor.rewrite.splitLines
source
source.assembly
source.doc
source.fixAll
source.freesymbols
goTest
gopls.doc.features
source.organizeImports
source.test
Kinds are hierarchical, so "refactor" includes "refactor.inline".
(Note: actions of kind "goTest" are not returned unless explicitly
(Note: actions of kind "source.test" are not returned unless explicitly
requested.)
The -title flag specifies a regular expression that must match the

Просмотреть файл

@ -988,6 +988,17 @@ type C struct{}
t.Errorf("codeaction: got <<%s>>, want <<%s>>\nstderr:\n%s", got, want, res.stderr)
}
}
// list code actions in file, filtering (hierarchically) by kind
{
res := gopls(t, tree, "codeaction", "-kind=source", "a.go")
res.checkExit(true)
got := res.stdout
want := `command "Browse documentation for package a" [source.doc]` +
"\n"
if got != want {
t.Errorf("codeaction: got <<%s>>, want <<%s>>\nstderr:\n%s", got, want, res.stderr)
}
}
// list code actions at position (of io.Reader)
{
res := gopls(t, tree, "codeaction", "b.go:#31")

Просмотреть файл

@ -18,21 +18,34 @@ The -kind flag specifies a comma-separated list of LSP CodeAction kinds.
Only actions of these kinds will be requested from the server.
Valid kinds include:
gopls.doc.features
quickfix
refactor
refactor.extract
refactor.extract.function
refactor.extract.method
refactor.extract.toNewFile
refactor.extract.variable
refactor.inline
refactor.inline.call
refactor.rewrite
source.organizeImports
source.fixAll
refactor.rewrite.changeQuote
refactor.rewrite.fillStruct
refactor.rewrite.fillSwitch
refactor.rewrite.invertIf
refactor.rewrite.joinLines
refactor.rewrite.removeUnusedParam
refactor.rewrite.splitLines
source
source.assembly
source.doc
source.fixAll
source.freesymbols
goTest
gopls.doc.features
source.organizeImports
source.test
Kinds are hierarchical, so "refactor" includes "refactor.inline".
(Note: actions of kind "goTest" are not returned unless explicitly
(Note: actions of kind "source.test" are not returned unless explicitly
requested.)
The -title flag specifies a regular expression that must match the

Просмотреть файл

@ -14,6 +14,7 @@ import (
"golang.org/x/tools/gopls/internal/cache/parsego"
"golang.org/x/tools/gopls/internal/file"
"golang.org/x/tools/gopls/internal/protocol"
"golang.org/x/tools/gopls/internal/settings"
"golang.org/x/tools/gopls/internal/util/bug"
"golang.org/x/tools/gopls/internal/util/safetoken"
"golang.org/x/tools/internal/diff"
@ -72,7 +73,7 @@ func convertStringLiteral(pgf *parsego.File, fh file.Handle, startPos, endPos to
}
return protocol.CodeAction{
Title: title,
Kind: protocol.RefactorRewrite,
Kind: settings.RefactorRewriteChangeQuote,
Edit: protocol.NewWorkspaceEdit(protocol.DocumentChangeEdit(fh, textedits)),
}, true
}

Просмотреть файл

@ -29,174 +29,189 @@ import (
"golang.org/x/tools/internal/typesinternal"
)
// CodeActions returns all wanted code actions (edits and other
// CodeActions returns all enabled code actions (edits and other
// commands) available for the selected range.
//
// Depending on how the request was triggered, fewer actions may be
// offered, e.g. to avoid UI distractions after mere cursor motion.
//
// See ../protocol/codeactionkind.go for some code action theory.
func CodeActions(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle, rng protocol.Range, diagnostics []protocol.Diagnostic, want map[protocol.CodeActionKind]bool, trigger protocol.CodeActionTriggerKind) (actions []protocol.CodeAction, _ error) {
// Only compute quick fixes if there are any diagnostics to fix.
wantQuickFixes := want[protocol.QuickFix] && len(diagnostics) > 0
func CodeActions(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle, rng protocol.Range, diagnostics []protocol.Diagnostic, enabled func(protocol.CodeActionKind) bool, trigger protocol.CodeActionTriggerKind) (actions []protocol.CodeAction, _ error) {
// code actions that require only a parse tree
pgf, err := snapshot.ParseGo(ctx, fh, parsego.Full)
if err != nil {
return nil, err
}
start, end, err := pgf.RangePos(rng)
if err != nil {
return nil, err
}
// add adds a code action to the result.
add := func(cmd protocol.Command, kind protocol.CodeActionKind) {
action := newCodeAction(cmd.Title, kind, &cmd, nil, snapshot.Options())
actions = append(actions, action)
}
// Note: don't forget to update the allow-list in Server.CodeAction
// when adding new query operations like GoTest and GoDoc that
// are permitted even in generated source files
// are permitted even in generated source files.
// Code actions that can be offered based on syntax information alone.
if wantQuickFixes ||
want[protocol.SourceOrganizeImports] ||
want[protocol.RefactorExtract] ||
want[settings.GoFreeSymbols] ||
want[settings.GoplsDocFeatures] {
pgf, err := snapshot.ParseGo(ctx, fh, parsego.Full)
// Only compute quick fixes if there are any diagnostics to fix.
wantQuickFixes := len(diagnostics) > 0 && enabled(protocol.QuickFix)
if wantQuickFixes || enabled(protocol.SourceOrganizeImports) {
// Process any missing imports and pair them with the diagnostics they fix.
importEdits, importEditsPerFix, err := allImportsFixes(ctx, snapshot, pgf)
if err != nil {
return nil, err
event.Error(ctx, "imports fixes", err, label.File.Of(fh.URI().Path()))
importEdits = nil
importEditsPerFix = nil
}
// Process any missing imports and pair them with the diagnostics they fix.
if wantQuickFixes || want[protocol.SourceOrganizeImports] {
importEdits, importEditsPerFix, err := allImportsFixes(ctx, snapshot, pgf)
if err != nil {
event.Error(ctx, "imports fixes", err, label.File.Of(fh.URI().Path()))
importEdits = nil
importEditsPerFix = nil
}
// Separate this into a set of codeActions per diagnostic, where
// each action is the addition, removal, or renaming of one import.
if wantQuickFixes {
for _, importFix := range importEditsPerFix {
fixed := fixedByImportFix(importFix.fix, diagnostics)
if len(fixed) == 0 {
continue
}
actions = append(actions, protocol.CodeAction{
Title: importFixTitle(importFix.fix),
Kind: protocol.QuickFix,
Edit: protocol.NewWorkspaceEdit(
protocol.DocumentChangeEdit(fh, importFix.edits)),
Diagnostics: fixed,
})
// Separate this into a set of codeActions per diagnostic, where
// each action is the addition, removal, or renaming of one import.
if wantQuickFixes {
for _, importFix := range importEditsPerFix {
fixed := fixedByImportFix(importFix.fix, diagnostics)
if len(fixed) == 0 {
continue
}
}
// Send all of the import edits as one code action if the file is
// being organized.
if want[protocol.SourceOrganizeImports] && len(importEdits) > 0 {
actions = append(actions, protocol.CodeAction{
Title: "Organize Imports",
Kind: protocol.SourceOrganizeImports,
Title: importFixTitle(importFix.fix),
Kind: protocol.QuickFix,
Edit: protocol.NewWorkspaceEdit(
protocol.DocumentChangeEdit(fh, importEdits)),
protocol.DocumentChangeEdit(fh, importFix.edits)),
Diagnostics: fixed,
})
}
}
if want[protocol.RefactorExtract] {
extractions, err := getExtractCodeActions(pgf, rng, snapshot.Options())
if err != nil {
return nil, err
}
actions = append(actions, extractions...)
}
if want[settings.GoFreeSymbols] && rng.End != rng.Start {
loc := protocol.Location{URI: pgf.URI, Range: rng}
cmd, err := command.NewFreeSymbolsCommand("Browse free symbols", snapshot.View().ID(), loc)
if err != nil {
return nil, err
}
// For implementation, see commandHandler.FreeSymbols.
// Send all of the import edits as one code action if the file is
// being organized.
if len(importEdits) > 0 && enabled(protocol.SourceOrganizeImports) {
actions = append(actions, protocol.CodeAction{
Title: cmd.Title,
Kind: settings.GoFreeSymbols,
Command: &cmd,
})
}
if want[settings.GoplsDocFeatures] {
// TODO(adonovan): after the docs are published in gopls/v0.17.0,
// use the gopls release tag instead of master.
cmd, err := command.NewClientOpenURLCommand(
"Browse gopls feature documentation",
"https://github.com/golang/tools/blob/master/gopls/doc/features/README.md")
if err != nil {
return nil, err
}
actions = append(actions, protocol.CodeAction{
Title: cmd.Title,
Kind: settings.GoplsDocFeatures,
Command: &cmd,
Title: "Organize Imports",
Kind: protocol.SourceOrganizeImports,
Edit: protocol.NewWorkspaceEdit(
protocol.DocumentChangeEdit(fh, importEdits)),
})
}
}
// Code actions requiring type information.
if want[protocol.RefactorRewrite] ||
want[protocol.RefactorInline] ||
want[settings.GoAssembly] ||
want[settings.GoDoc] ||
want[settings.GoTest] {
pkg, pgf, err := NarrowestPackageForFile(ctx, snapshot, fh.URI())
// refactor.extract.*
{
extractions, err := getExtractCodeActions(enabled, pgf, rng, snapshot.Options())
if err != nil {
return nil, err
}
start, end, err := pgf.RangePos(rng)
actions = append(actions, extractions...)
}
if kind := settings.GoFreeSymbols; enabled(kind) && rng.End != rng.Start {
loc := protocol.Location{URI: pgf.URI, Range: rng}
cmd, err := command.NewFreeSymbolsCommand("Browse free symbols", snapshot.View().ID(), loc)
if err != nil {
return nil, err
}
// For implementation, see commandHandler.FreeSymbols.
add(cmd, kind)
}
if want[protocol.RefactorRewrite] {
rewrites, err := getRewriteCodeActions(ctx, pkg, snapshot, pgf, fh, rng, snapshot.Options())
if err != nil {
return nil, err
}
actions = append(actions, rewrites...)
if kind := settings.GoplsDocFeatures; enabled(kind) {
// TODO(adonovan): after the docs are published in gopls/v0.17.0,
// use the gopls release tag instead of master.
cmd, err := command.NewClientOpenURLCommand(
"Browse gopls feature documentation",
"https://github.com/golang/tools/blob/master/gopls/doc/features/README.md")
if err != nil {
return nil, err
}
add(cmd, kind)
}
// To avoid distraction (e.g. VS Code lightbulb), offer "inline"
// only after a selection or explicit menu operation.
if want[protocol.RefactorInline] && (trigger != protocol.CodeActionAutomatic || rng.Start != rng.End) {
rewrites, err := getInlineCodeActions(pkg, pgf, rng, snapshot.Options())
if err != nil {
return nil, err
}
actions = append(actions, rewrites...)
}
// code actions that require type information
//
// In order to keep the fast path (in particular,
// VS Code's request for just source.organizeImports
// immediately after a save) fast, avoid type checking
// if no enabled code actions need it.
//
// TODO(adonovan): design some kind of registration mechanism
// that avoids the need to keep this list up to date.
if !slices.ContainsFunc([]protocol.CodeActionKind{
settings.RefactorRewriteRemoveUnusedParam,
settings.RefactorRewriteChangeQuote,
settings.RefactorRewriteInvertIf,
settings.RefactorRewriteSplitLines,
settings.RefactorRewriteJoinLines,
settings.RefactorRewriteFillStruct,
settings.RefactorRewriteFillSwitch,
settings.RefactorInlineCall,
settings.GoTest,
settings.GoDoc,
settings.GoAssembly,
}, enabled) {
return actions, nil
}
if want[settings.GoTest] {
fixes, err := getGoTestCodeActions(pkg, pgf, rng)
if err != nil {
return nil, err
}
actions = append(actions, fixes...)
}
// NB: update pgf, since it may not be a parse cache hit (esp. on 386).
// And update start, end, since they may have changed too.
// A framework would really make this cleaner.
pkg, pgf, err := NarrowestPackageForFile(ctx, snapshot, fh.URI())
if err != nil {
return nil, err
}
start, end, err = pgf.RangePos(rng)
if err != nil {
return nil, err
}
if want[settings.GoDoc] {
// "Browse documentation for ..."
_, _, title := DocFragment(pkg, pgf, start, end)
loc := protocol.Location{URI: pgf.URI, Range: rng}
cmd, err := command.NewDocCommand(title, loc)
if err != nil {
return nil, err
}
actions = append(actions, protocol.CodeAction{
Title: cmd.Title,
Kind: settings.GoDoc,
Command: &cmd,
})
// refactor.rewrite.*
{
rewrites, err := getRewriteCodeActions(enabled, ctx, pkg, snapshot, pgf, fh, rng, snapshot.Options())
if err != nil {
return nil, err
}
actions = append(actions, rewrites...)
}
if want[settings.GoAssembly] {
fixes, err := getGoAssemblyAction(snapshot.View(), pkg, pgf, rng)
if err != nil {
return nil, err
}
actions = append(actions, fixes...)
// To avoid distraction (e.g. VS Code lightbulb), offer "inline"
// only after a selection or explicit menu operation.
if trigger != protocol.CodeActionAutomatic || rng.Start != rng.End {
rewrites, err := getInlineCodeActions(enabled, pkg, pgf, rng, snapshot.Options())
if err != nil {
return nil, err
}
actions = append(actions, rewrites...)
}
if enabled(settings.GoTest) {
fixes, err := getGoTestCodeActions(pkg, pgf, rng)
if err != nil {
return nil, err
}
actions = append(actions, fixes...)
}
if kind := settings.GoDoc; enabled(kind) {
// "Browse documentation for ..."
_, _, title := DocFragment(pkg, pgf, start, end)
loc := protocol.Location{URI: pgf.URI, Range: rng}
cmd, err := command.NewDocCommand(title, loc)
if err != nil {
return nil, err
}
add(cmd, kind)
}
if enabled(settings.GoAssembly) {
fixes, err := getGoAssemblyAction(snapshot.View(), pkg, pgf, rng)
if err != nil {
return nil, err
}
actions = append(actions, fixes...)
}
return actions, nil
}
@ -256,63 +271,81 @@ func fixedByImportFix(fix *imports.ImportFix, diagnostics []protocol.Diagnostic)
}
// getExtractCodeActions returns any refactor.extract code actions for the selection.
func getExtractCodeActions(pgf *parsego.File, rng protocol.Range, options *settings.Options) ([]protocol.CodeAction, error) {
func getExtractCodeActions(enabled func(protocol.CodeActionKind) bool, pgf *parsego.File, rng protocol.Range, options *settings.Options) ([]protocol.CodeAction, error) {
start, end, err := pgf.RangePos(rng)
if err != nil {
return nil, err
}
puri := pgf.URI
var commands []protocol.Command
if _, ok, methodOk, _ := canExtractFunction(pgf.Tok, start, end, pgf.Src, pgf.File); ok {
cmd, err := command.NewApplyFixCommand("Extract function", command.ApplyFixArgs{
Fix: fixExtractFunction,
URI: puri,
Range: rng,
ResolveEdits: supportsResolveEdits(options),
})
if err != nil {
return nil, err
var actions []protocol.CodeAction
add := func(cmd protocol.Command, kind protocol.CodeActionKind) {
action := newCodeAction(cmd.Title, kind, &cmd, nil, options)
actions = append(actions, action)
}
// extract function or method
if enabled(settings.RefactorExtractFunction) || enabled(settings.RefactorExtractMethod) {
if _, ok, methodOk, _ := canExtractFunction(pgf.Tok, start, end, pgf.Src, pgf.File); ok {
// extract function
if kind := settings.RefactorExtractFunction; enabled(kind) {
cmd, err := command.NewApplyFixCommand("Extract function", command.ApplyFixArgs{
Fix: fixExtractFunction,
URI: pgf.URI,
Range: rng,
ResolveEdits: supportsResolveEdits(options),
})
if err != nil {
return nil, err
}
add(cmd, kind)
}
// extract method
if kind := settings.RefactorExtractMethod; methodOk && enabled(kind) {
cmd, err := command.NewApplyFixCommand("Extract method", command.ApplyFixArgs{
Fix: fixExtractMethod,
URI: pgf.URI,
Range: rng,
ResolveEdits: supportsResolveEdits(options),
})
if err != nil {
return nil, err
}
add(cmd, kind)
}
}
commands = append(commands, cmd)
if methodOk {
cmd, err := command.NewApplyFixCommand("Extract method", command.ApplyFixArgs{
Fix: fixExtractMethod,
URI: puri,
}
// extract variable
if kind := settings.RefactorExtractVariable; enabled(kind) {
if _, _, ok, _ := canExtractVariable(start, end, pgf.File); ok {
cmd, err := command.NewApplyFixCommand("Extract variable", command.ApplyFixArgs{
Fix: fixExtractVariable,
URI: pgf.URI,
Range: rng,
ResolveEdits: supportsResolveEdits(options),
})
if err != nil {
return nil, err
}
commands = append(commands, cmd)
add(cmd, kind)
}
}
if _, _, ok, _ := canExtractVariable(start, end, pgf.File); ok {
cmd, err := command.NewApplyFixCommand("Extract variable", command.ApplyFixArgs{
Fix: fixExtractVariable,
URI: puri,
Range: rng,
ResolveEdits: supportsResolveEdits(options),
})
if err != nil {
return nil, err
// extract to new file
if kind := settings.RefactorExtractToNewFile; enabled(kind) {
if canExtractToNewFile(pgf, start, end) {
cmd, err := command.NewExtractToNewFileCommand(
"Extract declarations to new file",
protocol.Location{URI: pgf.URI, Range: rng},
)
if err != nil {
return nil, err
}
add(cmd, kind)
}
commands = append(commands, cmd)
}
if canExtractToNewFile(pgf, start, end) {
cmd, err := command.NewExtractToNewFileCommand(
"Extract declarations to new file",
protocol.Location{URI: pgf.URI, Range: rng},
)
if err != nil {
return nil, err
}
commands = append(commands, cmd)
}
var actions []protocol.CodeAction
for i := range commands {
actions = append(actions, newCodeAction(commands[i].Title, protocol.RefactorExtract, &commands[i], nil, options))
}
return actions, nil
}
@ -335,7 +368,7 @@ func newCodeAction(title string, kind protocol.CodeActionKind, cmd *protocol.Com
return action
}
func getRewriteCodeActions(ctx context.Context, pkg *cache.Package, snapshot *cache.Snapshot, pgf *parsego.File, fh file.Handle, rng protocol.Range, options *settings.Options) (_ []protocol.CodeAction, rerr error) {
func getRewriteCodeActions(enabled func(protocol.CodeActionKind) bool, ctx context.Context, pkg *cache.Package, snapshot *cache.Snapshot, pgf *parsego.File, fh file.Handle, rng protocol.Range, options *settings.Options) (_ []protocol.CodeAction, rerr error) {
// golang/go#61693: code actions were refactored to run outside of the
// analysis framework, but as a result they lost their panic recovery.
//
@ -348,9 +381,14 @@ func getRewriteCodeActions(ctx context.Context, pkg *cache.Package, snapshot *ca
}()
var actions []protocol.CodeAction
add := func(cmd protocol.Command, kind protocol.CodeActionKind) {
action := newCodeAction(cmd.Title, kind, &cmd, nil, options)
actions = append(actions, action)
}
if canRemoveParameter(pkg, pgf, rng) {
cmd, err := command.NewChangeSignatureCommand("remove unused parameter", command.ChangeSignatureArgs{
// remove unused param
if kind := settings.RefactorRewriteRemoveUnusedParam; enabled(kind) && canRemoveParameter(pkg, pgf, rng) {
cmd, err := command.NewChangeSignatureCommand("Refactor: remove unused parameter", command.ChangeSignatureArgs{
RemoveParameter: protocol.Location{
URI: pgf.URI,
Range: rng,
@ -360,7 +398,7 @@ func getRewriteCodeActions(ctx context.Context, pkg *cache.Package, snapshot *ca
if err != nil {
return nil, err
}
actions = append(actions, newCodeAction("Refactor: remove unused parameter", protocol.RefactorRewrite, &cmd, nil, options))
add(cmd, kind)
}
start, end, err := pgf.RangePos(rng)
@ -368,61 +406,18 @@ func getRewriteCodeActions(ctx context.Context, pkg *cache.Package, snapshot *ca
return nil, err
}
if action, ok := convertStringLiteral(pgf, fh, start, end); ok {
actions = append(actions, action)
// change quote
if enabled(settings.RefactorRewriteChangeQuote) {
if action, ok := convertStringLiteral(pgf, fh, start, end); ok {
actions = append(actions, action)
}
}
var commands []protocol.Command
if _, ok, _ := canInvertIfCondition(pgf.File, start, end); ok {
cmd, err := command.NewApplyFixCommand("Invert 'if' condition", command.ApplyFixArgs{
Fix: fixInvertIfCondition,
URI: pgf.URI,
Range: rng,
ResolveEdits: supportsResolveEdits(options),
})
if err != nil {
return nil, err
}
commands = append(commands, cmd)
}
if msg, ok, _ := canSplitLines(pgf.File, pkg.FileSet(), start, end); ok {
cmd, err := command.NewApplyFixCommand(msg, command.ApplyFixArgs{
Fix: fixSplitLines,
URI: pgf.URI,
Range: rng,
ResolveEdits: supportsResolveEdits(options),
})
if err != nil {
return nil, err
}
commands = append(commands, cmd)
}
if msg, ok, _ := canJoinLines(pgf.File, pkg.FileSet(), start, end); ok {
cmd, err := command.NewApplyFixCommand(msg, command.ApplyFixArgs{
Fix: fixJoinLines,
URI: pgf.URI,
Range: rng,
ResolveEdits: supportsResolveEdits(options),
})
if err != nil {
return nil, err
}
commands = append(commands, cmd)
}
// fillstruct.Diagnose is a lazy analyzer: all it gives us is
// the (start, end, message) of each SuggestedFix; the actual
// edit is computed only later by ApplyFix, which calls fillstruct.SuggestedFix.
for _, diag := range fillstruct.Diagnose(pgf.File, start, end, pkg.Types(), pkg.TypesInfo()) {
rng, err := pgf.Mapper.PosRange(pgf.Tok, diag.Pos, diag.End)
if err != nil {
return nil, err
}
for _, fix := range diag.SuggestedFixes {
cmd, err := command.NewApplyFixCommand(fix.Message, command.ApplyFixArgs{
Fix: diag.Category,
// invert if condition
if kind := settings.RefactorRewriteInvertIf; enabled(kind) {
if _, ok, _ := canInvertIfCondition(pgf.File, start, end); ok {
cmd, err := command.NewApplyFixCommand("Invert 'if' condition", command.ApplyFixArgs{
Fix: fixInvertIfCondition,
URI: pgf.URI,
Range: rng,
ResolveEdits: supportsResolveEdits(options),
@ -430,23 +425,81 @@ func getRewriteCodeActions(ctx context.Context, pkg *cache.Package, snapshot *ca
if err != nil {
return nil, err
}
commands = append(commands, cmd)
add(cmd, kind)
}
}
for _, diag := range fillswitch.Diagnose(pgf.File, start, end, pkg.Types(), pkg.TypesInfo()) {
changes, err := suggestedFixToDocumentChange(ctx, snapshot, pkg.FileSet(), &diag.SuggestedFixes[0])
if err != nil {
return nil, err
// split lines
if kind := settings.RefactorRewriteSplitLines; enabled(kind) {
if msg, ok, _ := canSplitLines(pgf.File, pkg.FileSet(), start, end); ok {
cmd, err := command.NewApplyFixCommand(msg, command.ApplyFixArgs{
Fix: fixSplitLines,
URI: pgf.URI,
Range: rng,
ResolveEdits: supportsResolveEdits(options),
})
if err != nil {
return nil, err
}
add(cmd, kind)
}
actions = append(actions, protocol.CodeAction{
Title: diag.Message,
Kind: protocol.RefactorRewrite,
Edit: protocol.NewWorkspaceEdit(changes...),
})
}
for i := range commands {
actions = append(actions, newCodeAction(commands[i].Title, protocol.RefactorRewrite, &commands[i], nil, options))
// join lines
if kind := settings.RefactorRewriteJoinLines; enabled(kind) {
if msg, ok, _ := canJoinLines(pgf.File, pkg.FileSet(), start, end); ok {
cmd, err := command.NewApplyFixCommand(msg, command.ApplyFixArgs{
Fix: fixJoinLines,
URI: pgf.URI,
Range: rng,
ResolveEdits: supportsResolveEdits(options),
})
if err != nil {
return nil, err
}
add(cmd, kind)
}
}
// fill struct
//
// fillstruct.Diagnose is a lazy analyzer: all it gives us is
// the (start, end, message) of each SuggestedFix; the actual
// edit is computed only later by ApplyFix, which calls fillstruct.SuggestedFix.
if kind := settings.RefactorRewriteFillStruct; enabled(kind) {
for _, diag := range fillstruct.Diagnose(pgf.File, start, end, pkg.Types(), pkg.TypesInfo()) {
rng, err := pgf.Mapper.PosRange(pgf.Tok, diag.Pos, diag.End)
if err != nil {
return nil, err
}
for _, fix := range diag.SuggestedFixes {
cmd, err := command.NewApplyFixCommand(fix.Message, command.ApplyFixArgs{
Fix: diag.Category,
URI: pgf.URI,
Range: rng,
ResolveEdits: supportsResolveEdits(options),
})
if err != nil {
return nil, err
}
add(cmd, kind)
}
}
}
// fill switch
if kind := settings.RefactorRewriteFillSwitch; enabled(kind) {
for _, diag := range fillswitch.Diagnose(pgf.File, start, end, pkg.Types(), pkg.TypesInfo()) {
changes, err := suggestedFixToDocumentChange(ctx, snapshot, pkg.FileSet(), &diag.SuggestedFixes[0])
if err != nil {
return nil, err
}
actions = append(actions, protocol.CodeAction{
Title: diag.Message,
Kind: kind,
Edit: protocol.NewWorkspaceEdit(changes...),
})
}
}
return actions, nil
@ -502,32 +555,35 @@ func canRemoveParameter(pkg *cache.Package, pgf *parsego.File, rng protocol.Rang
}
// getInlineCodeActions returns refactor.inline actions available at the specified range.
func getInlineCodeActions(pkg *cache.Package, pgf *parsego.File, rng protocol.Range, options *settings.Options) ([]protocol.CodeAction, error) {
start, end, err := pgf.RangePos(rng)
if err != nil {
return nil, err
func getInlineCodeActions(enabled func(protocol.CodeActionKind) bool, pkg *cache.Package, pgf *parsego.File, rng protocol.Range, options *settings.Options) ([]protocol.CodeAction, error) {
var actions []protocol.CodeAction
add := func(cmd protocol.Command, kind protocol.CodeActionKind) {
action := newCodeAction(cmd.Title, kind, &cmd, nil, options)
actions = append(actions, action)
}
// If range is within call expression, offer to inline the call.
var commands []protocol.Command
if _, fn, err := enclosingStaticCall(pkg, pgf, start, end); err == nil {
cmd, err := command.NewApplyFixCommand(fmt.Sprintf("Inline call to %s", fn.Name()), command.ApplyFixArgs{
Fix: fixInlineCall,
URI: pgf.URI,
Range: rng,
ResolveEdits: supportsResolveEdits(options),
})
// inline call
if kind := settings.RefactorInlineCall; enabled(kind) {
start, end, err := pgf.RangePos(rng)
if err != nil {
return nil, err
}
commands = append(commands, cmd)
// If range is within call expression, offer to inline the call.
if _, fn, err := enclosingStaticCall(pkg, pgf, start, end); err == nil {
cmd, err := command.NewApplyFixCommand(fmt.Sprintf("Inline call to %s", fn.Name()), command.ApplyFixArgs{
Fix: fixInlineCall,
URI: pgf.URI,
Range: rng,
ResolveEdits: supportsResolveEdits(options),
})
if err != nil {
return nil, err
}
add(cmd, kind)
}
}
// Convert commands to actions.
var actions []protocol.CodeAction
for i := range commands {
actions = append(actions, newCodeAction(commands[i].Title, protocol.RefactorInline, &commands[i], nil, options))
}
return actions, nil
}

Просмотреть файл

@ -31,56 +31,72 @@ func (s *server) CodeAction(ctx context.Context, params *protocol.CodeActionPara
}
defer release()
uri := fh.URI()
// Determine the supported actions for this file kind.
kind := snapshot.FileKind(fh)
supportedCodeActions, ok := snapshot.Options().SupportedCodeActions[kind]
// Determine the supported code action kinds for this file.
//
// We interpret CodeActionKinds hierarchically, so refactor.rewrite
// subsumes refactor.rewrite.change_quote, for example.
// See ../protocol/codeactionkind.go for some code action theory.
codeActionKinds, ok := snapshot.Options().SupportedCodeActions[kind]
if !ok {
return nil, fmt.Errorf("no supported code actions for %v file kind", kind)
}
if len(supportedCodeActions) == 0 {
return nil, nil // not an error if there are none supported
}
// The Only field of the context specifies which code actions the client wants.
// If Only is empty, assume that the client wants all of the non-explicit code actions.
want := supportedCodeActions
// The Only field of the context specifies which code actions
// the client wants. If Only is empty, assume the client wants
// all supported code actions.
if len(params.Context.Only) > 0 {
want = make(map[protocol.CodeActionKind]bool)
// Explicit Code Actions are opt-in and shouldn't be
// returned to the client unless requested using Only.
//
// This mechanim exists to avoid a distracting
// lightbulb (code action) on each Test function.
// These actions are unwanted in VS Code because it
// has Test Explorer, and in other editors because
// the UX of executeCommand is unsatisfactory for tests:
// it doesn't show the complete streaming output.
// See https://github.com/joaotavora/eglot/discussions/1402
// for a better solution.
explicit := map[protocol.CodeActionKind]bool{
settings.GoTest: true,
}
for _, only := range params.Context.Only {
for k, v := range supportedCodeActions {
if only == k || strings.HasPrefix(string(k), string(only)+".") {
want[k] = want[k] || v
}
}
want[only] = want[only] || explicit[only]
codeActionKinds = make(map[protocol.CodeActionKind]bool)
for _, kind := range params.Context.Only {
codeActionKinds[kind] = true
}
}
if len(want) == 0 {
return nil, fmt.Errorf("no supported code action to execute for %s, wanted %v", uri, params.Context.Only)
// enabled reports whether the specified kind of code action is required.
enabled := func(kind protocol.CodeActionKind) bool {
// Given "refactor.rewrite.foo", check for it,
// then "refactor.rewrite", "refactor".
// A false map entry prunes the search for ancestors.
for {
if v, ok := codeActionKinds[kind]; ok {
return v
}
dot := strings.LastIndexByte(string(kind), '.')
if dot < 0 {
return false
}
// The "source.test" code action shouldn't be
// returned to the client unless requested by
// an exact match in Only.
//
// This mechanism exists to avoid a distracting
// lightbulb (code action) on each Test function.
// These actions are unwanted in VS Code because it
// has Test Explorer, and in other editors because
// the UX of executeCommand is unsatisfactory for tests:
// it doesn't show the complete streaming output.
// See https://github.com/joaotavora/eglot/discussions/1402
// for a better solution. See also
// https://github.com/golang/go/issues/67400.
//
// TODO(adonovan): consider instead switching on
// codeActionTriggerKind. Perhaps other noisy Source
// Actions should be guarded in the same way.
if kind == settings.GoTest {
return false // don't search ancestors
}
kind = kind[:dot]
}
}
switch kind {
case file.Mod:
var actions []protocol.CodeAction
fixes, err := s.codeActionsMatchingDiagnostics(ctx, fh.URI(), snapshot, params.Context.Diagnostics, want)
fixes, err := s.codeActionsMatchingDiagnostics(ctx, fh.URI(), snapshot, params.Context.Diagnostics, enabled)
if err != nil {
return nil, err
}
@ -117,7 +133,7 @@ func (s *server) CodeAction(ctx context.Context, params *protocol.CodeActionPara
// Note s.codeActionsMatchingDiagnostics returns only fixes
// detected during the analysis phase. golang.CodeActions computes
// extra changes that can address some diagnostics.
actions, err := s.codeActionsMatchingDiagnostics(ctx, uri, snapshot, params.Context.Diagnostics, want)
actions, err := s.codeActionsMatchingDiagnostics(ctx, uri, snapshot, params.Context.Diagnostics, enabled)
if err != nil {
return nil, err
}
@ -127,7 +143,7 @@ func (s *server) CodeAction(ctx context.Context, params *protocol.CodeActionPara
if k := params.Context.TriggerKind; k != nil { // (some clients omit it)
trigger = *k
}
moreActions, err := golang.CodeActions(ctx, snapshot, fh, params.Range, params.Context.Diagnostics, want, trigger)
moreActions, err := golang.CodeActions(ctx, snapshot, fh, params.Range, params.Context.Diagnostics, enabled, trigger)
if err != nil {
return nil, err
}
@ -206,14 +222,14 @@ func (s *server) ResolveCodeAction(ctx context.Context, ca *protocol.CodeAction)
// protocol.Diagnostic.Data field or, if there were none, by creating
// actions from edits associated with a matching Diagnostic from the
// set of stored diagnostics for this file.
func (s *server) codeActionsMatchingDiagnostics(ctx context.Context, uri protocol.DocumentURI, snapshot *cache.Snapshot, pds []protocol.Diagnostic, want map[protocol.CodeActionKind]bool) ([]protocol.CodeAction, error) {
func (s *server) codeActionsMatchingDiagnostics(ctx context.Context, uri protocol.DocumentURI, snapshot *cache.Snapshot, pds []protocol.Diagnostic, enabled func(protocol.CodeActionKind) bool) ([]protocol.CodeAction, error) {
var actions []protocol.CodeAction
var unbundled []protocol.Diagnostic // diagnostics without bundled code actions in their Data field
for _, pd := range pds {
bundled := cache.BundledLazyFixes(pd)
if len(bundled) > 0 {
for _, fix := range bundled {
if want[fix.Kind] {
if enabled(fix.Kind) {
actions = append(actions, fix)
}
}
@ -225,7 +241,7 @@ func (s *server) codeActionsMatchingDiagnostics(ctx context.Context, uri protoco
for _, pd := range unbundled {
for _, sd := range s.findMatchingDiagnostics(uri, pd) {
diagActions, err := codeActionsForDiagnostic(ctx, snapshot, sd, &pd, want)
diagActions, err := codeActionsForDiagnostic(ctx, snapshot, sd, &pd, enabled)
if err != nil {
return nil, err
}
@ -235,10 +251,10 @@ func (s *server) codeActionsMatchingDiagnostics(ctx context.Context, uri protoco
return actions, nil
}
func codeActionsForDiagnostic(ctx context.Context, snapshot *cache.Snapshot, sd *cache.Diagnostic, pd *protocol.Diagnostic, want map[protocol.CodeActionKind]bool) ([]protocol.CodeAction, error) {
func codeActionsForDiagnostic(ctx context.Context, snapshot *cache.Snapshot, sd *cache.Diagnostic, pd *protocol.Diagnostic, enabled func(protocol.CodeActionKind) bool) ([]protocol.CodeAction, error) {
var actions []protocol.CodeAction
for _, fix := range sd.SuggestedFixes {
if !want[fix.ActionKind] {
if !enabled(fix.ActionKind) {
continue
}
var changes []protocol.DocumentChange

Просмотреть файл

@ -12,16 +12,28 @@ import "golang.org/x/tools/gopls/internal/protocol"
//
// See ../protocol/tsprotocol.go for LSP standard kinds, including
//
// "quickfix"
// "refactor"
// "refactor.extract"
// "refactor.inline"
// "refactor.move"
// "refactor.rewrite"
// "source"
// "source.organizeImports"
// "source.fixAll"
// "notebook"
// quickfix
// refactor
// refactor.extract
// refactor.inline
// refactor.move
// refactor.rewrite
// source
// source.organizeImports
// source.fixAll
// notebook
//
// Kinds are hierarchical: "refactor" subsumes "refactor.inline",
// which subsumes "refactor.inline.call". The "Only" field in a
// CodeAction request may specify a category such as "refactor"; any
// matching code action will be returned.
//
// All CodeActions returned by gopls use a specific leaf kind such as
// "refactor.inline.call", except for quick fixes, which all use
// "quickfix". TODO(adonovan): perhaps quick fixes should also be
// hierarchical (e.g. quickfix.govulncheck.{reset,upgrade}).
//
// # VS Code
//
// The effects of CodeActionKind on the behavior of VS Code are
// baffling and undocumented. Here's what we have observed.
@ -54,32 +66,33 @@ import "golang.org/x/tools/gopls/internal/protocol"
// are unambiguously safe to apply so that clients may automatically
// apply all actions matching this category on save. (That said, this
// is not VS Code's default behavior; see editor.codeActionsOnSave.)
//
// TODO(adonovan): the intent of CodeActionKind is a hierarchy. We
// should changes gopls so that we don't create instances of the
// predefined kinds directly, but treat them as interfaces.
//
// For example,
//
// instead of: we should create:
// refactor.extract refactor.extract.const
// refactor.extract.var
// refactor.extract.func
// refactor.rewrite refactor.rewrite.fillstruct
// refactor.rewrite.unusedparam
// quickfix quickfix.govulncheck.reset
// quickfix.govulncheck.upgrade
//
// etc, so that client editors and scripts can be more specific in
// their requests.
//
// This entails that we use a segmented-path matching operator
// instead of == for CodeActionKinds throughout gopls.
// See golang/go#40438 for related discussion.
const (
GoAssembly protocol.CodeActionKind = "source.assembly"
GoDoc protocol.CodeActionKind = "source.doc"
GoFreeSymbols protocol.CodeActionKind = "source.freesymbols"
GoTest protocol.CodeActionKind = "source.test"
// source
GoAssembly protocol.CodeActionKind = "source.assembly"
GoDoc protocol.CodeActionKind = "source.doc"
GoFreeSymbols protocol.CodeActionKind = "source.freesymbols"
GoTest protocol.CodeActionKind = "source.test"
// gopls
GoplsDocFeatures protocol.CodeActionKind = "gopls.doc.features"
// refactor.rewrite
RefactorRewriteChangeQuote protocol.CodeActionKind = "refactor.rewrite.changeQuote"
RefactorRewriteFillStruct protocol.CodeActionKind = "refactor.rewrite.fillStruct"
RefactorRewriteFillSwitch protocol.CodeActionKind = "refactor.rewrite.fillSwitch"
RefactorRewriteInvertIf protocol.CodeActionKind = "refactor.rewrite.invertIf"
RefactorRewriteJoinLines protocol.CodeActionKind = "refactor.rewrite.joinLines"
RefactorRewriteRemoveUnusedParam protocol.CodeActionKind = "refactor.rewrite.removeUnusedParam"
RefactorRewriteSplitLines protocol.CodeActionKind = "refactor.rewrite.splitLines"
// refactor.inline
RefactorInlineCall protocol.CodeActionKind = "refactor.inline.call"
// refactor.extract
RefactorExtractFunction protocol.CodeActionKind = "refactor.extract.function"
RefactorExtractMethod protocol.CodeActionKind = "refactor.extract.method"
RefactorExtractVariable protocol.CodeActionKind = "refactor.extract.variable"
RefactorExtractToNewFile protocol.CodeActionKind = "refactor.extract.toNewFile"
// Note: add new kinds to the SupportedCodeActions map in defaults.go too.
)

Просмотреть файл

@ -43,17 +43,29 @@ func DefaultOptions(overrides ...func(*Options)) *Options {
ServerOptions: ServerOptions{
SupportedCodeActions: map[file.Kind]map[protocol.CodeActionKind]bool{
file.Go: {
protocol.SourceFixAll: true,
protocol.SourceOrganizeImports: true,
protocol.QuickFix: true,
protocol.RefactorRewrite: true,
protocol.RefactorInline: true,
protocol.RefactorExtract: true,
GoAssembly: true,
GoDoc: true,
GoFreeSymbols: true,
// This should include specific leaves in the tree,
// (e.g. refactor.inline.call) not generic branches
// (e.g. refactor.inline or refactor).
protocol.SourceFixAll: true,
protocol.SourceOrganizeImports: true,
protocol.QuickFix: true,
GoAssembly: true,
GoDoc: true,
GoFreeSymbols: true,
GoplsDocFeatures: true,
RefactorRewriteChangeQuote: true,
RefactorRewriteFillStruct: true,
RefactorRewriteFillSwitch: true,
RefactorRewriteInvertIf: true,
RefactorRewriteJoinLines: true,
RefactorRewriteRemoveUnusedParam: true,
RefactorRewriteSplitLines: true,
RefactorInlineCall: true,
RefactorExtractFunction: true,
RefactorExtractMethod: true,
RefactorExtractVariable: true,
RefactorExtractToNewFile: true,
// Not GoTest: it must be explicit in CodeActionParams.Context.Only
GoplsDocFeatures: true,
},
file.Mod: {
protocol.SourceOrganizeImports: true,

Просмотреть файл

@ -1026,16 +1026,6 @@ func (e *Editor) applyCodeActions(ctx context.Context, loc protocol.Location, di
if action.Title == "" {
return 0, fmt.Errorf("empty title for code action")
}
var match bool
for _, o := range only {
if action.Kind == o {
match = true
break
}
}
if !match {
continue
}
applied++
if err := e.ApplyCodeAction(ctx, action); err != nil {
return 0, err

Просмотреть файл

@ -68,8 +68,8 @@ func g() {}
settings.GoDoc,
settings.GoFreeSymbols,
settings.GoplsDocFeatures,
protocol.RefactorExtract,
protocol.RefactorInline)
settings.RefactorExtractVariable,
settings.RefactorInlineCall)
check("gen/a.go",
settings.GoAssembly,
settings.GoDoc,
@ -78,7 +78,7 @@ func g() {}
})
}
// Test refactor.inline is not included in automatically triggered code action
// Test refactor.inline.call is not included in automatically triggered code action
// unless users want refactoring.
func TestVSCodeIssue65167(t *testing.T) {
const vim1 = `package main
@ -108,9 +108,9 @@ func Func() int { return 0 }
actions := env.CodeAction(loc, nil, trigger)
want := trigger != protocol.CodeActionAutomatic || selectedRange
if got := slices.ContainsFunc(actions, func(act protocol.CodeAction) bool {
return act.Kind == protocol.RefactorInline
return act.Kind == settings.RefactorInlineCall
}); got != want {
t.Errorf("got refactor.inline = %t, want %t", got, want)
t.Errorf("got refactor.inline.call = %t, want %t", got, want)
}
})
}

Просмотреть файл

@ -7,6 +7,7 @@ package misc
import (
"testing"
"golang.org/x/tools/gopls/internal/settings"
"golang.org/x/tools/gopls/internal/test/compare"
. "golang.org/x/tools/gopls/internal/test/integration"
@ -38,7 +39,7 @@ func Foo() int {
// Find the extract function code action.
var extractFunc *protocol.CodeAction
for _, action := range actions {
if action.Kind == protocol.RefactorExtract && action.Title == "Extract function" {
if action.Kind == settings.RefactorExtractFunction {
extractFunc = &action
break
}

Просмотреть файл

@ -7,6 +7,7 @@ package misc
import (
"testing"
"golang.org/x/tools/gopls/internal/settings"
"golang.org/x/tools/gopls/internal/test/compare"
. "golang.org/x/tools/gopls/internal/test/integration"
@ -49,7 +50,7 @@ func Foo() {
runner.Run(t, basic, func(t *testing.T, env *Env) {
env.OpenFile("main.go")
fixes, err := env.Editor.CodeActions(env.Ctx, env.RegexpSearch("main.go", "Info{}"), nil, protocol.RefactorRewrite)
fixes, err := env.Editor.CodeActions(env.Ctx, env.RegexpSearch("main.go", "Info{}"), nil, settings.RefactorRewriteFillStruct)
if err != nil {
t.Fatal(err)
}

Просмотреть файл

@ -484,7 +484,7 @@ func checkMatch(t *testing.T, want bool, got []byte, pattern string) {
}
}
// codeActionByKind returns the first action of the specified kind, or an error.
// codeActionByKind returns the first action of (exactly) the specified kind, or an error.
func codeActionByKind(actions []protocol.CodeAction, kind protocol.CodeActionKind) (*protocol.CodeAction, error) {
for _, act := range actions {
if act.Kind == kind {

Просмотреть файл

@ -100,17 +100,15 @@ The following markers are supported within marker tests:
completion candidate produced at the given location with provided label
results in the given golden state.
- codeaction(start, end, kind, golden, ...titles): specifies a code action
- codeaction(start, end, kind, golden): specifies a code action
to request 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 changed file content after the code action is applied.
If titles are provided, they are used to filter the matching code
action.
TODO(rfindley): now that 'location' supports multi-line matches, replace
uses of 'codeaction' with codeactionedit.
- codeactionedit(location, kind, golden, ...titles): a shorter form of
- codeactionedit(location, 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.

Просмотреть файл

@ -1921,13 +1921,13 @@ func changedFiles(env *integration.Env, changes []protocol.DocumentChange) (map[
return result, nil
}
func codeActionMarker(mark marker, start, end protocol.Location, actionKind string, g *Golden, titles ...string) {
func codeActionMarker(mark marker, start, end protocol.Location, actionKind string, g *Golden) {
// Request the range from start.Start to end.End.
loc := start
loc.Range.End = end.Range.End
// Apply the fix it suggests.
changed, err := codeAction(mark.run.env, loc.URI, loc.Range, actionKind, nil, titles)
changed, err := codeAction(mark.run.env, loc.URI, loc.Range, actionKind, nil)
if err != nil {
mark.errorf("codeAction failed: %v", err)
return
@ -1937,8 +1937,8 @@ func codeActionMarker(mark marker, start, end protocol.Location, actionKind stri
checkChangedFiles(mark, changed, g)
}
func codeActionEditMarker(mark marker, loc protocol.Location, actionKind string, g *Golden, titles ...string) {
changed, err := codeAction(mark.run.env, loc.URI, loc.Range, actionKind, nil, titles)
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
@ -1950,7 +1950,7 @@ func codeActionEditMarker(mark marker, loc protocol.Location, actionKind string,
func codeActionErrMarker(mark marker, start, end protocol.Location, actionKind string, wantErr stringMatcher) {
loc := start
loc.Range.End = end.Range.End
_, err := codeAction(mark.run.env, loc.URI, loc.Range, actionKind, nil, nil)
_, err := codeAction(mark.run.env, loc.URI, loc.Range, actionKind, nil)
wantErr.checkErr(mark, err)
}
@ -2034,7 +2034,7 @@ func suggestedfixMarker(mark marker, loc protocol.Location, re *regexp.Regexp, g
}
// Apply the fix it suggests.
changed, err := codeAction(mark.run.env, loc.URI, diag.Range, "quickfix", &diag, nil)
changed, err := codeAction(mark.run.env, loc.URI, diag.Range, "quickfix", &diag)
if err != nil {
mark.errorf("suggestedfix failed: %v. (Use @suggestedfixerr for expected errors.)", err)
return
@ -2054,7 +2054,7 @@ func suggestedfixErrMarker(mark marker, loc protocol.Location, re *regexp.Regexp
}
// Apply the fix it suggests.
_, err := codeAction(mark.run.env, loc.URI, diag.Range, "quickfix", &diag, nil)
_, err := codeAction(mark.run.env, loc.URI, diag.Range, "quickfix", &diag)
wantErr.checkErr(mark, err)
}
@ -2065,8 +2065,8 @@ func suggestedfixErrMarker(mark marker, loc protocol.Location, re *regexp.Regexp
// The resulting map contains resulting file contents after the code action is
// applied. Currently, this function does not support code actions that return
// edits directly; it only supports code action commands.
func codeAction(env *integration.Env, uri protocol.DocumentURI, rng protocol.Range, actionKind string, diag *protocol.Diagnostic, titles []string) (map[string][]byte, error) {
changes, err := codeActionChanges(env, uri, rng, actionKind, diag, titles)
func codeAction(env *integration.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
}
@ -2076,8 +2076,7 @@ func codeAction(env *integration.Env, uri protocol.DocumentURI, rng protocol.Ran
// 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.
// If titles is non-empty, the code action title must be present among the provided titles.
func codeActionChanges(env *integration.Env, uri protocol.DocumentURI, rng protocol.Range, actionKind string, diag *protocol.Diagnostic, titles []string) ([]protocol.DocumentChange, error) {
func codeActionChanges(env *integration.Env, uri protocol.DocumentURI, rng protocol.Range, actionKind string, diag *protocol.Diagnostic) ([]protocol.DocumentChange, error) {
// Request all code actions that apply to the diagnostic.
// (The protocol supports filtering using Context.Only={actionKind}
// but we can give a better error if we don't filter.)
@ -2097,27 +2096,19 @@ func codeActionChanges(env *integration.Env, uri protocol.DocumentURI, rng proto
return nil, err
}
// Find the sole candidates CodeAction of the specified kind (e.g. refactor.rewrite).
// Find the sole candidate CodeAction of exactly the specified kind
// (e.g. refactor.inline.call).
var candidates []protocol.CodeAction
for _, act := range actions {
if act.Kind == protocol.CodeActionKind(actionKind) {
if len(titles) > 0 {
for _, f := range titles {
if act.Title == f {
candidates = append(candidates, act)
break
}
}
} else {
candidates = append(candidates, act)
}
candidates = append(candidates, act)
}
}
if len(candidates) != 1 {
for _, act := range actions {
env.T.Logf("found CodeAction Kind=%s Title=%q", act.Kind, act.Title)
}
return nil, fmt.Errorf("found %d CodeActions of kind %s matching filters %v for this diagnostic, want 1", len(candidates), actionKind, titles)
return nil, fmt.Errorf("found %d CodeActions of kind %s for this diagnostic, want 1", len(candidates), actionKind)
}
action := candidates[0]

Просмотреть файл

@ -17,53 +17,53 @@ import (
func foo() {
var s string
s = "hello" //@codeactionedit(`"`, "refactor.rewrite", a1, "Convert to raw string literal")
s = `hello` //@codeactionedit("`", "refactor.rewrite", a2, "Convert to interpreted string literal")
s = "hello\tworld" //@codeactionedit(`"`, "refactor.rewrite", a3, "Convert to raw string literal")
s = `hello world` //@codeactionedit("`", "refactor.rewrite", a4, "Convert to interpreted string literal")
s = "hello\nworld" //@codeactionedit(`"`, "refactor.rewrite", a5, "Convert to raw string literal")
s = "hello" //@codeactionedit(`"`, "refactor.rewrite.changeQuote", a1)
s = `hello` //@codeactionedit("`", "refactor.rewrite.changeQuote", a2)
s = "hello\tworld" //@codeactionedit(`"`, "refactor.rewrite.changeQuote", a3)
s = `hello world` //@codeactionedit("`", "refactor.rewrite.changeQuote", a4)
s = "hello\nworld" //@codeactionedit(`"`, "refactor.rewrite.changeQuote", a5)
// add a comment to avoid affect diff compute
s = `hello
world` //@codeactionedit("`", "refactor.rewrite", a6, "Convert to interpreted string literal")
s = "hello\"world" //@codeactionedit(`"`, "refactor.rewrite", a7, "Convert to raw string literal")
s = `hello"world` //@codeactionedit("`", "refactor.rewrite", a8, "Convert to interpreted string literal")
s = "hello\x1bworld" //@codeactionerr(`"`, "", "refactor.rewrite", re"found 0 CodeActions")
s = "hello`world" //@codeactionerr(`"`, "", "refactor.rewrite", re"found 0 CodeActions")
s = "hello\x7fworld" //@codeactionerr(`"`, "", "refactor.rewrite", re"found 0 CodeActions")
world` //@codeactionedit("`", "refactor.rewrite.changeQuote", a6)
s = "hello\"world" //@codeactionedit(`"`, "refactor.rewrite.changeQuote", a7)
s = `hello"world` //@codeactionedit("`", "refactor.rewrite.changeQuote", a8)
s = "hello\x1bworld" //@codeactionerr(`"`, "", "refactor.rewrite.changeQuote", re"found 0 CodeActions")
s = "hello`world" //@codeactionerr(`"`, "", "refactor.rewrite.changeQuote", re"found 0 CodeActions")
s = "hello\x7fworld" //@codeactionerr(`"`, "", "refactor.rewrite.changeQuote", re"found 0 CodeActions")
fmt.Println(s)
}
-- @a1/a.go --
@@ -9 +9 @@
- s = "hello" //@codeactionedit(`"`, "refactor.rewrite", a1, "Convert to raw string literal")
+ s = `hello` //@codeactionedit(`"`, "refactor.rewrite", a1, "Convert to raw string literal")
- s = "hello" //@codeactionedit(`"`, "refactor.rewrite.changeQuote", a1)
+ s = `hello` //@codeactionedit(`"`, "refactor.rewrite.changeQuote", a1)
-- @a2/a.go --
@@ -10 +10 @@
- s = `hello` //@codeactionedit("`", "refactor.rewrite", a2, "Convert to interpreted string literal")
+ s = "hello" //@codeactionedit("`", "refactor.rewrite", a2, "Convert to interpreted string literal")
- s = `hello` //@codeactionedit("`", "refactor.rewrite.changeQuote", a2)
+ s = "hello" //@codeactionedit("`", "refactor.rewrite.changeQuote", a2)
-- @a3/a.go --
@@ -11 +11 @@
- s = "hello\tworld" //@codeactionedit(`"`, "refactor.rewrite", a3, "Convert to raw string literal")
+ s = `hello world` //@codeactionedit(`"`, "refactor.rewrite", a3, "Convert to raw string literal")
- s = "hello\tworld" //@codeactionedit(`"`, "refactor.rewrite.changeQuote", a3)
+ s = `hello world` //@codeactionedit(`"`, "refactor.rewrite.changeQuote", a3)
-- @a4/a.go --
@@ -12 +12 @@
- s = `hello world` //@codeactionedit("`", "refactor.rewrite", a4, "Convert to interpreted string literal")
+ s = "hello\tworld" //@codeactionedit("`", "refactor.rewrite", a4, "Convert to interpreted string literal")
- s = `hello world` //@codeactionedit("`", "refactor.rewrite.changeQuote", a4)
+ s = "hello\tworld" //@codeactionedit("`", "refactor.rewrite.changeQuote", a4)
-- @a5/a.go --
@@ -13 +13,2 @@
- s = "hello\nworld" //@codeactionedit(`"`, "refactor.rewrite", a5, "Convert to raw string literal")
- s = "hello\nworld" //@codeactionedit(`"`, "refactor.rewrite.changeQuote", a5)
+ s = `hello
+world` //@codeactionedit(`"`, "refactor.rewrite", a5, "Convert to raw string literal")
+world` //@codeactionedit(`"`, "refactor.rewrite.changeQuote", a5)
-- @a6/a.go --
@@ -15,2 +15 @@
- s = `hello
-world` //@codeactionedit("`", "refactor.rewrite", a6, "Convert to interpreted string literal")
+ s = "hello\nworld" //@codeactionedit("`", "refactor.rewrite", a6, "Convert to interpreted string literal")
-world` //@codeactionedit("`", "refactor.rewrite.changeQuote", a6)
+ s = "hello\nworld" //@codeactionedit("`", "refactor.rewrite.changeQuote", a6)
-- @a7/a.go --
@@ -17 +17 @@
- s = "hello\"world" //@codeactionedit(`"`, "refactor.rewrite", a7, "Convert to raw string literal")
+ s = `hello"world` //@codeactionedit(`"`, "refactor.rewrite", a7, "Convert to raw string literal")
- s = "hello\"world" //@codeactionedit(`"`, "refactor.rewrite.changeQuote", a7)
+ s = `hello"world` //@codeactionedit(`"`, "refactor.rewrite.changeQuote", a7)
-- @a8/a.go --
@@ -18 +18 @@
- s = `hello"world` //@codeactionedit("`", "refactor.rewrite", a8, "Convert to interpreted string literal")
+ s = "hello\"world" //@codeactionedit("`", "refactor.rewrite", a8, "Convert to interpreted string literal")
- s = `hello"world` //@codeactionedit("`", "refactor.rewrite.changeQuote", a8)
+ s = "hello\"world" //@codeactionedit("`", "refactor.rewrite.changeQuote", a8)

Просмотреть файл

@ -9,7 +9,7 @@ go 1.18
-- a/a.go --
package a
//@codeactionedit(block, "refactor.extract", out, "Extract function")
//@codeactionedit(block, "refactor.extract.function", out)
func _() {
var logf func(string, ...any)

Просмотреть файл

@ -6,18 +6,18 @@ This test exercises function and method extraction.
-- basic.go --
package extract
//@codeactionedit(A_XLessThanYP, "refactor.extract", meth1, "Extract method")
//@codeactionedit(A_XLessThanYP, "refactor.extract", func1, "Extract function")
//@codeactionedit(A_AddP1, "refactor.extract", meth2, "Extract method")
//@codeactionedit(A_AddP1, "refactor.extract", func2, "Extract function")
//@codeactionedit(A_AddP2, "refactor.extract", meth3, "Extract method")
//@codeactionedit(A_AddP2, "refactor.extract", func3, "Extract function")
//@codeactionedit(A_XLessThanY, "refactor.extract", meth4, "Extract method")
//@codeactionedit(A_XLessThanY, "refactor.extract", func4, "Extract function")
//@codeactionedit(A_Add1, "refactor.extract", meth5, "Extract method")
//@codeactionedit(A_Add1, "refactor.extract", func5, "Extract function")
//@codeactionedit(A_Add2, "refactor.extract", meth6, "Extract method")
//@codeactionedit(A_Add2, "refactor.extract", func6, "Extract function")
//@codeactionedit(A_XLessThanYP, "refactor.extract.method", meth1)
//@codeactionedit(A_XLessThanYP, "refactor.extract.function", func1)
//@codeactionedit(A_AddP1, "refactor.extract.method", meth2)
//@codeactionedit(A_AddP1, "refactor.extract.function", func2)
//@codeactionedit(A_AddP2, "refactor.extract.method", meth3)
//@codeactionedit(A_AddP2, "refactor.extract.function", func3)
//@codeactionedit(A_XLessThanY, "refactor.extract.method", meth4)
//@codeactionedit(A_XLessThanY, "refactor.extract.function", func4)
//@codeactionedit(A_Add1, "refactor.extract.method", meth5)
//@codeactionedit(A_Add1, "refactor.extract.function", func5)
//@codeactionedit(A_Add2, "refactor.extract.method", meth6)
//@codeactionedit(A_Add2, "refactor.extract.function", func6)
type A struct {
x int
@ -162,18 +162,18 @@ import (
"testing"
)
//@codeactionedit(B_AddP, "refactor.extract", contextMeth1, "Extract method")
//@codeactionedit(B_AddP, "refactor.extract", contextFunc1, "Extract function")
//@codeactionedit(B_LongList, "refactor.extract", contextMeth2, "Extract method")
//@codeactionedit(B_LongList, "refactor.extract", contextFunc2, "Extract function")
//@codeactionedit(B_AddPWithB, "refactor.extract", contextFuncB, "Extract function")
//@codeactionedit(B_LongListWithT, "refactor.extract", contextFuncT, "Extract function")
//@codeactionedit(B_AddP, "refactor.extract.method", contextMeth1)
//@codeactionedit(B_AddP, "refactor.extract.function", contextFunc1)
//@codeactionedit(B_LongList, "refactor.extract.method", contextMeth2)
//@codeactionedit(B_LongList, "refactor.extract.function", contextFunc2)
//@codeactionedit(B_AddPWithB, "refactor.extract.function", contextFuncB)
//@codeactionedit(B_LongListWithT, "refactor.extract.function", contextFuncT)
type B struct {
x int
y int
}
func (b *B) AddP(ctx context.Context) (int, error) {
sum := b.x + b.y
return sum, ctx.Err() //@loc(B_AddP, re`return.*ctx\.Err\(\)`)

Просмотреть файл

@ -16,7 +16,7 @@ import (
func f() io.Reader
func main() {
switch r := f().(type) { //@codeactionedit("f()", "refactor.extract", type_switch_func_call)
switch r := f().(type) { //@codeactionedit("f()", "refactor.extract.variable", type_switch_func_call)
default:
_ = r
}
@ -24,6 +24,6 @@ func main() {
-- @type_switch_func_call/extract_switch.go --
@@ -10 +10,2 @@
- switch r := f().(type) { //@codeactionedit("f()", "refactor.extract", type_switch_func_call)
- switch r := f().(type) { //@codeactionedit("f()", "refactor.extract.variable", type_switch_func_call)
+ x := f()
+ switch r := x.(type) { //@codeactionedit("f()", "refactor.extract", type_switch_func_call)
+ switch r := x.(type) { //@codeactionedit("f()", "refactor.extract.variable", type_switch_func_call)

Просмотреть файл

@ -8,41 +8,41 @@ See extract_variable_resolve.txt for the same test with resolve support.
package extract
func _() {
var _ = 1 + 2 //@codeactionedit("1", "refactor.extract", basic_lit1)
var _ = 3 + 4 //@codeactionedit("3 + 4", "refactor.extract", basic_lit2)
var _ = 1 + 2 //@codeactionedit("1", "refactor.extract.variable", basic_lit1)
var _ = 3 + 4 //@codeactionedit("3 + 4", "refactor.extract.variable", basic_lit2)
}
-- @basic_lit1/basic_lit.go --
@@ -4 +4,2 @@
- var _ = 1 + 2 //@codeactionedit("1", "refactor.extract", basic_lit1)
- var _ = 1 + 2 //@codeactionedit("1", "refactor.extract.variable", basic_lit1)
+ x := 1
+ var _ = x + 2 //@codeactionedit("1", "refactor.extract", basic_lit1)
+ var _ = x + 2 //@codeactionedit("1", "refactor.extract.variable", basic_lit1)
-- @basic_lit2/basic_lit.go --
@@ -5 +5,2 @@
- var _ = 3 + 4 //@codeactionedit("3 + 4", "refactor.extract", basic_lit2)
- var _ = 3 + 4 //@codeactionedit("3 + 4", "refactor.extract.variable", basic_lit2)
+ x := 3 + 4
+ var _ = x //@codeactionedit("3 + 4", "refactor.extract", basic_lit2)
+ var _ = x //@codeactionedit("3 + 4", "refactor.extract.variable", basic_lit2)
-- func_call.go --
package extract
import "strconv"
func _() {
x0 := append([]int{}, 1) //@codeactionedit("append([]int{}, 1)", "refactor.extract", func_call1)
x0 := append([]int{}, 1) //@codeactionedit("append([]int{}, 1)", "refactor.extract.variable", func_call1)
str := "1"
b, err := strconv.Atoi(str) //@codeactionedit("strconv.Atoi(str)", "refactor.extract", func_call2)
b, err := strconv.Atoi(str) //@codeactionedit("strconv.Atoi(str)", "refactor.extract.variable", func_call2)
}
-- @func_call1/func_call.go --
@@ -6 +6,2 @@
- x0 := append([]int{}, 1) //@codeactionedit("append([]int{}, 1)", "refactor.extract", func_call1)
- x0 := append([]int{}, 1) //@codeactionedit("append([]int{}, 1)", "refactor.extract.variable", func_call1)
+ x := append([]int{}, 1)
+ x0 := x //@codeactionedit("append([]int{}, 1)", "refactor.extract", func_call1)
+ x0 := x //@codeactionedit("append([]int{}, 1)", "refactor.extract.variable", func_call1)
-- @func_call2/func_call.go --
@@ -8 +8,2 @@
- b, err := strconv.Atoi(str) //@codeactionedit("strconv.Atoi(str)", "refactor.extract", func_call2)
- b, err := strconv.Atoi(str) //@codeactionedit("strconv.Atoi(str)", "refactor.extract.variable", func_call2)
+ x, x1 := strconv.Atoi(str)
+ b, err := x, x1 //@codeactionedit("strconv.Atoi(str)", "refactor.extract", func_call2)
+ b, err := x, x1 //@codeactionedit("strconv.Atoi(str)", "refactor.extract.variable", func_call2)
-- scope.go --
package extract
@ -51,20 +51,20 @@ import "go/ast"
func _() {
x0 := 0
if true {
y := ast.CompositeLit{} //@codeactionedit("ast.CompositeLit{}", "refactor.extract", scope1)
y := ast.CompositeLit{} //@codeactionedit("ast.CompositeLit{}", "refactor.extract.variable", scope1)
}
if true {
x1 := !false //@codeactionedit("!false", "refactor.extract", scope2)
x1 := !false //@codeactionedit("!false", "refactor.extract.variable", scope2)
}
}
-- @scope1/scope.go --
@@ -8 +8,2 @@
- y := ast.CompositeLit{} //@codeactionedit("ast.CompositeLit{}", "refactor.extract", scope1)
- y := ast.CompositeLit{} //@codeactionedit("ast.CompositeLit{}", "refactor.extract.variable", scope1)
+ x := ast.CompositeLit{}
+ y := x //@codeactionedit("ast.CompositeLit{}", "refactor.extract", scope1)
+ y := x //@codeactionedit("ast.CompositeLit{}", "refactor.extract.variable", scope1)
-- @scope2/scope.go --
@@ -11 +11,2 @@
- x1 := !false //@codeactionedit("!false", "refactor.extract", scope2)
- x1 := !false //@codeactionedit("!false", "refactor.extract.variable", scope2)
+ x := !false
+ x1 := x //@codeactionedit("!false", "refactor.extract", scope2)
+ x1 := x //@codeactionedit("!false", "refactor.extract.variable", scope2)

Просмотреть файл

@ -19,41 +19,41 @@ See extract_variable.txt for the same test without resolve support.
package extract
func _() {
var _ = 1 + 2 //@codeactionedit("1", "refactor.extract", basic_lit1)
var _ = 3 + 4 //@codeactionedit("3 + 4", "refactor.extract", basic_lit2)
var _ = 1 + 2 //@codeactionedit("1", "refactor.extract.variable", basic_lit1)
var _ = 3 + 4 //@codeactionedit("3 + 4", "refactor.extract.variable", basic_lit2)
}
-- @basic_lit1/basic_lit.go --
@@ -4 +4,2 @@
- var _ = 1 + 2 //@codeactionedit("1", "refactor.extract", basic_lit1)
- var _ = 1 + 2 //@codeactionedit("1", "refactor.extract.variable", basic_lit1)
+ x := 1
+ var _ = x + 2 //@codeactionedit("1", "refactor.extract", basic_lit1)
+ var _ = x + 2 //@codeactionedit("1", "refactor.extract.variable", basic_lit1)
-- @basic_lit2/basic_lit.go --
@@ -5 +5,2 @@
- var _ = 3 + 4 //@codeactionedit("3 + 4", "refactor.extract", basic_lit2)
- var _ = 3 + 4 //@codeactionedit("3 + 4", "refactor.extract.variable", basic_lit2)
+ x := 3 + 4
+ var _ = x //@codeactionedit("3 + 4", "refactor.extract", basic_lit2)
+ var _ = x //@codeactionedit("3 + 4", "refactor.extract.variable", basic_lit2)
-- func_call.go --
package extract
import "strconv"
func _() {
x0 := append([]int{}, 1) //@codeactionedit("append([]int{}, 1)", "refactor.extract", func_call1)
x0 := append([]int{}, 1) //@codeactionedit("append([]int{}, 1)", "refactor.extract.variable", func_call1)
str := "1"
b, err := strconv.Atoi(str) //@codeactionedit("strconv.Atoi(str)", "refactor.extract", func_call2)
b, err := strconv.Atoi(str) //@codeactionedit("strconv.Atoi(str)", "refactor.extract.variable", func_call2)
}
-- @func_call1/func_call.go --
@@ -6 +6,2 @@
- x0 := append([]int{}, 1) //@codeactionedit("append([]int{}, 1)", "refactor.extract", func_call1)
- x0 := append([]int{}, 1) //@codeactionedit("append([]int{}, 1)", "refactor.extract.variable", func_call1)
+ x := append([]int{}, 1)
+ x0 := x //@codeactionedit("append([]int{}, 1)", "refactor.extract", func_call1)
+ x0 := x //@codeactionedit("append([]int{}, 1)", "refactor.extract.variable", func_call1)
-- @func_call2/func_call.go --
@@ -8 +8,2 @@
- b, err := strconv.Atoi(str) //@codeactionedit("strconv.Atoi(str)", "refactor.extract", func_call2)
- b, err := strconv.Atoi(str) //@codeactionedit("strconv.Atoi(str)", "refactor.extract.variable", func_call2)
+ x, x1 := strconv.Atoi(str)
+ b, err := x, x1 //@codeactionedit("strconv.Atoi(str)", "refactor.extract", func_call2)
+ b, err := x, x1 //@codeactionedit("strconv.Atoi(str)", "refactor.extract.variable", func_call2)
-- scope.go --
package extract
@ -62,20 +62,20 @@ import "go/ast"
func _() {
x0 := 0
if true {
y := ast.CompositeLit{} //@codeactionedit("ast.CompositeLit{}", "refactor.extract", scope1)
y := ast.CompositeLit{} //@codeactionedit("ast.CompositeLit{}", "refactor.extract.variable", scope1)
}
if true {
x1 := !false //@codeactionedit("!false", "refactor.extract", scope2)
x1 := !false //@codeactionedit("!false", "refactor.extract.variable", scope2)
}
}
-- @scope1/scope.go --
@@ -8 +8,2 @@
- y := ast.CompositeLit{} //@codeactionedit("ast.CompositeLit{}", "refactor.extract", scope1)
- y := ast.CompositeLit{} //@codeactionedit("ast.CompositeLit{}", "refactor.extract.variable", scope1)
+ x := ast.CompositeLit{}
+ y := x //@codeactionedit("ast.CompositeLit{}", "refactor.extract", scope1)
+ y := x //@codeactionedit("ast.CompositeLit{}", "refactor.extract.variable", scope1)
-- @scope2/scope.go --
@@ -11 +11,2 @@
- x1 := !false //@codeactionedit("!false", "refactor.extract", scope2)
- x1 := !false //@codeactionedit("!false", "refactor.extract.variable", scope2)
+ x := !false
+ x1 := x //@codeactionedit("!false", "refactor.extract", scope2)
+ x1 := x //@codeactionedit("!false", "refactor.extract.variable", scope2)

Просмотреть файл

@ -12,28 +12,28 @@ go 1.18
package main
// docs
func fn() {} //@codeactionedit("func", "refactor.extract", function_declaration)
func fn() {} //@codeactionedit("func", "refactor.extract.toNewFile", function_declaration)
func fn2() {} //@codeactionedit("fn2", "refactor.extract", only_select_func_name)
func fn2() {} //@codeactionedit("fn2", "refactor.extract.toNewFile", only_select_func_name)
func fn3() {} //@codeactionedit(re`()fn3`, "refactor.extract", zero_width_selection_on_func_name)
func fn3() {} //@codeactionedit(re`()fn3`, "refactor.extract.toNewFile", zero_width_selection_on_func_name)
// docs
type T int //@codeactionedit("type", "refactor.extract", type_declaration)
type T int //@codeactionedit("type", "refactor.extract.toNewFile", type_declaration)
// docs
var V int //@codeactionedit("var", "refactor.extract", var_declaration)
var V int //@codeactionedit("var", "refactor.extract.toNewFile", var_declaration)
// docs
const K = "" //@codeactionedit("const", "refactor.extract", const_declaration)
const K = "" //@codeactionedit("const", "refactor.extract.toNewFile", const_declaration)
const ( //@codeactionedit("const", "refactor.extract", const_declaration_multiple_specs)
const ( //@codeactionedit("const", "refactor.extract.toNewFile", const_declaration_multiple_specs)
P = iota
Q
R
)
func fnA () {} //@codeaction("func", mdEnd, "refactor.extract", multiple_declarations)
func fnA () {} //@codeaction("func", mdEnd, "refactor.extract.toNewFile", multiple_declarations)
// unattached comment
@ -45,13 +45,13 @@ func fnB () {} //@loc(mdEnd, "}")
-- existing2.1.go --
-- b.go --
package main
func existing() {} //@codeactionedit("func", "refactor.extract", file_name_conflict)
func existing2() {} //@codeactionedit("func", "refactor.extract", file_name_conflict_again)
func existing() {} //@codeactionedit("func", "refactor.extract.toNewFile", file_name_conflict)
func existing2() {} //@codeactionedit("func", "refactor.extract.toNewFile", file_name_conflict_again)
-- single_import.go --
package main
import "fmt"
func F() { //@codeactionedit("func", "refactor.extract", single_import)
func F() { //@codeactionedit("func", "refactor.extract.toNewFile", single_import)
fmt.Println()
}
@ -65,24 +65,24 @@ import (
func init(){
log.Println()
}
func F() { //@codeactionedit("func", "refactor.extract", multiple_imports)
func F() { //@codeactionedit("func", "refactor.extract.toNewFile", multiple_imports)
fmt.Println()
}
func g() string{ //@codeactionedit("func", "refactor.extract", renamed_import)
func g() string{ //@codeactionedit("func", "refactor.extract.toNewFile", renamed_import)
return time1.Now().string()
}
-- blank_import.go --
package main
import _ "fmt"
func F() {} //@codeactionedit("func", "refactor.extract", blank_import)
func F() {} //@codeactionedit("func", "refactor.extract.toNewFile", blank_import)
-- @blank_import/blank_import.go --
@@ -3 +3 @@
-func F() {} //@codeactionedit("func", "refactor.extract", blank_import)
+//@codeactionedit("func", "refactor.extract", blank_import)
-func F() {} //@codeactionedit("func", "refactor.extract.toNewFile", blank_import)
+//@codeactionedit("func", "refactor.extract.toNewFile", blank_import)
-- @blank_import/f.go --
@@ -0,0 +1,3 @@
+package main
@ -91,8 +91,8 @@ func F() {} //@codeactionedit("func", "refactor.extract", blank_import)
-- @const_declaration/a.go --
@@ -16,2 +16 @@
-// docs
-const K = "" //@codeactionedit("const", "refactor.extract", const_declaration)
+//@codeactionedit("const", "refactor.extract", const_declaration)
-const K = "" //@codeactionedit("const", "refactor.extract.toNewFile", const_declaration)
+//@codeactionedit("const", "refactor.extract.toNewFile", const_declaration)
-- @const_declaration/k.go --
@@ -0,0 +1,4 @@
+package main
@ -101,7 +101,7 @@ func F() {} //@codeactionedit("func", "refactor.extract", blank_import)
+const K = ""
-- @const_declaration_multiple_specs/a.go --
@@ -19,6 +19 @@
-const ( //@codeactionedit("const", "refactor.extract", const_declaration_multiple_specs)
-const ( //@codeactionedit("const", "refactor.extract.toNewFile", const_declaration_multiple_specs)
- P = iota
- Q
- R
@ -111,15 +111,15 @@ func F() {} //@codeactionedit("func", "refactor.extract", blank_import)
@@ -0,0 +1,7 @@
+package main
+
+const ( //@codeactionedit("const", "refactor.extract", const_declaration_multiple_specs)
+const ( //@codeactionedit("const", "refactor.extract.toNewFile", const_declaration_multiple_specs)
+ P = iota
+ Q
+ R
+)
-- @file_name_conflict/b.go --
@@ -2 +2 @@
-func existing() {} //@codeactionedit("func", "refactor.extract", file_name_conflict)
+//@codeactionedit("func", "refactor.extract", file_name_conflict)
-func existing() {} //@codeactionedit("func", "refactor.extract.toNewFile", file_name_conflict)
+//@codeactionedit("func", "refactor.extract.toNewFile", file_name_conflict)
-- @file_name_conflict/existing.1.go --
@@ -0,0 +1,3 @@
+package main
@ -127,8 +127,8 @@ func F() {} //@codeactionedit("func", "refactor.extract", blank_import)
+func existing() {}
-- @file_name_conflict_again/b.go --
@@ -3 +3 @@
-func existing2() {} //@codeactionedit("func", "refactor.extract", file_name_conflict_again)
+//@codeactionedit("func", "refactor.extract", file_name_conflict_again)
-func existing2() {} //@codeactionedit("func", "refactor.extract.toNewFile", file_name_conflict_again)
+//@codeactionedit("func", "refactor.extract.toNewFile", file_name_conflict_again)
-- @file_name_conflict_again/existing2.2.go --
@@ -0,0 +1,3 @@
+package main
@ -137,8 +137,8 @@ func F() {} //@codeactionedit("func", "refactor.extract", blank_import)
-- @function_declaration/a.go --
@@ -3,2 +3 @@
-// docs
-func fn() {} //@codeactionedit("func", "refactor.extract", function_declaration)
+//@codeactionedit("func", "refactor.extract", function_declaration)
-func fn() {} //@codeactionedit("func", "refactor.extract.toNewFile", function_declaration)
+//@codeactionedit("func", "refactor.extract.toNewFile", function_declaration)
-- @function_declaration/fn.go --
@@ -0,0 +1,4 @@
+package main
@ -149,22 +149,22 @@ func F() {} //@codeactionedit("func", "refactor.extract", blank_import)
package main
// docs
func fn() {} //@codeactionedit("func", "refactor.extract", function_declaration)
func fn() {} //@codeactionedit("func", "refactor.extract.toNewFile", function_declaration)
func fn2() {} //@codeactionedit("fn2", "refactor.extract", only_select_func_name)
func fn2() {} //@codeactionedit("fn2", "refactor.extract.toNewFile", only_select_func_name)
func fn3() {} //@codeactionedit(re`()fn3`, "refactor.extract", zero_width_selection_on_func_name)
func fn3() {} //@codeactionedit(re`()fn3`, "refactor.extract.toNewFile", zero_width_selection_on_func_name)
// docs
type T int //@codeactionedit("type", "refactor.extract", type_declaration)
type T int //@codeactionedit("type", "refactor.extract.toNewFile", type_declaration)
// docs
var V int //@codeactionedit("var", "refactor.extract", var_declaration)
var V int //@codeactionedit("var", "refactor.extract.toNewFile", var_declaration)
// docs
const K = "" //@codeactionedit("const", "refactor.extract", const_declaration)
const K = "" //@codeactionedit("const", "refactor.extract.toNewFile", const_declaration)
const ( //@codeactionedit("const", "refactor.extract", const_declaration_multiple_specs)
const ( //@codeactionedit("const", "refactor.extract.toNewFile", const_declaration_multiple_specs)
P = iota
Q
R
@ -176,7 +176,7 @@ const ( //@codeactionedit("const", "refactor.extract", const_declaration_multipl
-- @multiple_declarations/fna.go --
package main
func fnA() {} //@codeaction("func", mdEnd, "refactor.extract", multiple_declarations)
func fnA() {} //@codeaction("func", mdEnd, "refactor.extract.toNewFile", multiple_declarations)
// unattached comment
@ -189,7 +189,7 @@ func fnB() {}
+ "fmt"
+)
+
+func F() { //@codeactionedit("func", "refactor.extract", multiple_imports)
+func F() { //@codeactionedit("func", "refactor.extract.toNewFile", multiple_imports)
+ fmt.Println()
+}
-- @multiple_imports/multiple_imports.go --
@ -197,13 +197,13 @@ func fnB() {}
- "fmt"
+
@@ -10,3 +10 @@
-func F() { //@codeactionedit("func", "refactor.extract", multiple_imports)
-func F() { //@codeactionedit("func", "refactor.extract.toNewFile", multiple_imports)
- fmt.Println()
-}
-- @only_select_func_name/a.go --
@@ -6 +6 @@
-func fn2() {} //@codeactionedit("fn2", "refactor.extract", only_select_func_name)
+//@codeactionedit("fn2", "refactor.extract", only_select_func_name)
-func fn2() {} //@codeactionedit("fn2", "refactor.extract.toNewFile", only_select_func_name)
+//@codeactionedit("fn2", "refactor.extract.toNewFile", only_select_func_name)
-- @only_select_func_name/fn2.go --
@@ -0,0 +1,3 @@
+package main
@ -217,20 +217,20 @@ func fnB() {}
+ "fmt"
+)
+
+func F() { //@codeactionedit("func", "refactor.extract", single_import)
+func F() { //@codeactionedit("func", "refactor.extract.toNewFile", single_import)
+ fmt.Println()
+}
-- @single_import/single_import.go --
@@ -2,4 +2 @@
-import "fmt"
-func F() { //@codeactionedit("func", "refactor.extract", single_import)
-func F() { //@codeactionedit("func", "refactor.extract.toNewFile", single_import)
- fmt.Println()
-}
-- @type_declaration/a.go --
@@ -10,2 +10 @@
-// docs
-type T int //@codeactionedit("type", "refactor.extract", type_declaration)
+//@codeactionedit("type", "refactor.extract", type_declaration)
-type T int //@codeactionedit("type", "refactor.extract.toNewFile", type_declaration)
+//@codeactionedit("type", "refactor.extract.toNewFile", type_declaration)
-- @type_declaration/t.go --
@@ -0,0 +1,4 @@
+package main
@ -240,8 +240,8 @@ func fnB() {}
-- @var_declaration/a.go --
@@ -13,2 +13 @@
-// docs
-var V int //@codeactionedit("var", "refactor.extract", var_declaration)
+//@codeactionedit("var", "refactor.extract", var_declaration)
-var V int //@codeactionedit("var", "refactor.extract.toNewFile", var_declaration)
+//@codeactionedit("var", "refactor.extract.toNewFile", var_declaration)
-- @var_declaration/v.go --
@@ -0,0 +1,4 @@
+package main
@ -250,8 +250,8 @@ func fnB() {}
+var V int
-- @zero_width_selection_on_func_name/a.go --
@@ -8 +8 @@
-func fn3() {} //@codeactionedit(re`()fn3`, "refactor.extract", zero_width_selection_on_func_name)
+//@codeactionedit(re`()fn3`, "refactor.extract", zero_width_selection_on_func_name)
-func fn3() {} //@codeactionedit(re`()fn3`, "refactor.extract.toNewFile", zero_width_selection_on_func_name)
+//@codeactionedit(re`()fn3`, "refactor.extract.toNewFile", zero_width_selection_on_func_name)
-- @zero_width_selection_on_func_name/fn3.go --
@@ -0,0 +1,3 @@
+package main
@ -265,7 +265,7 @@ func fnB() {}
+ time1 "time"
+)
+
+func g() string { //@codeactionedit("func", "refactor.extract", renamed_import)
+func g() string { //@codeactionedit("func", "refactor.extract.toNewFile", renamed_import)
+ return time1.Now().string()
+}
-- @renamed_import/multiple_imports.go --
@ -273,7 +273,7 @@ func fnB() {}
- time1 "time"
+
@@ -13,4 +13 @@
-func g() string{ //@codeactionedit("func", "refactor.extract", renamed_import)
-func g() string{ //@codeactionedit("func", "refactor.extract.toNewFile", renamed_import)
- return time1.Now().string()
-}
-

Просмотреть файл

@ -28,49 +28,49 @@ type basicStruct struct {
foo int
}
var _ = basicStruct{} //@codeactionedit("}", "refactor.rewrite", a1)
var _ = basicStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a1)
type twoArgStruct struct {
foo int
bar string
}
var _ = twoArgStruct{} //@codeactionedit("}", "refactor.rewrite", a2)
var _ = twoArgStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a2)
type nestedStruct struct {
bar string
basic basicStruct
}
var _ = nestedStruct{} //@codeactionedit("}", "refactor.rewrite", a3)
var _ = nestedStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a3)
var _ = data.B{} //@codeactionedit("}", "refactor.rewrite", a4)
var _ = data.B{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a4)
-- @a1/a.go --
@@ -11 +11,3 @@
-var _ = basicStruct{} //@codeactionedit("}", "refactor.rewrite", a1)
-var _ = basicStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a1)
+var _ = basicStruct{
+ foo: 0,
+} //@codeactionedit("}", "refactor.rewrite", a1)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", a1)
-- @a2/a.go --
@@ -18 +18,4 @@
-var _ = twoArgStruct{} //@codeactionedit("}", "refactor.rewrite", a2)
-var _ = twoArgStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a2)
+var _ = twoArgStruct{
+ foo: 0,
+ bar: "",
+} //@codeactionedit("}", "refactor.rewrite", a2)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", a2)
-- @a3/a.go --
@@ -25 +25,4 @@
-var _ = nestedStruct{} //@codeactionedit("}", "refactor.rewrite", a3)
-var _ = nestedStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a3)
+var _ = nestedStruct{
+ bar: "",
+ basic: basicStruct{},
+} //@codeactionedit("}", "refactor.rewrite", a3)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", a3)
-- @a4/a.go --
@@ -27 +27,3 @@
-var _ = data.B{} //@codeactionedit("}", "refactor.rewrite", a4)
-var _ = data.B{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a4)
+var _ = data.B{
+ ExportedInt: 0,
+} //@codeactionedit("}", "refactor.rewrite", a4)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", a4)
-- a2.go --
package fillstruct
@ -82,57 +82,57 @@ type typedStruct struct {
a [2]string
}
var _ = typedStruct{} //@codeactionedit("}", "refactor.rewrite", a21)
var _ = typedStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a21)
type funStruct struct {
fn func(i int) int
}
var _ = funStruct{} //@codeactionedit("}", "refactor.rewrite", a22)
var _ = funStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a22)
type funStructComplex struct {
fn func(i int, s string) (string, int)
}
var _ = funStructComplex{} //@codeactionedit("}", "refactor.rewrite", a23)
var _ = funStructComplex{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a23)
type funStructEmpty struct {
fn func()
}
var _ = funStructEmpty{} //@codeactionedit("}", "refactor.rewrite", a24)
var _ = funStructEmpty{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a24)
-- @a21/a2.go --
@@ -11 +11,7 @@
-var _ = typedStruct{} //@codeactionedit("}", "refactor.rewrite", a21)
-var _ = typedStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a21)
+var _ = typedStruct{
+ m: map[string]int{},
+ s: []int{},
+ c: make(chan int),
+ c1: make(<-chan int),
+ a: [2]string{},
+} //@codeactionedit("}", "refactor.rewrite", a21)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", a21)
-- @a22/a2.go --
@@ -17 +17,4 @@
-var _ = funStruct{} //@codeactionedit("}", "refactor.rewrite", a22)
-var _ = funStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a22)
+var _ = funStruct{
+ fn: func(i int) int {
+ },
+} //@codeactionedit("}", "refactor.rewrite", a22)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", a22)
-- @a23/a2.go --
@@ -23 +23,4 @@
-var _ = funStructComplex{} //@codeactionedit("}", "refactor.rewrite", a23)
-var _ = funStructComplex{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a23)
+var _ = funStructComplex{
+ fn: func(i int, s string) (string, int) {
+ },
+} //@codeactionedit("}", "refactor.rewrite", a23)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", a23)
-- @a24/a2.go --
@@ -29 +29,4 @@
-var _ = funStructEmpty{} //@codeactionedit("}", "refactor.rewrite", a24)
-var _ = funStructEmpty{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a24)
+var _ = funStructEmpty{
+ fn: func() {
+ },
+} //@codeactionedit("}", "refactor.rewrite", a24)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", a24)
-- a3.go --
package fillstruct
@ -150,7 +150,7 @@ type Bar struct {
Y *Foo
}
var _ = Bar{} //@codeactionedit("}", "refactor.rewrite", a31)
var _ = Bar{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a31)
type importedStruct struct {
m map[*ast.CompositeLit]ast.Field
@ -161,7 +161,7 @@ type importedStruct struct {
st ast.CompositeLit
}
var _ = importedStruct{} //@codeactionedit("}", "refactor.rewrite", a32)
var _ = importedStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a32)
type pointerBuiltinStruct struct {
b *bool
@ -169,23 +169,23 @@ type pointerBuiltinStruct struct {
i *int
}
var _ = pointerBuiltinStruct{} //@codeactionedit("}", "refactor.rewrite", a33)
var _ = pointerBuiltinStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a33)
var _ = []ast.BasicLit{
{}, //@codeactionedit("}", "refactor.rewrite", a34)
{}, //@codeactionedit("}", "refactor.rewrite.fillStruct", a34)
}
var _ = []ast.BasicLit{{}} //@codeactionedit("}", "refactor.rewrite", a35)
var _ = []ast.BasicLit{{}} //@codeactionedit("}", "refactor.rewrite.fillStruct", a35)
-- @a31/a3.go --
@@ -17 +17,4 @@
-var _ = Bar{} //@codeactionedit("}", "refactor.rewrite", a31)
-var _ = Bar{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a31)
+var _ = Bar{
+ X: &Foo{},
+ Y: &Foo{},
+} //@codeactionedit("}", "refactor.rewrite", a31)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", a31)
-- @a32/a3.go --
@@ -28 +28,9 @@
-var _ = importedStruct{} //@codeactionedit("}", "refactor.rewrite", a32)
-var _ = importedStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a32)
+var _ = importedStruct{
+ m: map[*ast.CompositeLit]ast.Field{},
+ s: []ast.BadExpr{},
@ -194,31 +194,31 @@ var _ = []ast.BasicLit{{}} //@codeactionedit("}", "refactor.rewrite", a35)
+ fn: func(ast_decl ast.DeclStmt) ast.Ellipsis {
+ },
+ st: ast.CompositeLit{},
+} //@codeactionedit("}", "refactor.rewrite", a32)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", a32)
-- @a33/a3.go --
@@ -36 +36,5 @@
-var _ = pointerBuiltinStruct{} //@codeactionedit("}", "refactor.rewrite", a33)
-var _ = pointerBuiltinStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a33)
+var _ = pointerBuiltinStruct{
+ b: new(bool),
+ s: new(string),
+ i: new(int),
+} //@codeactionedit("}", "refactor.rewrite", a33)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", a33)
-- @a34/a3.go --
@@ -39 +39,5 @@
- {}, //@codeactionedit("}", "refactor.rewrite", a34)
- {}, //@codeactionedit("}", "refactor.rewrite.fillStruct", a34)
+ {
+ ValuePos: 0,
+ Kind: 0,
+ Value: "",
+ }, //@codeactionedit("}", "refactor.rewrite", a34)
+ }, //@codeactionedit("}", "refactor.rewrite.fillStruct", a34)
-- @a35/a3.go --
@@ -42 +42,5 @@
-var _ = []ast.BasicLit{{}} //@codeactionedit("}", "refactor.rewrite", a35)
-var _ = []ast.BasicLit{{}} //@codeactionedit("}", "refactor.rewrite.fillStruct", a35)
+var _ = []ast.BasicLit{{
+ ValuePos: 0,
+ Kind: 0,
+ Value: "",
+}} //@codeactionedit("}", "refactor.rewrite", a35)
+}} //@codeactionedit("}", "refactor.rewrite.fillStruct", a35)
-- a4.go --
package fillstruct
@ -244,49 +244,49 @@ type assignStruct struct {
func fill() {
var x int
var _ = iStruct{} //@codeactionedit("}", "refactor.rewrite", a41)
var _ = iStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a41)
var s string
var _ = sStruct{} //@codeactionedit("}", "refactor.rewrite", a42)
var _ = sStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a42)
var n int
_ = []int{}
if true {
arr := []int{1, 2}
}
var _ = multiFill{} //@codeactionedit("}", "refactor.rewrite", a43)
var _ = multiFill{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a43)
var node *ast.CompositeLit
var _ = assignStruct{} //@codeactionedit("}", "refactor.rewrite", a45)
var _ = assignStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a45)
}
-- @a41/a4.go --
@@ -25 +25,3 @@
- var _ = iStruct{} //@codeactionedit("}", "refactor.rewrite", a41)
- var _ = iStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a41)
+ var _ = iStruct{
+ X: x,
+ } //@codeactionedit("}", "refactor.rewrite", a41)
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", a41)
-- @a42/a4.go --
@@ -28 +28,3 @@
- var _ = sStruct{} //@codeactionedit("}", "refactor.rewrite", a42)
- var _ = sStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a42)
+ var _ = sStruct{
+ str: s,
+ } //@codeactionedit("}", "refactor.rewrite", a42)
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", a42)
-- @a43/a4.go --
@@ -35 +35,5 @@
- var _ = multiFill{} //@codeactionedit("}", "refactor.rewrite", a43)
- var _ = multiFill{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a43)
+ var _ = multiFill{
+ num: n,
+ strin: s,
+ arr: []int{},
+ } //@codeactionedit("}", "refactor.rewrite", a43)
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", a43)
-- @a45/a4.go --
@@ -38 +38,3 @@
- var _ = assignStruct{} //@codeactionedit("}", "refactor.rewrite", a45)
- var _ = assignStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a45)
+ var _ = assignStruct{
+ n: node,
+ } //@codeactionedit("}", "refactor.rewrite", a45)
-- fill_struct.go --
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", a45)
-- fillStruct.go --
package fillstruct
type StructA struct {
@ -306,43 +306,43 @@ type StructA3 struct {
}
func fill() {
a := StructA{} //@codeactionedit("}", "refactor.rewrite", fill_struct1)
b := StructA2{} //@codeactionedit("}", "refactor.rewrite", fill_struct2)
c := StructA3{} //@codeactionedit("}", "refactor.rewrite", fill_struct3)
a := StructA{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct1)
b := StructA2{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct2)
c := StructA3{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct3)
if true {
_ = StructA3{} //@codeactionedit("}", "refactor.rewrite", fill_struct4)
_ = StructA3{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct4)
}
}
-- @fill_struct1/fill_struct.go --
-- @fillStruct1/fillStruct.go --
@@ -20 +20,7 @@
- a := StructA{} //@codeactionedit("}", "refactor.rewrite", fill_struct1)
- a := StructA{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct1)
+ a := StructA{
+ unexportedIntField: 0,
+ ExportedIntField: 0,
+ MapA: map[int]string{},
+ Array: []int{},
+ StructB: StructB{},
+ } //@codeactionedit("}", "refactor.rewrite", fill_struct1)
-- @fill_struct2/fill_struct.go --
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct1)
-- @fillStruct2/fillStruct.go --
@@ -21 +21,3 @@
- b := StructA2{} //@codeactionedit("}", "refactor.rewrite", fill_struct2)
- b := StructA2{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct2)
+ b := StructA2{
+ B: &StructB{},
+ } //@codeactionedit("}", "refactor.rewrite", fill_struct2)
-- @fill_struct3/fill_struct.go --
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct2)
-- @fillStruct3/fillStruct.go --
@@ -22 +22,3 @@
- c := StructA3{} //@codeactionedit("}", "refactor.rewrite", fill_struct3)
- c := StructA3{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct3)
+ c := StructA3{
+ B: StructB{},
+ } //@codeactionedit("}", "refactor.rewrite", fill_struct3)
-- @fill_struct4/fill_struct.go --
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct3)
-- @fillStruct4/fillStruct.go --
@@ -24 +24,3 @@
- _ = StructA3{} //@codeactionedit("}", "refactor.rewrite", fill_struct4)
- _ = StructA3{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct4)
+ _ = StructA3{
+ B: StructB{},
+ } //@codeactionedit("}", "refactor.rewrite", fill_struct4)
-- fill_struct_anon.go --
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct4)
-- fillStruct_anon.go --
package fillstruct
type StructAnon struct {
@ -355,17 +355,17 @@ type StructAnon struct {
}
func fill() {
_ := StructAnon{} //@codeactionedit("}", "refactor.rewrite", fill_struct_anon)
_ := StructAnon{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_anon)
}
-- @fill_struct_anon/fill_struct_anon.go --
-- @fillStruct_anon/fillStruct_anon.go --
@@ -13 +13,5 @@
- _ := StructAnon{} //@codeactionedit("}", "refactor.rewrite", fill_struct_anon)
- _ := StructAnon{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_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 --
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_anon)
-- fillStruct_nested.go --
package fillstruct
type StructB struct {
@ -378,17 +378,17 @@ type StructC struct {
func nested() {
c := StructB{
StructC: StructC{}, //@codeactionedit("}", "refactor.rewrite", fill_nested)
StructC: StructC{}, //@codeactionedit("}", "refactor.rewrite.fillStruct", fill_nested)
}
}
-- @fill_nested/fill_struct_nested.go --
-- @fill_nested/fillStruct_nested.go --
@@ -13 +13,3 @@
- StructC: StructC{}, //@codeactionedit("}", "refactor.rewrite", fill_nested)
- StructC: StructC{}, //@codeactionedit("}", "refactor.rewrite.fillStruct", fill_nested)
+ StructC: StructC{
+ unexportedInt: 0,
+ }, //@codeactionedit("}", "refactor.rewrite", fill_nested)
-- fill_struct_package.go --
+ }, //@codeactionedit("}", "refactor.rewrite.fillStruct", fill_nested)
-- fillStruct_package.go --
package fillstruct
import (
@ -398,26 +398,26 @@ import (
)
func unexported() {
a := data.B{} //@codeactionedit("}", "refactor.rewrite", fill_struct_package1)
_ = h2.Client{} //@codeactionedit("}", "refactor.rewrite", fill_struct_package2)
a := data.B{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_package1)
_ = h2.Client{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_package2)
}
-- @fill_struct_package1/fill_struct_package.go --
-- @fillStruct_package1/fillStruct_package.go --
@@ -10 +10,3 @@
- a := data.B{} //@codeactionedit("}", "refactor.rewrite", fill_struct_package1)
- a := data.B{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_package1)
+ a := data.B{
+ ExportedInt: 0,
+ } //@codeactionedit("}", "refactor.rewrite", fill_struct_package1)
-- @fill_struct_package2/fill_struct_package.go --
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_package1)
-- @fillStruct_package2/fillStruct_package.go --
@@ -11 +11,7 @@
- _ = h2.Client{} //@codeactionedit("}", "refactor.rewrite", fill_struct_package2)
- _ = h2.Client{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_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 --
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_package2)
-- fillStruct_partial.go --
package fillstruct
type StructPartialA struct {
@ -434,22 +434,22 @@ type StructPartialB struct {
func fill() {
a := StructPartialA{
PrefilledInt: 5,
} //@codeactionedit("}", "refactor.rewrite", fill_struct_partial1)
} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_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)
} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_partial2)
}
-- @fill_struct_partial1/fill_struct_partial.go --
-- @fillStruct_partial1/fillStruct_partial.go --
@@ -16 +16,3 @@
- PrefilledInt: 5,
+ PrefilledInt: 5,
+ UnfilledInt: 0,
+ StructPartialB: StructPartialB{},
-- @fill_struct_partial2/fill_struct_partial.go --
-- @fillStruct_partial2/fillStruct_partial.go --
@@ -19,4 +19,2 @@
- /* this comment should disappear */
- PrefilledInt: 7, // This comment should be blown away.
@ -457,7 +457,7 @@ func fill() {
- this one */
+ PrefilledInt: 7,
+ UnfilledInt: 0,
-- fill_struct_spaces.go --
-- fillStruct_spaces.go --
package fillstruct
type StructD struct {
@ -465,16 +465,16 @@ type StructD struct {
}
func spaces() {
d := StructD{} //@codeactionedit("}", "refactor.rewrite", fill_struct_spaces)
d := StructD{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_spaces)
}
-- @fill_struct_spaces/fill_struct_spaces.go --
-- @fillStruct_spaces/fillStruct_spaces.go --
@@ -8 +8,3 @@
- d := StructD{} //@codeactionedit("}", "refactor.rewrite", fill_struct_spaces)
- d := StructD{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_spaces)
+ d := StructD{
+ ExportedIntField: 0,
+ } //@codeactionedit("}", "refactor.rewrite", fill_struct_spaces)
-- fill_struct_unsafe.go --
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_spaces)
-- fillStruct_unsafe.go --
package fillstruct
import "unsafe"
@ -485,16 +485,16 @@ type unsafeStruct struct {
}
func fill() {
_ := unsafeStruct{} //@codeactionedit("}", "refactor.rewrite", fill_struct_unsafe)
_ := unsafeStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_unsafe)
}
-- @fill_struct_unsafe/fill_struct_unsafe.go --
-- @fillStruct_unsafe/fillStruct_unsafe.go --
@@ -11 +11,4 @@
- _ := unsafeStruct{} //@codeactionedit("}", "refactor.rewrite", fill_struct_unsafe)
- _ := unsafeStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_unsafe)
+ _ := unsafeStruct{
+ x: 0,
+ p: nil,
+ } //@codeactionedit("}", "refactor.rewrite", fill_struct_unsafe)
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_unsafe)
-- typeparams.go --
package fillstruct
@ -506,59 +506,59 @@ type basicStructWithTypeParams[T any] struct {
foo T
}
var _ = basicStructWithTypeParams[int]{} //@codeactionedit("}", "refactor.rewrite", typeparams1)
var _ = basicStructWithTypeParams[int]{} //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams1)
type twoArgStructWithTypeParams[F, B any] struct {
foo F
bar B
}
var _ = twoArgStructWithTypeParams[string, int]{} //@codeactionedit("}", "refactor.rewrite", typeparams2)
var _ = twoArgStructWithTypeParams[string, int]{} //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams2)
var _ = twoArgStructWithTypeParams[int, string]{
bar: "bar",
} //@codeactionedit("}", "refactor.rewrite", typeparams3)
} //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams3)
type nestedStructWithTypeParams struct {
bar string
basic basicStructWithTypeParams[int]
}
var _ = nestedStructWithTypeParams{} //@codeactionedit("}", "refactor.rewrite", typeparams4)
var _ = nestedStructWithTypeParams{} //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams4)
func _[T any]() {
type S struct{ t T }
_ = S{} //@codeactionedit("}", "refactor.rewrite", typeparams5)
_ = S{} //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams5)
}
-- @typeparams1/typeparams.go --
@@ -11 +11,3 @@
-var _ = basicStructWithTypeParams[int]{} //@codeactionedit("}", "refactor.rewrite", typeparams1)
-var _ = basicStructWithTypeParams[int]{} //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams1)
+var _ = basicStructWithTypeParams[int]{
+ foo: 0,
+} //@codeactionedit("}", "refactor.rewrite", typeparams1)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams1)
-- @typeparams2/typeparams.go --
@@ -18 +18,4 @@
-var _ = twoArgStructWithTypeParams[string, int]{} //@codeactionedit("}", "refactor.rewrite", typeparams2)
-var _ = twoArgStructWithTypeParams[string, int]{} //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams2)
+var _ = twoArgStructWithTypeParams[string, int]{
+ foo: "",
+ bar: 0,
+} //@codeactionedit("}", "refactor.rewrite", typeparams2)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams2)
-- @typeparams3/typeparams.go --
@@ -21 +21 @@
+ foo: 0,
-- @typeparams4/typeparams.go --
@@ -29 +29,4 @@
-var _ = nestedStructWithTypeParams{} //@codeactionedit("}", "refactor.rewrite", typeparams4)
-var _ = nestedStructWithTypeParams{} //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams4)
+var _ = nestedStructWithTypeParams{
+ bar: "",
+ basic: basicStructWithTypeParams{},
+} //@codeactionedit("}", "refactor.rewrite", typeparams4)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams4)
-- @typeparams5/typeparams.go --
@@ -33 +33,3 @@
- _ = S{} //@codeactionedit("}", "refactor.rewrite", typeparams5)
- _ = S{} //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams5)
+ _ = S{
+ t: *new(T),
+ } //@codeactionedit("}", "refactor.rewrite", typeparams5)
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams5)
-- issue63921.go --
package fillstruct
@ -571,5 +571,5 @@ type invalidStruct struct {
func _() {
// Note: the golden content for issue63921 is empty: fillstruct produces no
// edits, but does not panic.
invalidStruct{} //@codeactionedit("}", "refactor.rewrite", issue63921)
invalidStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", issue63921)
}

Просмотреть файл

@ -39,49 +39,49 @@ type basicStruct struct {
foo int
}
var _ = basicStruct{} //@codeactionedit("}", "refactor.rewrite", a1)
var _ = basicStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a1)
type twoArgStruct struct {
foo int
bar string
}
var _ = twoArgStruct{} //@codeactionedit("}", "refactor.rewrite", a2)
var _ = twoArgStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a2)
type nestedStruct struct {
bar string
basic basicStruct
}
var _ = nestedStruct{} //@codeactionedit("}", "refactor.rewrite", a3)
var _ = nestedStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a3)
var _ = data.B{} //@codeactionedit("}", "refactor.rewrite", a4)
var _ = data.B{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a4)
-- @a1/a.go --
@@ -11 +11,3 @@
-var _ = basicStruct{} //@codeactionedit("}", "refactor.rewrite", a1)
-var _ = basicStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a1)
+var _ = basicStruct{
+ foo: 0,
+} //@codeactionedit("}", "refactor.rewrite", a1)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", a1)
-- @a2/a.go --
@@ -18 +18,4 @@
-var _ = twoArgStruct{} //@codeactionedit("}", "refactor.rewrite", a2)
-var _ = twoArgStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a2)
+var _ = twoArgStruct{
+ foo: 0,
+ bar: "",
+} //@codeactionedit("}", "refactor.rewrite", a2)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", a2)
-- @a3/a.go --
@@ -25 +25,4 @@
-var _ = nestedStruct{} //@codeactionedit("}", "refactor.rewrite", a3)
-var _ = nestedStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a3)
+var _ = nestedStruct{
+ bar: "",
+ basic: basicStruct{},
+} //@codeactionedit("}", "refactor.rewrite", a3)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", a3)
-- @a4/a.go --
@@ -27 +27,3 @@
-var _ = data.B{} //@codeactionedit("}", "refactor.rewrite", a4)
-var _ = data.B{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a4)
+var _ = data.B{
+ ExportedInt: 0,
+} //@codeactionedit("}", "refactor.rewrite", a4)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", a4)
-- a2.go --
package fillstruct
@ -93,57 +93,57 @@ type typedStruct struct {
a [2]string
}
var _ = typedStruct{} //@codeactionedit("}", "refactor.rewrite", a21)
var _ = typedStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a21)
type funStruct struct {
fn func(i int) int
}
var _ = funStruct{} //@codeactionedit("}", "refactor.rewrite", a22)
var _ = funStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a22)
type funStructComplex struct {
fn func(i int, s string) (string, int)
}
var _ = funStructComplex{} //@codeactionedit("}", "refactor.rewrite", a23)
var _ = funStructComplex{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a23)
type funStructEmpty struct {
fn func()
}
var _ = funStructEmpty{} //@codeactionedit("}", "refactor.rewrite", a24)
var _ = funStructEmpty{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a24)
-- @a21/a2.go --
@@ -11 +11,7 @@
-var _ = typedStruct{} //@codeactionedit("}", "refactor.rewrite", a21)
-var _ = typedStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a21)
+var _ = typedStruct{
+ m: map[string]int{},
+ s: []int{},
+ c: make(chan int),
+ c1: make(<-chan int),
+ a: [2]string{},
+} //@codeactionedit("}", "refactor.rewrite", a21)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", a21)
-- @a22/a2.go --
@@ -17 +17,4 @@
-var _ = funStruct{} //@codeactionedit("}", "refactor.rewrite", a22)
-var _ = funStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a22)
+var _ = funStruct{
+ fn: func(i int) int {
+ },
+} //@codeactionedit("}", "refactor.rewrite", a22)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", a22)
-- @a23/a2.go --
@@ -23 +23,4 @@
-var _ = funStructComplex{} //@codeactionedit("}", "refactor.rewrite", a23)
-var _ = funStructComplex{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a23)
+var _ = funStructComplex{
+ fn: func(i int, s string) (string, int) {
+ },
+} //@codeactionedit("}", "refactor.rewrite", a23)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", a23)
-- @a24/a2.go --
@@ -29 +29,4 @@
-var _ = funStructEmpty{} //@codeactionedit("}", "refactor.rewrite", a24)
-var _ = funStructEmpty{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a24)
+var _ = funStructEmpty{
+ fn: func() {
+ },
+} //@codeactionedit("}", "refactor.rewrite", a24)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", a24)
-- a3.go --
package fillstruct
@ -161,7 +161,7 @@ type Bar struct {
Y *Foo
}
var _ = Bar{} //@codeactionedit("}", "refactor.rewrite", a31)
var _ = Bar{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a31)
type importedStruct struct {
m map[*ast.CompositeLit]ast.Field
@ -172,7 +172,7 @@ type importedStruct struct {
st ast.CompositeLit
}
var _ = importedStruct{} //@codeactionedit("}", "refactor.rewrite", a32)
var _ = importedStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a32)
type pointerBuiltinStruct struct {
b *bool
@ -180,23 +180,23 @@ type pointerBuiltinStruct struct {
i *int
}
var _ = pointerBuiltinStruct{} //@codeactionedit("}", "refactor.rewrite", a33)
var _ = pointerBuiltinStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a33)
var _ = []ast.BasicLit{
{}, //@codeactionedit("}", "refactor.rewrite", a34)
{}, //@codeactionedit("}", "refactor.rewrite.fillStruct", a34)
}
var _ = []ast.BasicLit{{}} //@codeactionedit("}", "refactor.rewrite", a35)
var _ = []ast.BasicLit{{}} //@codeactionedit("}", "refactor.rewrite.fillStruct", a35)
-- @a31/a3.go --
@@ -17 +17,4 @@
-var _ = Bar{} //@codeactionedit("}", "refactor.rewrite", a31)
-var _ = Bar{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a31)
+var _ = Bar{
+ X: &Foo{},
+ Y: &Foo{},
+} //@codeactionedit("}", "refactor.rewrite", a31)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", a31)
-- @a32/a3.go --
@@ -28 +28,9 @@
-var _ = importedStruct{} //@codeactionedit("}", "refactor.rewrite", a32)
-var _ = importedStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a32)
+var _ = importedStruct{
+ m: map[*ast.CompositeLit]ast.Field{},
+ s: []ast.BadExpr{},
@ -205,31 +205,31 @@ var _ = []ast.BasicLit{{}} //@codeactionedit("}", "refactor.rewrite", a35)
+ fn: func(ast_decl ast.DeclStmt) ast.Ellipsis {
+ },
+ st: ast.CompositeLit{},
+} //@codeactionedit("}", "refactor.rewrite", a32)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", a32)
-- @a33/a3.go --
@@ -36 +36,5 @@
-var _ = pointerBuiltinStruct{} //@codeactionedit("}", "refactor.rewrite", a33)
-var _ = pointerBuiltinStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a33)
+var _ = pointerBuiltinStruct{
+ b: new(bool),
+ s: new(string),
+ i: new(int),
+} //@codeactionedit("}", "refactor.rewrite", a33)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", a33)
-- @a34/a3.go --
@@ -39 +39,5 @@
- {}, //@codeactionedit("}", "refactor.rewrite", a34)
- {}, //@codeactionedit("}", "refactor.rewrite.fillStruct", a34)
+ {
+ ValuePos: 0,
+ Kind: 0,
+ Value: "",
+ }, //@codeactionedit("}", "refactor.rewrite", a34)
+ }, //@codeactionedit("}", "refactor.rewrite.fillStruct", a34)
-- @a35/a3.go --
@@ -42 +42,5 @@
-var _ = []ast.BasicLit{{}} //@codeactionedit("}", "refactor.rewrite", a35)
-var _ = []ast.BasicLit{{}} //@codeactionedit("}", "refactor.rewrite.fillStruct", a35)
+var _ = []ast.BasicLit{{
+ ValuePos: 0,
+ Kind: 0,
+ Value: "",
+}} //@codeactionedit("}", "refactor.rewrite", a35)
+}} //@codeactionedit("}", "refactor.rewrite.fillStruct", a35)
-- a4.go --
package fillstruct
@ -255,49 +255,49 @@ type assignStruct struct {
func fill() {
var x int
var _ = iStruct{} //@codeactionedit("}", "refactor.rewrite", a41)
var _ = iStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a41)
var s string
var _ = sStruct{} //@codeactionedit("}", "refactor.rewrite", a42)
var _ = sStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a42)
var n int
_ = []int{}
if true {
arr := []int{1, 2}
}
var _ = multiFill{} //@codeactionedit("}", "refactor.rewrite", a43)
var _ = multiFill{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a43)
var node *ast.CompositeLit
var _ = assignStruct{} //@codeactionedit("}", "refactor.rewrite", a45)
var _ = assignStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a45)
}
-- @a41/a4.go --
@@ -25 +25,3 @@
- var _ = iStruct{} //@codeactionedit("}", "refactor.rewrite", a41)
- var _ = iStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a41)
+ var _ = iStruct{
+ X: x,
+ } //@codeactionedit("}", "refactor.rewrite", a41)
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", a41)
-- @a42/a4.go --
@@ -28 +28,3 @@
- var _ = sStruct{} //@codeactionedit("}", "refactor.rewrite", a42)
- var _ = sStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a42)
+ var _ = sStruct{
+ str: s,
+ } //@codeactionedit("}", "refactor.rewrite", a42)
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", a42)
-- @a43/a4.go --
@@ -35 +35,5 @@
- var _ = multiFill{} //@codeactionedit("}", "refactor.rewrite", a43)
- var _ = multiFill{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a43)
+ var _ = multiFill{
+ num: n,
+ strin: s,
+ arr: []int{},
+ } //@codeactionedit("}", "refactor.rewrite", a43)
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", a43)
-- @a45/a4.go --
@@ -38 +38,3 @@
- var _ = assignStruct{} //@codeactionedit("}", "refactor.rewrite", a45)
- var _ = assignStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", a45)
+ var _ = assignStruct{
+ n: node,
+ } //@codeactionedit("}", "refactor.rewrite", a45)
-- fill_struct.go --
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", a45)
-- fillStruct.go --
package fillstruct
type StructA struct {
@ -317,43 +317,43 @@ type StructA3 struct {
}
func fill() {
a := StructA{} //@codeactionedit("}", "refactor.rewrite", fill_struct1)
b := StructA2{} //@codeactionedit("}", "refactor.rewrite", fill_struct2)
c := StructA3{} //@codeactionedit("}", "refactor.rewrite", fill_struct3)
a := StructA{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct1)
b := StructA2{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct2)
c := StructA3{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct3)
if true {
_ = StructA3{} //@codeactionedit("}", "refactor.rewrite", fill_struct4)
_ = StructA3{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct4)
}
}
-- @fill_struct1/fill_struct.go --
-- @fillStruct1/fillStruct.go --
@@ -20 +20,7 @@
- a := StructA{} //@codeactionedit("}", "refactor.rewrite", fill_struct1)
- a := StructA{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct1)
+ a := StructA{
+ unexportedIntField: 0,
+ ExportedIntField: 0,
+ MapA: map[int]string{},
+ Array: []int{},
+ StructB: StructB{},
+ } //@codeactionedit("}", "refactor.rewrite", fill_struct1)
-- @fill_struct2/fill_struct.go --
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct1)
-- @fillStruct2/fillStruct.go --
@@ -21 +21,3 @@
- b := StructA2{} //@codeactionedit("}", "refactor.rewrite", fill_struct2)
- b := StructA2{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct2)
+ b := StructA2{
+ B: &StructB{},
+ } //@codeactionedit("}", "refactor.rewrite", fill_struct2)
-- @fill_struct3/fill_struct.go --
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct2)
-- @fillStruct3/fillStruct.go --
@@ -22 +22,3 @@
- c := StructA3{} //@codeactionedit("}", "refactor.rewrite", fill_struct3)
- c := StructA3{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct3)
+ c := StructA3{
+ B: StructB{},
+ } //@codeactionedit("}", "refactor.rewrite", fill_struct3)
-- @fill_struct4/fill_struct.go --
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct3)
-- @fillStruct4/fillStruct.go --
@@ -24 +24,3 @@
- _ = StructA3{} //@codeactionedit("}", "refactor.rewrite", fill_struct4)
- _ = StructA3{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct4)
+ _ = StructA3{
+ B: StructB{},
+ } //@codeactionedit("}", "refactor.rewrite", fill_struct4)
-- fill_struct_anon.go --
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct4)
-- fillStruct_anon.go --
package fillstruct
type StructAnon struct {
@ -366,17 +366,17 @@ type StructAnon struct {
}
func fill() {
_ := StructAnon{} //@codeactionedit("}", "refactor.rewrite", fill_struct_anon)
_ := StructAnon{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_anon)
}
-- @fill_struct_anon/fill_struct_anon.go --
-- @fillStruct_anon/fillStruct_anon.go --
@@ -13 +13,5 @@
- _ := StructAnon{} //@codeactionedit("}", "refactor.rewrite", fill_struct_anon)
- _ := StructAnon{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_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 --
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_anon)
-- fillStruct_nested.go --
package fillstruct
type StructB struct {
@ -389,17 +389,17 @@ type StructC struct {
func nested() {
c := StructB{
StructC: StructC{}, //@codeactionedit("}", "refactor.rewrite", fill_nested)
StructC: StructC{}, //@codeactionedit("}", "refactor.rewrite.fillStruct", fill_nested)
}
}
-- @fill_nested/fill_struct_nested.go --
-- @fill_nested/fillStruct_nested.go --
@@ -13 +13,3 @@
- StructC: StructC{}, //@codeactionedit("}", "refactor.rewrite", fill_nested)
- StructC: StructC{}, //@codeactionedit("}", "refactor.rewrite.fillStruct", fill_nested)
+ StructC: StructC{
+ unexportedInt: 0,
+ }, //@codeactionedit("}", "refactor.rewrite", fill_nested)
-- fill_struct_package.go --
+ }, //@codeactionedit("}", "refactor.rewrite.fillStruct", fill_nested)
-- fillStruct_package.go --
package fillstruct
import (
@ -409,26 +409,26 @@ import (
)
func unexported() {
a := data.B{} //@codeactionedit("}", "refactor.rewrite", fill_struct_package1)
_ = h2.Client{} //@codeactionedit("}", "refactor.rewrite", fill_struct_package2)
a := data.B{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_package1)
_ = h2.Client{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_package2)
}
-- @fill_struct_package1/fill_struct_package.go --
-- @fillStruct_package1/fillStruct_package.go --
@@ -10 +10,3 @@
- a := data.B{} //@codeactionedit("}", "refactor.rewrite", fill_struct_package1)
- a := data.B{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_package1)
+ a := data.B{
+ ExportedInt: 0,
+ } //@codeactionedit("}", "refactor.rewrite", fill_struct_package1)
-- @fill_struct_package2/fill_struct_package.go --
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_package1)
-- @fillStruct_package2/fillStruct_package.go --
@@ -11 +11,7 @@
- _ = h2.Client{} //@codeactionedit("}", "refactor.rewrite", fill_struct_package2)
- _ = h2.Client{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_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 --
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_package2)
-- fillStruct_partial.go --
package fillstruct
type StructPartialA struct {
@ -445,22 +445,22 @@ type StructPartialB struct {
func fill() {
a := StructPartialA{
PrefilledInt: 5,
} //@codeactionedit("}", "refactor.rewrite", fill_struct_partial1)
} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_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)
} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_partial2)
}
-- @fill_struct_partial1/fill_struct_partial.go --
-- @fillStruct_partial1/fillStruct_partial.go --
@@ -16 +16,3 @@
- PrefilledInt: 5,
+ PrefilledInt: 5,
+ UnfilledInt: 0,
+ StructPartialB: StructPartialB{},
-- @fill_struct_partial2/fill_struct_partial.go --
-- @fillStruct_partial2/fillStruct_partial.go --
@@ -19,4 +19,2 @@
- /* this comment should disappear */
- PrefilledInt: 7, // This comment should be blown away.
@ -468,7 +468,7 @@ func fill() {
- this one */
+ PrefilledInt: 7,
+ UnfilledInt: 0,
-- fill_struct_spaces.go --
-- fillStruct_spaces.go --
package fillstruct
type StructD struct {
@ -476,16 +476,16 @@ type StructD struct {
}
func spaces() {
d := StructD{} //@codeactionedit("}", "refactor.rewrite", fill_struct_spaces)
d := StructD{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_spaces)
}
-- @fill_struct_spaces/fill_struct_spaces.go --
-- @fillStruct_spaces/fillStruct_spaces.go --
@@ -8 +8,3 @@
- d := StructD{} //@codeactionedit("}", "refactor.rewrite", fill_struct_spaces)
- d := StructD{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_spaces)
+ d := StructD{
+ ExportedIntField: 0,
+ } //@codeactionedit("}", "refactor.rewrite", fill_struct_spaces)
-- fill_struct_unsafe.go --
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_spaces)
-- fillStruct_unsafe.go --
package fillstruct
import "unsafe"
@ -496,16 +496,16 @@ type unsafeStruct struct {
}
func fill() {
_ := unsafeStruct{} //@codeactionedit("}", "refactor.rewrite", fill_struct_unsafe)
_ := unsafeStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_unsafe)
}
-- @fill_struct_unsafe/fill_struct_unsafe.go --
-- @fillStruct_unsafe/fillStruct_unsafe.go --
@@ -11 +11,4 @@
- _ := unsafeStruct{} //@codeactionedit("}", "refactor.rewrite", fill_struct_unsafe)
- _ := unsafeStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_unsafe)
+ _ := unsafeStruct{
+ x: 0,
+ p: nil,
+ } //@codeactionedit("}", "refactor.rewrite", fill_struct_unsafe)
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", fillStruct_unsafe)
-- typeparams.go --
package fillstruct
@ -517,59 +517,59 @@ type basicStructWithTypeParams[T any] struct {
foo T
}
var _ = basicStructWithTypeParams[int]{} //@codeactionedit("}", "refactor.rewrite", typeparams1)
var _ = basicStructWithTypeParams[int]{} //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams1)
type twoArgStructWithTypeParams[F, B any] struct {
foo F
bar B
}
var _ = twoArgStructWithTypeParams[string, int]{} //@codeactionedit("}", "refactor.rewrite", typeparams2)
var _ = twoArgStructWithTypeParams[string, int]{} //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams2)
var _ = twoArgStructWithTypeParams[int, string]{
bar: "bar",
} //@codeactionedit("}", "refactor.rewrite", typeparams3)
} //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams3)
type nestedStructWithTypeParams struct {
bar string
basic basicStructWithTypeParams[int]
}
var _ = nestedStructWithTypeParams{} //@codeactionedit("}", "refactor.rewrite", typeparams4)
var _ = nestedStructWithTypeParams{} //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams4)
func _[T any]() {
type S struct{ t T }
_ = S{} //@codeactionedit("}", "refactor.rewrite", typeparams5)
_ = S{} //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams5)
}
-- @typeparams1/typeparams.go --
@@ -11 +11,3 @@
-var _ = basicStructWithTypeParams[int]{} //@codeactionedit("}", "refactor.rewrite", typeparams1)
-var _ = basicStructWithTypeParams[int]{} //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams1)
+var _ = basicStructWithTypeParams[int]{
+ foo: 0,
+} //@codeactionedit("}", "refactor.rewrite", typeparams1)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams1)
-- @typeparams2/typeparams.go --
@@ -18 +18,4 @@
-var _ = twoArgStructWithTypeParams[string, int]{} //@codeactionedit("}", "refactor.rewrite", typeparams2)
-var _ = twoArgStructWithTypeParams[string, int]{} //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams2)
+var _ = twoArgStructWithTypeParams[string, int]{
+ foo: "",
+ bar: 0,
+} //@codeactionedit("}", "refactor.rewrite", typeparams2)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams2)
-- @typeparams3/typeparams.go --
@@ -21 +21 @@
+ foo: 0,
-- @typeparams4/typeparams.go --
@@ -29 +29,4 @@
-var _ = nestedStructWithTypeParams{} //@codeactionedit("}", "refactor.rewrite", typeparams4)
-var _ = nestedStructWithTypeParams{} //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams4)
+var _ = nestedStructWithTypeParams{
+ bar: "",
+ basic: basicStructWithTypeParams{},
+} //@codeactionedit("}", "refactor.rewrite", typeparams4)
+} //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams4)
-- @typeparams5/typeparams.go --
@@ -33 +33,3 @@
- _ = S{} //@codeactionedit("}", "refactor.rewrite", typeparams5)
- _ = S{} //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams5)
+ _ = S{
+ t: *new(T),
+ } //@codeactionedit("}", "refactor.rewrite", typeparams5)
+ } //@codeactionedit("}", "refactor.rewrite.fillStruct", typeparams5)
-- issue63921.go --
package fillstruct
@ -582,5 +582,5 @@ type invalidStruct struct {
func _() {
// Note: the golden content for issue63921 is empty: fillstruct produces no
// edits, but does not panic.
invalidStruct{} //@codeactionedit("}", "refactor.rewrite", issue63921)
invalidStruct{} //@codeactionedit("}", "refactor.rewrite.fillStruct", issue63921)
}

Просмотреть файл

@ -50,19 +50,19 @@ func (notificationTwo) isNotification() {}
func doSwitch() {
var b data.TypeB
switch b {
case data.TypeBOne: //@codeactionedit(":", "refactor.rewrite", a1)
case data.TypeBOne: //@codeactionedit(":", "refactor.rewrite.fillSwitch", a1)
}
var a typeA
switch a {
case typeAThree: //@codeactionedit(":", "refactor.rewrite", a2)
case typeAThree: //@codeactionedit(":", "refactor.rewrite.fillSwitch", a2)
}
var n notification
switch n.(type) { //@codeactionedit("{", "refactor.rewrite", a3)
switch n.(type) { //@codeactionedit("{", "refactor.rewrite.fillSwitch", a3)
}
switch nt := n.(type) { //@codeactionedit("{", "refactor.rewrite", a4)
switch nt := n.(type) { //@codeactionedit("{", "refactor.rewrite.fillSwitch", a4)
}
var s struct {
@ -70,7 +70,7 @@ func doSwitch() {
}
switch s.a {
case typeAThree: //@codeactionedit(":", "refactor.rewrite", a5)
case typeAThree: //@codeactionedit(":", "refactor.rewrite.fillSwitch", a5)
}
}
-- @a1/a.go --

Просмотреть файл

@ -61,19 +61,19 @@ func (notificationTwo) isNotification() {}
func doSwitch() {
var b data.TypeB
switch b {
case data.TypeBOne: //@codeactionedit(":", "refactor.rewrite", a1)
case data.TypeBOne: //@codeactionedit(":", "refactor.rewrite.fillSwitch", a1)
}
var a typeA
switch a {
case typeAThree: //@codeactionedit(":", "refactor.rewrite", a2)
case typeAThree: //@codeactionedit(":", "refactor.rewrite.fillSwitch", a2)
}
var n notification
switch n.(type) { //@codeactionedit("{", "refactor.rewrite", a3)
switch n.(type) { //@codeactionedit("{", "refactor.rewrite.fillSwitch", a3)
}
switch nt := n.(type) { //@codeactionedit("{", "refactor.rewrite", a4)
switch nt := n.(type) { //@codeactionedit("{", "refactor.rewrite.fillSwitch", a4)
}
var s struct {
@ -81,7 +81,7 @@ func doSwitch() {
}
switch s.a {
case typeAThree: //@codeactionedit(":", "refactor.rewrite", a5)
case typeAThree: //@codeactionedit(":", "refactor.rewrite.fillSwitch", a5)
}
}
-- @a1/a.go --

Просмотреть файл

@ -8,16 +8,16 @@ go 1.18
-- basic.go --
package extract
func _() { //@codeaction("{", closeBracket, "refactor.extract", outer)
a := 1 //@codeaction("a", end, "refactor.extract", inner)
func _() { //@codeaction("{", closeBracket, "refactor.extract.function", outer)
a := 1 //@codeaction("a", end, "refactor.extract.function", inner)
_ = a + 4 //@loc(end, "4")
} //@loc(closeBracket, "}")
-- @inner/basic.go --
package extract
func _() { //@codeaction("{", closeBracket, "refactor.extract", outer)
//@codeaction("a", end, "refactor.extract", inner)
func _() { //@codeaction("{", closeBracket, "refactor.extract.function", outer)
//@codeaction("a", end, "refactor.extract.function", inner)
newFunction() //@loc(end, "4")
}
@ -29,8 +29,8 @@ func newFunction() {
-- @outer/basic.go --
package extract
func _() { //@codeaction("{", closeBracket, "refactor.extract", outer)
//@codeaction("a", end, "refactor.extract", inner)
func _() { //@codeaction("{", closeBracket, "refactor.extract.function", outer)
//@codeaction("a", end, "refactor.extract.function", inner)
newFunction() //@loc(end, "4")
}
@ -44,7 +44,7 @@ package extract
func _() bool {
x := 1
if x == 0 { //@codeaction("if", ifend, "refactor.extract", return)
if x == 0 { //@codeaction("if", ifend, "refactor.extract.function", return)
return true
} //@loc(ifend, "}")
return false
@ -55,7 +55,7 @@ package extract
func _() bool {
x := 1
//@codeaction("if", ifend, "refactor.extract", return)
//@codeaction("if", ifend, "refactor.extract.function", return)
shouldReturn, returnValue := newFunction(x)
if shouldReturn {
return returnValue
@ -74,7 +74,7 @@ func newFunction(x int) (bool, bool) {
package extract
func _() bool {
x := 1 //@codeaction("x", rnnEnd, "refactor.extract", rnn)
x := 1 //@codeaction("x", rnnEnd, "refactor.extract.function", rnn)
if x == 0 {
return true
}
@ -85,7 +85,7 @@ func _() bool {
package extract
func _() bool {
//@codeaction("x", rnnEnd, "refactor.extract", rnn)
//@codeaction("x", rnnEnd, "refactor.extract.function", rnn)
return newFunction() //@loc(rnnEnd, "false")
}
@ -105,7 +105,7 @@ import "fmt"
func _() (int, string, error) {
x := 1
y := "hello"
z := "bye" //@codeaction("z", rcEnd, "refactor.extract", rc)
z := "bye" //@codeaction("z", rcEnd, "refactor.extract.function", rc)
if y == z {
return x, y, fmt.Errorf("same")
} else if false {
@ -123,7 +123,7 @@ import "fmt"
func _() (int, string, error) {
x := 1
y := "hello"
//@codeaction("z", rcEnd, "refactor.extract", rc)
//@codeaction("z", rcEnd, "refactor.extract.function", rc)
z, shouldReturn, returnValue, returnValue1, returnValue2 := newFunction(y, x)
if shouldReturn {
return returnValue, returnValue1, returnValue2
@ -150,7 +150,7 @@ import "fmt"
func _() (int, string, error) {
x := 1
y := "hello"
z := "bye" //@codeaction("z", rcnnEnd, "refactor.extract", rcnn)
z := "bye" //@codeaction("z", rcnnEnd, "refactor.extract.function", rcnn)
if y == z {
return x, y, fmt.Errorf("same")
} else if false {
@ -168,7 +168,7 @@ import "fmt"
func _() (int, string, error) {
x := 1
y := "hello"
//@codeaction("z", rcnnEnd, "refactor.extract", rcnn)
//@codeaction("z", rcnnEnd, "refactor.extract.function", rcnn)
return newFunction(y, x) //@loc(rcnnEnd, "nil")
}
@ -190,7 +190,7 @@ import "go/ast"
func _() {
ast.Inspect(ast.NewIdent("a"), func(n ast.Node) bool {
if n == nil { //@codeaction("if", rflEnd, "refactor.extract", rfl)
if n == nil { //@codeaction("if", rflEnd, "refactor.extract.function", rfl)
return true
} //@loc(rflEnd, "}")
return false
@ -204,7 +204,7 @@ import "go/ast"
func _() {
ast.Inspect(ast.NewIdent("a"), func(n ast.Node) bool {
//@codeaction("if", rflEnd, "refactor.extract", rfl)
//@codeaction("if", rflEnd, "refactor.extract.function", rfl)
shouldReturn, returnValue := newFunction(n)
if shouldReturn {
return returnValue
@ -227,7 +227,7 @@ import "go/ast"
func _() {
ast.Inspect(ast.NewIdent("a"), func(n ast.Node) bool {
if n == nil { //@codeaction("if", rflnnEnd, "refactor.extract", rflnn)
if n == nil { //@codeaction("if", rflnnEnd, "refactor.extract.function", rflnn)
return true
}
return false //@loc(rflnnEnd, "false")
@ -241,7 +241,7 @@ import "go/ast"
func _() {
ast.Inspect(ast.NewIdent("a"), func(n ast.Node) bool {
//@codeaction("if", rflnnEnd, "refactor.extract", rflnn)
//@codeaction("if", rflnnEnd, "refactor.extract.function", rflnn)
return newFunction(n) //@loc(rflnnEnd, "false")
})
}
@ -258,7 +258,7 @@ package extract
func _() string {
x := 1
if x == 0 { //@codeaction("if", riEnd, "refactor.extract", ri)
if x == 0 { //@codeaction("if", riEnd, "refactor.extract.function", ri)
x = 3
return "a"
} //@loc(riEnd, "}")
@ -271,7 +271,7 @@ package extract
func _() string {
x := 1
//@codeaction("if", riEnd, "refactor.extract", ri)
//@codeaction("if", riEnd, "refactor.extract.function", ri)
shouldReturn, returnValue := newFunction(x)
if shouldReturn {
return returnValue
@ -293,7 +293,7 @@ package extract
func _() string {
x := 1
if x == 0 { //@codeaction("if", rinnEnd, "refactor.extract", rinn)
if x == 0 { //@codeaction("if", rinnEnd, "refactor.extract.function", rinn)
x = 3
return "a"
}
@ -306,7 +306,7 @@ package extract
func _() string {
x := 1
//@codeaction("if", rinnEnd, "refactor.extract", rinn)
//@codeaction("if", rinnEnd, "refactor.extract.function", rinn)
return newFunction(x) //@loc(rinnEnd, "\"b\"")
}
@ -324,10 +324,10 @@ package extract
func _() {
a := 1
a = 5 //@codeaction("a", araend, "refactor.extract", ara)
a = 5 //@codeaction("a", araend, "refactor.extract.function", ara)
a = a + 2 //@loc(araend, "2")
b := a * 2 //@codeaction("b", arbend, "refactor.extract", arb)
b := a * 2 //@codeaction("b", arbend, "refactor.extract.function", arb)
_ = b + 4 //@loc(arbend, "4")
}
@ -336,10 +336,10 @@ package extract
func _() {
a := 1
//@codeaction("a", araend, "refactor.extract", ara)
//@codeaction("a", araend, "refactor.extract.function", ara)
a = newFunction(a) //@loc(araend, "2")
b := a * 2 //@codeaction("b", arbend, "refactor.extract", arb)
b := a * 2 //@codeaction("b", arbend, "refactor.extract.function", arb)
_ = b + 4 //@loc(arbend, "4")
}
@ -354,10 +354,10 @@ package extract
func _() {
a := 1
a = 5 //@codeaction("a", araend, "refactor.extract", ara)
a = 5 //@codeaction("a", araend, "refactor.extract.function", ara)
a = a + 2 //@loc(araend, "2")
//@codeaction("b", arbend, "refactor.extract", arb)
//@codeaction("b", arbend, "refactor.extract.function", arb)
newFunction(a) //@loc(arbend, "4")
}
@ -371,7 +371,7 @@ package extract
func _() {
newFunction := 1
a := newFunction //@codeaction("a", "newFunction", "refactor.extract", scope)
a := newFunction //@codeaction("a", "newFunction", "refactor.extract.function", scope)
_ = a // avoid diagnostic
}
@ -384,7 +384,7 @@ package extract
func _() {
newFunction := 1
a := newFunction2(newFunction) //@codeaction("a", "newFunction", "refactor.extract", scope)
a := newFunction2(newFunction) //@codeaction("a", "newFunction", "refactor.extract.function", scope)
_ = a // avoid diagnostic
}
@ -402,7 +402,7 @@ package extract
func _() {
var a []int
a = append(a, 2) //@codeaction("a", siEnd, "refactor.extract", si)
a = append(a, 2) //@codeaction("a", siEnd, "refactor.extract.function", si)
b := 4 //@loc(siEnd, "4")
a = append(a, b)
}
@ -412,7 +412,7 @@ package extract
func _() {
var a []int
//@codeaction("a", siEnd, "refactor.extract", si)
//@codeaction("a", siEnd, "refactor.extract.function", si)
a, b := newFunction(a) //@loc(siEnd, "4")
a = append(a, b)
}
@ -429,7 +429,7 @@ package extract
func _() {
var b []int
var a int
a = 2 //@codeaction("a", srEnd, "refactor.extract", sr)
a = 2 //@codeaction("a", srEnd, "refactor.extract.function", sr)
b = []int{}
b = append(b, a) //@loc(srEnd, ")")
b[0] = 1
@ -441,7 +441,7 @@ package extract
func _() {
var b []int
var a int
//@codeaction("a", srEnd, "refactor.extract", sr)
//@codeaction("a", srEnd, "refactor.extract.function", sr)
b = newFunction(a, b) //@loc(srEnd, ")")
b[0] = 1
}
@ -458,7 +458,7 @@ package extract
func _() {
var b []int
a := 2 //@codeaction("a", upEnd, "refactor.extract", up)
a := 2 //@codeaction("a", upEnd, "refactor.extract.function", up)
b = []int{}
b = append(b, a) //@loc(upEnd, ")")
b[0] = 1
@ -472,7 +472,7 @@ package extract
func _() {
var b []int
//@codeaction("a", upEnd, "refactor.extract", up)
//@codeaction("a", upEnd, "refactor.extract.function", up)
a, b := newFunction(b) //@loc(upEnd, ")")
b[0] = 1
if a == 2 {
@ -491,9 +491,9 @@ func newFunction(b []int) (int, []int) {
package extract
func _() {
a := /* comment in the middle of a line */ 1 //@codeaction("a", commentEnd, "refactor.extract", comment1)
// Comment on its own line //@codeaction("Comment", commentEnd, "refactor.extract", comment2)
_ = a + 4 //@loc(commentEnd, "4"),codeaction("_", lastComment, "refactor.extract", comment3)
a := /* comment in the middle of a line */ 1 //@codeaction("a", commentEnd, "refactor.extract.function", comment1)
// Comment on its own line //@codeaction("Comment", commentEnd, "refactor.extract.function", comment2)
_ = a + 4 //@loc(commentEnd, "4"),codeaction("_", lastComment, "refactor.extract.function", comment3)
// Comment right after 3 + 4
// Comment after with space //@loc(lastComment, "Comment")
@ -504,9 +504,9 @@ package extract
func _() {
/* comment in the middle of a line */
//@codeaction("a", commentEnd, "refactor.extract", comment1)
// Comment on its own line //@codeaction("Comment", commentEnd, "refactor.extract", comment2)
newFunction() //@loc(commentEnd, "4"),codeaction("_", lastComment, "refactor.extract", comment3)
//@codeaction("a", commentEnd, "refactor.extract.function", comment1)
// Comment on its own line //@codeaction("Comment", commentEnd, "refactor.extract.function", comment2)
newFunction() //@loc(commentEnd, "4"),codeaction("_", lastComment, "refactor.extract.function", comment3)
// Comment right after 3 + 4
// Comment after with space //@loc(lastComment, "Comment")
@ -522,9 +522,9 @@ func newFunction() {
package extract
func _() {
a := /* comment in the middle of a line */ 1 //@codeaction("a", commentEnd, "refactor.extract", comment1)
// Comment on its own line //@codeaction("Comment", commentEnd, "refactor.extract", comment2)
newFunction(a) //@loc(commentEnd, "4"),codeaction("_", lastComment, "refactor.extract", comment3)
a := /* comment in the middle of a line */ 1 //@codeaction("a", commentEnd, "refactor.extract.function", comment1)
// Comment on its own line //@codeaction("Comment", commentEnd, "refactor.extract.function", comment2)
newFunction(a) //@loc(commentEnd, "4"),codeaction("_", lastComment, "refactor.extract.function", comment3)
// Comment right after 3 + 4
// Comment after with space //@loc(lastComment, "Comment")
@ -538,9 +538,9 @@ func newFunction(a int) {
package extract
func _() {
a := /* comment in the middle of a line */ 1 //@codeaction("a", commentEnd, "refactor.extract", comment1)
// Comment on its own line //@codeaction("Comment", commentEnd, "refactor.extract", comment2)
newFunction(a) //@loc(commentEnd, "4"),codeaction("_", lastComment, "refactor.extract", comment3)
a := /* comment in the middle of a line */ 1 //@codeaction("a", commentEnd, "refactor.extract.function", comment1)
// Comment on its own line //@codeaction("Comment", commentEnd, "refactor.extract.function", comment2)
newFunction(a) //@loc(commentEnd, "4"),codeaction("_", lastComment, "refactor.extract.function", comment3)
// Comment right after 3 + 4
// Comment after with space //@loc(lastComment, "Comment")
@ -557,7 +557,7 @@ import "strconv"
func _() {
i, err := strconv.Atoi("1")
u, err := strconv.Atoi("2") //@codeaction("u", ")", "refactor.extract", redefine)
u, err := strconv.Atoi("2") //@codeaction("u", ")", "refactor.extract.function", redefine)
if i == u || err == nil {
return
}
@ -570,7 +570,7 @@ import "strconv"
func _() {
i, err := strconv.Atoi("1")
u, err := newFunction() //@codeaction("u", ")", "refactor.extract", redefine)
u, err := newFunction() //@codeaction("u", ")", "refactor.extract.function", redefine)
if i == u || err == nil {
return
}

Просмотреть файл

@ -12,7 +12,7 @@ package extract
import "fmt"
func main() {
x := []rune{} //@codeaction("x", end, "refactor.extract", ext)
x := []rune{} //@codeaction("x", end, "refactor.extract.function", ext)
s := "HELLO"
for _, c := range s {
x = append(x, c)
@ -26,7 +26,7 @@ package extract
import "fmt"
func main() {
//@codeaction("x", end, "refactor.extract", ext)
//@codeaction("x", end, "refactor.extract.function", ext)
x := newFunction() //@loc(end, "}")
fmt.Printf("%x\n", x)
}

Просмотреть файл

@ -12,7 +12,7 @@ package func_arg
func A(
a string,
b, c int64,
x int /*@codeaction("x", "x", "refactor.rewrite", func_arg)*/,
x int /*@codeaction("x", "x", "refactor.rewrite.joinLines", func_arg)*/,
y int,
) (r1 string, r2, r3 int64, r4 int, r5 int) {
return a, b, c, x, y
@ -21,7 +21,7 @@ func A(
-- @func_arg/func_arg/func_arg.go --
package func_arg
func A(a string, b, c int64, x int /*@codeaction("x", "x", "refactor.rewrite", func_arg)*/, y int) (r1 string, r2, r3 int64, r4 int, r5 int) {
func A(a string, b, c int64, x int /*@codeaction("x", "x", "refactor.rewrite.joinLines", func_arg)*/, y int) (r1 string, r2, r3 int64, r4 int, r5 int) {
return a, b, c, x, y
}
@ -29,7 +29,7 @@ func A(a string, b, c int64, x int /*@codeaction("x", "x", "refactor.rewrite", f
package func_ret
func A(a string, b, c int64, x int, y int) (
r1 string /*@codeaction("r1", "r1", "refactor.rewrite", func_ret)*/,
r1 string /*@codeaction("r1", "r1", "refactor.rewrite.joinLines", func_ret)*/,
r2, r3 int64,
r4 int,
r5 int,
@ -40,7 +40,7 @@ func A(a string, b, c int64, x int, y int) (
-- @func_ret/func_ret/func_ret.go --
package func_ret
func A(a string, b, c int64, x int, y int) (r1 string /*@codeaction("r1", "r1", "refactor.rewrite", func_ret)*/, r2, r3 int64, r4 int, r5 int) {
func A(a string, b, c int64, x int, y int) (r1 string /*@codeaction("r1", "r1", "refactor.rewrite.joinLines", func_ret)*/, r2, r3 int64, r4 int, r5 int) {
return a, b, c, x, y
}
@ -50,20 +50,20 @@ package functype_arg
type A func(
a string,
b, c int64,
x int /*@codeaction("x", "x", "refactor.rewrite", functype_arg)*/,
x int /*@codeaction("x", "x", "refactor.rewrite.joinLines", functype_arg)*/,
y int,
) (r1 string, r2, r3 int64, r4 int, r5 int)
-- @functype_arg/functype_arg/functype_arg.go --
package functype_arg
type A func(a string, b, c int64, x int /*@codeaction("x", "x", "refactor.rewrite", functype_arg)*/, y int) (r1 string, r2, r3 int64, r4 int, r5 int)
type A func(a string, b, c int64, x int /*@codeaction("x", "x", "refactor.rewrite.joinLines", functype_arg)*/, y int) (r1 string, r2, r3 int64, r4 int, r5 int)
-- functype_ret/functype_ret.go --
package functype_ret
type A func(a string, b, c int64, x int, y int) (
r1 string /*@codeaction("r1", "r1", "refactor.rewrite", functype_ret)*/,
r1 string /*@codeaction("r1", "r1", "refactor.rewrite.joinLines", functype_ret)*/,
r2, r3 int64,
r4 int,
r5 int,
@ -72,7 +72,7 @@ type A func(a string, b, c int64, x int, y int) (
-- @functype_ret/functype_ret/functype_ret.go --
package functype_ret
type A func(a string, b, c int64, x int, y int) (r1 string /*@codeaction("r1", "r1", "refactor.rewrite", functype_ret)*/, r2, r3 int64, r4 int, r5 int)
type A func(a string, b, c int64, x int, y int) (r1 string /*@codeaction("r1", "r1", "refactor.rewrite.joinLines", functype_ret)*/, r2, r3 int64, r4 int, r5 int)
-- func_call/func_call.go --
package func_call
@ -81,7 +81,7 @@ import "fmt"
func a() {
fmt.Println(
1 /*@codeaction("1", "1", "refactor.rewrite", func_call)*/,
1 /*@codeaction("1", "1", "refactor.rewrite.joinLines", func_call)*/,
2,
3,
fmt.Sprintf("hello %d", 4),
@ -94,7 +94,7 @@ package func_call
import "fmt"
func a() {
fmt.Println(1 /*@codeaction("1", "1", "refactor.rewrite", func_call)*/, 2, 3, fmt.Sprintf("hello %d", 4))
fmt.Println(1 /*@codeaction("1", "1", "refactor.rewrite.joinLines", func_call)*/, 2, 3, fmt.Sprintf("hello %d", 4))
}
-- indent/indent.go --
@ -108,7 +108,7 @@ func a() {
2,
3,
fmt.Sprintf(
"hello %d" /*@codeaction("hello", "hello", "refactor.rewrite", indent, "Join arguments into one line")*/,
"hello %d" /*@codeaction("hello", "hello", "refactor.rewrite.joinLines", indent)*/,
4,
))
}
@ -123,7 +123,7 @@ func a() {
1,
2,
3,
fmt.Sprintf("hello %d" /*@codeaction("hello", "hello", "refactor.rewrite", indent, "Join arguments into one line")*/, 4))
fmt.Sprintf("hello %d" /*@codeaction("hello", "hello", "refactor.rewrite.joinLines", indent)*/, 4))
}
-- structelts/structelts.go --
@ -137,7 +137,7 @@ type A struct{
func a() {
_ = A{
a: 1,
b: 2 /*@codeaction("b", "b", "refactor.rewrite", structelts)*/,
b: 2 /*@codeaction("b", "b", "refactor.rewrite.joinLines", structelts)*/,
}
}
@ -150,7 +150,7 @@ type A struct{
}
func a() {
_ = A{a: 1, b: 2 /*@codeaction("b", "b", "refactor.rewrite", structelts)*/}
_ = A{a: 1, b: 2 /*@codeaction("b", "b", "refactor.rewrite.joinLines", structelts)*/}
}
-- sliceelts/sliceelts.go --
@ -158,7 +158,7 @@ package sliceelts
func a() {
_ = []int{
1 /*@codeaction("1", "1", "refactor.rewrite", sliceelts)*/,
1 /*@codeaction("1", "1", "refactor.rewrite.joinLines", sliceelts)*/,
2,
}
}
@ -167,7 +167,7 @@ func a() {
package sliceelts
func a() {
_ = []int{1 /*@codeaction("1", "1", "refactor.rewrite", sliceelts)*/, 2}
_ = []int{1 /*@codeaction("1", "1", "refactor.rewrite.joinLines", sliceelts)*/, 2}
}
-- mapelts/mapelts.go --
@ -175,7 +175,7 @@ package mapelts
func a() {
_ = map[string]int{
"a": 1 /*@codeaction("1", "1", "refactor.rewrite", mapelts)*/,
"a": 1 /*@codeaction("1", "1", "refactor.rewrite.joinLines", mapelts)*/,
"b": 2,
}
}
@ -184,14 +184,14 @@ func a() {
package mapelts
func a() {
_ = map[string]int{"a": 1 /*@codeaction("1", "1", "refactor.rewrite", mapelts)*/, "b": 2}
_ = map[string]int{"a": 1 /*@codeaction("1", "1", "refactor.rewrite.joinLines", mapelts)*/, "b": 2}
}
-- starcomment/starcomment.go --
package starcomment
func A(
/*1*/ x /*2*/ string /*3*/ /*@codeaction("x", "x", "refactor.rewrite", starcomment)*/,
/*1*/ x /*2*/ string /*3*/ /*@codeaction("x", "x", "refactor.rewrite.joinLines", starcomment)*/,
/*4*/ y /*5*/ int /*6*/,
) (string, int) {
return x, y
@ -200,7 +200,7 @@ func A(
-- @starcomment/starcomment/starcomment.go --
package starcomment
func A(/*1*/ x /*2*/ string /*3*/ /*@codeaction("x", "x", "refactor.rewrite", starcomment)*/, /*4*/ y /*5*/ int /*6*/) (string, int) {
func A(/*1*/ x /*2*/ string /*3*/ /*@codeaction("x", "x", "refactor.rewrite.joinLines", starcomment)*/, /*4*/ y /*5*/ int /*6*/) (string, int) {
return x, y
}

Просмотреть файл

@ -1,4 +1,4 @@
This is a minimal test of the refactor.inline code action, without resolve support.
This is a minimal test of the refactor.inline.call code action, without resolve support.
See inline_resolve.txt for same test with resolve support.
-- go.mod --
@ -9,7 +9,7 @@ go 1.18
package a
func _() {
println(add(1, 2)) //@codeaction("add", ")", "refactor.inline", inline)
println(add(1, 2)) //@codeaction("add", ")", "refactor.inline.call", inline)
}
func add(x, y int) int { return x + y }
@ -18,7 +18,7 @@ func add(x, y int) int { return x + y }
package a
func _() {
println(1 + 2) //@codeaction("add", ")", "refactor.inline", inline)
println(1 + 2) //@codeaction("add", ")", "refactor.inline.call", inline)
}
func add(x, y int) int { return x + y }

Просмотреть файл

@ -1,4 +1,4 @@
This is a minimal test of the refactor.inline code actions, with resolve support.
This is a minimal test of the refactor.inline.call code actions, with resolve support.
See inline.txt for same test without resolve support.
-- capabilities.json --
@ -20,7 +20,7 @@ go 1.18
package a
func _() {
println(add(1, 2)) //@codeaction("add", ")", "refactor.inline", inline)
println(add(1, 2)) //@codeaction("add", ")", "refactor.inline.call", inline)
}
func add(x, y int) int { return x + y }
@ -29,7 +29,7 @@ func add(x, y int) int { return x + y }
package a
func _() {
println(1 + 2) //@codeaction("add", ")", "refactor.inline", inline)
println(1 + 2) //@codeaction("add", ")", "refactor.inline.call", inline)
}
func add(x, y int) int { return x + y }

Просмотреть файл

@ -10,7 +10,7 @@ import (
func Boolean() {
b := true
if b { //@codeactionedit("if b", "refactor.rewrite", boolean)
if b { //@codeactionedit("if b", "refactor.rewrite.invertIf", boolean)
fmt.Println("A")
} else {
fmt.Println("B")
@ -18,7 +18,7 @@ func Boolean() {
}
func BooleanFn() {
if os.IsPathSeparator('X') { //@codeactionedit("if os.IsPathSeparator('X')", "refactor.rewrite", boolean_fn)
if os.IsPathSeparator('X') { //@codeactionedit("if os.IsPathSeparator('X')", "refactor.rewrite.invertIf", boolean_fn)
fmt.Println("A")
} else {
fmt.Println("B")
@ -30,7 +30,7 @@ func DontRemoveParens() {
a := false
b := true
if !(a ||
b) { //@codeactionedit("b", "refactor.rewrite", dont_remove_parens)
b) { //@codeactionedit("b", "refactor.rewrite.invertIf", dont_remove_parens)
fmt.Println("A")
} else {
fmt.Println("B")
@ -46,7 +46,7 @@ func ElseIf() {
// No inversion expected for else-if, that would become unreadable
if len(os.Args) > 2 {
fmt.Println("A")
} else if os.Args[0] == "X" { //@codeactionedit(re"if os.Args.0. == .X.", "refactor.rewrite", else_if)
} else if os.Args[0] == "X" { //@codeactionedit(re"if os.Args.0. == .X.", "refactor.rewrite.invertIf", else_if)
fmt.Println("B")
} else {
fmt.Println("C")
@ -54,7 +54,7 @@ func ElseIf() {
}
func GreaterThan() {
if len(os.Args) > 2 { //@codeactionedit("i", "refactor.rewrite", greater_than)
if len(os.Args) > 2 { //@codeactionedit("i", "refactor.rewrite.invertIf", greater_than)
fmt.Println("A")
} else {
fmt.Println("B")
@ -63,7 +63,7 @@ func GreaterThan() {
func NotBoolean() {
b := true
if !b { //@codeactionedit("if !b", "refactor.rewrite", not_boolean)
if !b { //@codeactionedit("if !b", "refactor.rewrite.invertIf", not_boolean)
fmt.Println("A")
} else {
fmt.Println("B")
@ -71,7 +71,7 @@ func NotBoolean() {
}
func RemoveElse() {
if true { //@codeactionedit("if true", "refactor.rewrite", remove_else)
if true { //@codeactionedit("if true", "refactor.rewrite.invertIf", remove_else)
fmt.Println("A")
} else {
fmt.Println("B")
@ -83,7 +83,7 @@ func RemoveElse() {
func RemoveParens() {
b := true
if !(b) { //@codeactionedit("if", "refactor.rewrite", remove_parens)
if !(b) { //@codeactionedit("if", "refactor.rewrite.invertIf", remove_parens)
fmt.Println("A")
} else {
fmt.Println("B")
@ -91,7 +91,7 @@ func RemoveParens() {
}
func Semicolon() {
if _, err := fmt.Println("x"); err != nil { //@codeactionedit("if", "refactor.rewrite", semicolon)
if _, err := fmt.Println("x"); err != nil { //@codeactionedit("if", "refactor.rewrite.invertIf", semicolon)
fmt.Println("A")
} else {
fmt.Println("B")
@ -99,7 +99,7 @@ func Semicolon() {
}
func SemicolonAnd() {
if n, err := fmt.Println("x"); err != nil && n > 0 { //@codeactionedit("f", "refactor.rewrite", semicolon_and)
if n, err := fmt.Println("x"); err != nil && n > 0 { //@codeactionedit("f", "refactor.rewrite.invertIf", semicolon_and)
fmt.Println("A")
} else {
fmt.Println("B")
@ -107,7 +107,7 @@ func SemicolonAnd() {
}
func SemicolonOr() {
if n, err := fmt.Println("x"); err != nil || n < 5 { //@codeactionedit(re"if n, err := fmt.Println..x..; err != nil .. n < 5", "refactor.rewrite", semicolon_or)
if n, err := fmt.Println("x"); err != nil || n < 5 { //@codeactionedit(re"if n, err := fmt.Println..x..; err != nil .. n < 5", "refactor.rewrite.invertIf", semicolon_or)
fmt.Println("A")
} else {
fmt.Println("B")
@ -116,103 +116,103 @@ func SemicolonOr() {
-- @boolean/p.go --
@@ -10,3 +10 @@
- if b { //@codeactionedit("if b", "refactor.rewrite", boolean)
- if b { //@codeactionedit("if b", "refactor.rewrite.invertIf", boolean)
- fmt.Println("A")
- } else {
+ if !b {
@@ -14 +12,2 @@
+ } else { //@codeactionedit("if b", "refactor.rewrite", boolean)
+ } else { //@codeactionedit("if b", "refactor.rewrite.invertIf", boolean)
+ fmt.Println("A")
-- @boolean_fn/p.go --
@@ -18,3 +18 @@
- if os.IsPathSeparator('X') { //@codeactionedit("if os.IsPathSeparator('X')", "refactor.rewrite", boolean_fn)
- if os.IsPathSeparator('X') { //@codeactionedit("if os.IsPathSeparator('X')", "refactor.rewrite.invertIf", boolean_fn)
- fmt.Println("A")
- } else {
+ if !os.IsPathSeparator('X') {
@@ -22 +20,2 @@
+ } else { //@codeactionedit("if os.IsPathSeparator('X')", "refactor.rewrite", boolean_fn)
+ } else { //@codeactionedit("if os.IsPathSeparator('X')", "refactor.rewrite.invertIf", boolean_fn)
+ fmt.Println("A")
-- @dont_remove_parens/p.go --
@@ -29,4 +29,2 @@
- if !(a ||
- b) { //@codeactionedit("b", "refactor.rewrite", dont_remove_parens)
- b) { //@codeactionedit("b", "refactor.rewrite.invertIf", dont_remove_parens)
- fmt.Println("A")
- } else {
+ if (a ||
+ b) {
@@ -34 +32,2 @@
+ } else { //@codeactionedit("b", "refactor.rewrite", dont_remove_parens)
+ } else { //@codeactionedit("b", "refactor.rewrite.invertIf", dont_remove_parens)
+ fmt.Println("A")
-- @else_if/p.go --
@@ -46,3 +46 @@
- } else if os.Args[0] == "X" { //@codeactionedit(re"if os.Args.0. == .X.", "refactor.rewrite", else_if)
- } else if os.Args[0] == "X" { //@codeactionedit(re"if os.Args.0. == .X.", "refactor.rewrite.invertIf", else_if)
- fmt.Println("B")
- } else {
+ } else if os.Args[0] != "X" {
@@ -50 +48,2 @@
+ } else { //@codeactionedit(re"if os.Args.0. == .X.", "refactor.rewrite", else_if)
+ } else { //@codeactionedit(re"if os.Args.0. == .X.", "refactor.rewrite.invertIf", else_if)
+ fmt.Println("B")
-- @greater_than/p.go --
@@ -54,3 +54 @@
- if len(os.Args) > 2 { //@codeactionedit("i", "refactor.rewrite", greater_than)
- if len(os.Args) > 2 { //@codeactionedit("i", "refactor.rewrite.invertIf", greater_than)
- fmt.Println("A")
- } else {
+ if len(os.Args) <= 2 {
@@ -58 +56,2 @@
+ } else { //@codeactionedit("i", "refactor.rewrite", greater_than)
+ } else { //@codeactionedit("i", "refactor.rewrite.invertIf", greater_than)
+ fmt.Println("A")
-- @not_boolean/p.go --
@@ -63,3 +63 @@
- if !b { //@codeactionedit("if !b", "refactor.rewrite", not_boolean)
- if !b { //@codeactionedit("if !b", "refactor.rewrite.invertIf", not_boolean)
- fmt.Println("A")
- } else {
+ if b {
@@ -67 +65,2 @@
+ } else { //@codeactionedit("if !b", "refactor.rewrite", not_boolean)
+ } else { //@codeactionedit("if !b", "refactor.rewrite.invertIf", not_boolean)
+ fmt.Println("A")
-- @remove_else/p.go --
@@ -71,3 +71 @@
- if true { //@codeactionedit("if true", "refactor.rewrite", remove_else)
- if true { //@codeactionedit("if true", "refactor.rewrite.invertIf", remove_else)
- fmt.Println("A")
- } else {
+ if false {
@@ -78 +76,3 @@
+ //@codeactionedit("if true", "refactor.rewrite", remove_else)
+ //@codeactionedit("if true", "refactor.rewrite.invertIf", remove_else)
+ fmt.Println("A")
+
-- @remove_parens/p.go --
@@ -83,3 +83 @@
- if !(b) { //@codeactionedit("if", "refactor.rewrite", remove_parens)
- if !(b) { //@codeactionedit("if", "refactor.rewrite.invertIf", remove_parens)
- fmt.Println("A")
- } else {
+ if b {
@@ -87 +85,2 @@
+ } else { //@codeactionedit("if", "refactor.rewrite", remove_parens)
+ } else { //@codeactionedit("if", "refactor.rewrite.invertIf", remove_parens)
+ fmt.Println("A")
-- @semicolon/p.go --
@@ -91,3 +91 @@
- if _, err := fmt.Println("x"); err != nil { //@codeactionedit("if", "refactor.rewrite", semicolon)
- if _, err := fmt.Println("x"); err != nil { //@codeactionedit("if", "refactor.rewrite.invertIf", semicolon)
- fmt.Println("A")
- } else {
+ if _, err := fmt.Println("x"); err == nil {
@@ -95 +93,2 @@
+ } else { //@codeactionedit("if", "refactor.rewrite", semicolon)
+ } else { //@codeactionedit("if", "refactor.rewrite.invertIf", semicolon)
+ fmt.Println("A")
-- @semicolon_and/p.go --
@@ -99,3 +99 @@
- if n, err := fmt.Println("x"); err != nil && n > 0 { //@codeactionedit("f", "refactor.rewrite", semicolon_and)
- if n, err := fmt.Println("x"); err != nil && n > 0 { //@codeactionedit("f", "refactor.rewrite.invertIf", semicolon_and)
- fmt.Println("A")
- } else {
+ if n, err := fmt.Println("x"); err == nil || n <= 0 {
@@ -103 +101,2 @@
+ } else { //@codeactionedit("f", "refactor.rewrite", semicolon_and)
+ } else { //@codeactionedit("f", "refactor.rewrite.invertIf", semicolon_and)
+ fmt.Println("A")
-- @semicolon_or/p.go --
@@ -107,3 +107 @@
- if n, err := fmt.Println("x"); err != nil || n < 5 { //@codeactionedit(re"if n, err := fmt.Println..x..; err != nil .. n < 5", "refactor.rewrite", semicolon_or)
- if n, err := fmt.Println("x"); err != nil || n < 5 { //@codeactionedit(re"if n, err := fmt.Println..x..; err != nil .. n < 5", "refactor.rewrite.invertIf", semicolon_or)
- fmt.Println("A")
- } else {
+ if n, err := fmt.Println("x"); err == nil && n >= 5 {
@@ -111 +109,2 @@
+ } else { //@codeactionedit(re"if n, err := fmt.Println..x..; err != nil .. n < 5", "refactor.rewrite", semicolon_or)
+ } else { //@codeactionedit(re"if n, err := fmt.Println..x..; err != nil .. n < 5", "refactor.rewrite.invertIf", semicolon_or)
+ fmt.Println("A")

Просмотреть файл

@ -8,7 +8,7 @@ go 1.18
package a
func _() {
f(1, 2) //@ diag("2", re"too many arguments"), codeactionerr("f", ")", "refactor.inline", re`inlining failed \("args/params mismatch"\), likely because inputs were ill-typed`)
f(1, 2) //@ diag("2", re"too many arguments"), codeactionerr("f", ")", "refactor.inline.call", re`inlining failed \("args/params mismatch"\), likely because inputs were ill-typed`)
}
func f(int) {}

Просмотреть файл

@ -9,14 +9,14 @@ go 1.18
-- a/a.go --
package a
func A(x, unused int) int { //@codeaction("unused", "unused", "refactor.rewrite", a)
func A(x, unused int) int { //@codeaction("unused", "unused", "refactor.rewrite.removeUnusedParam", a)
return x
}
-- @a/a/a.go --
package a
func A(x int) int { //@codeaction("unused", "unused", "refactor.rewrite", a)
func A(x int) int { //@codeaction("unused", "unused", "refactor.rewrite.removeUnusedParam", a)
return x
}
@ -99,7 +99,7 @@ func _() {
-- field/field.go --
package field
func Field(x int, field int) { //@codeaction("int", "int", "refactor.rewrite", field, "Refactor: remove unused parameter")
func Field(x int, field int) { //@codeaction("int", "int", "refactor.rewrite.removeUnusedParam", field)
}
func _() {
@ -108,7 +108,7 @@ func _() {
-- @field/field/field.go --
package field
func Field(field int) { //@codeaction("int", "int", "refactor.rewrite", field, "Refactor: remove unused parameter")
func Field(field int) { //@codeaction("int", "int", "refactor.rewrite.removeUnusedParam", field)
}
func _() {
@ -117,7 +117,7 @@ func _() {
-- ellipsis/ellipsis.go --
package ellipsis
func Ellipsis(...any) { //@codeaction("any", "any", "refactor.rewrite", ellipsis)
func Ellipsis(...any) { //@codeaction("any", "any", "refactor.rewrite.removeUnusedParam", ellipsis)
}
func _() {
@ -138,7 +138,7 @@ func i() []any
-- @ellipsis/ellipsis/ellipsis.go --
package ellipsis
func Ellipsis() { //@codeaction("any", "any", "refactor.rewrite", ellipsis)
func Ellipsis() { //@codeaction("any", "any", "refactor.rewrite.removeUnusedParam", ellipsis)
}
func _() {
@ -162,7 +162,7 @@ func i() []any
-- ellipsis2/ellipsis2.go --
package ellipsis2
func Ellipsis2(_, _ int, rest ...int) { //@codeaction("_", "_", "refactor.rewrite", ellipsis2, "Refactor: remove unused parameter")
func Ellipsis2(_, _ int, rest ...int) { //@codeaction("_", "_", "refactor.rewrite.removeUnusedParam", ellipsis2)
}
func _() {
@ -176,7 +176,7 @@ func h() (int, int)
-- @ellipsis2/ellipsis2/ellipsis2.go --
package ellipsis2
func Ellipsis2(_ int, rest ...int) { //@codeaction("_", "_", "refactor.rewrite", ellipsis2, "Refactor: remove unused parameter")
func Ellipsis2(_ int, rest ...int) { //@codeaction("_", "_", "refactor.rewrite.removeUnusedParam", ellipsis2)
}
func _() {
@ -191,7 +191,7 @@ func h() (int, int)
-- overlapping/overlapping.go --
package overlapping
func Overlapping(i int) int { //@codeactionerr(re"(i) int", re"(i) int", "refactor.rewrite", re"overlapping")
func Overlapping(i int) int { //@codeactionerr(re"(i) int", re"(i) int", "refactor.rewrite.removeUnusedParam", re"overlapping")
return 0
}
@ -203,7 +203,7 @@ func _() {
-- effects/effects.go --
package effects
func effects(x, y int) int { //@ diag("y", re"unused"), codeaction("y", "y", "refactor.rewrite", effects)
func effects(x, y int) int { //@ diag("y", re"unused"), codeaction("y", "y", "refactor.rewrite.removeUnusedParam", effects)
return x
}
@ -217,7 +217,7 @@ func _() {
-- @effects/effects/effects.go --
package effects
func effects(x int) int { //@ diag("y", re"unused"), codeaction("y", "y", "refactor.rewrite", effects)
func effects(x int) int { //@ diag("y", re"unused"), codeaction("y", "y", "refactor.rewrite.removeUnusedParam", effects)
return x
}
@ -235,13 +235,13 @@ func _() {
-- recursive/recursive.go --
package recursive
func Recursive(x int) int { //@codeaction("x", "x", "refactor.rewrite", recursive)
func Recursive(x int) int { //@codeaction("x", "x", "refactor.rewrite.removeUnusedParam", recursive)
return Recursive(1)
}
-- @recursive/recursive/recursive.go --
package recursive
func Recursive() int { //@codeaction("x", "x", "refactor.rewrite", recursive)
func Recursive() int { //@codeaction("x", "x", "refactor.rewrite.removeUnusedParam", recursive)
return Recursive()
}

Просмотреть файл

@ -14,7 +14,7 @@ go 1.18
package a
// A doc comment.
func A(x /* used parameter */, unused int /* unused parameter */ ) int { //@codeaction("unused", "unused", "refactor.rewrite", a)
func A(x /* used parameter */, unused int /* unused parameter */ ) int { //@codeaction("unused", "unused", "refactor.rewrite.removeUnusedParam", a)
// about to return
return x // returning
// just returned
@ -36,7 +36,7 @@ func one() int {
package a
// A doc comment.
func A(x int) int { //@codeaction("unused", "unused", "refactor.rewrite", a)
func A(x int) int { //@codeaction("unused", "unused", "refactor.rewrite.removeUnusedParam", a)
// about to return
return x // returning
// just returned

Просмотреть файл

@ -10,7 +10,7 @@ go 1.18
-- a/a.go --
package a
func A(x, unused int) int { //@codeactionerr("unused", "unused", "refactor.rewrite", re"non-call function reference")
func A(x, unused int) int { //@codeactionerr("unused", "unused", "refactor.rewrite.removeUnusedParam", re"non-call function reference")
return x
}

Просмотреть файл

@ -62,7 +62,7 @@ import "mod.test/c"
var Chan chan c.C
func B(x, y c.C) { //@codeaction("x", "x", "refactor.rewrite", b)
func B(x, y c.C) { //@codeaction("x", "x", "refactor.rewrite.removeUnusedParam", b)
}
-- c/c.go --
@ -76,7 +76,7 @@ package d
// Removing the parameter should remove this import.
import "mod.test/c"
func D(x c.C) { //@codeaction("x", "x", "refactor.rewrite", d)
func D(x c.C) { //@codeaction("x", "x", "refactor.rewrite.removeUnusedParam", d)
}
func _() {
@ -148,14 +148,14 @@ import "mod.test/c"
var Chan chan c.C
func B(y c.C) { //@codeaction("x", "x", "refactor.rewrite", b)
func B(y c.C) { //@codeaction("x", "x", "refactor.rewrite.removeUnusedParam", b)
}
-- @d/d/d.go --
package d
// Removing the parameter should remove this import.
func D() { //@codeaction("x", "x", "refactor.rewrite", d)
func D() { //@codeaction("x", "x", "refactor.rewrite.removeUnusedParam", d)
}
func _() {

Просмотреть файл

@ -27,7 +27,7 @@ func _() {
_ = i
}
func f(unused S, i int) int { //@codeaction("unused", "unused", "refactor.rewrite", rewrite, "Refactor: remove unused parameter"), diag("unused", re`unused`)
func f(unused S, i int) int { //@codeaction("unused", "unused", "refactor.rewrite.removeUnusedParam", rewrite), diag("unused", re`unused`)
return i
}
@ -53,6 +53,6 @@ func _() {
_ = i
}
func f(i int) int { //@codeaction("unused", "unused", "refactor.rewrite", rewrite, "Refactor: remove unused parameter"), diag("unused", re`unused`)
func f(i int) int { //@codeaction("unused", "unused", "refactor.rewrite.removeUnusedParam", rewrite), diag("unused", re`unused`)
return i
}

Просмотреть файл

@ -18,7 +18,7 @@ package rm
type Basic int
func (t Basic) Foo(x int) { //@codeaction("x", "x", "refactor.rewrite", basic)
func (t Basic) Foo(x int) { //@codeaction("x", "x", "refactor.rewrite.removeUnusedParam", basic)
}
func _(b Basic) {
@ -45,7 +45,7 @@ package rm
type Basic int
func (t Basic) Foo() { //@codeaction("x", "x", "refactor.rewrite", basic)
func (t Basic) Foo() { //@codeaction("x", "x", "refactor.rewrite.removeUnusedParam", basic)
}
func _(b Basic) {
@ -76,7 +76,7 @@ type Missing struct{}
var r2 int
func (Missing) M(a, b, c, r0 int) (r1 int) { //@codeaction("b", "b", "refactor.rewrite", missingrecv)
func (Missing) M(a, b, c, r0 int) (r1 int) { //@codeaction("b", "b", "refactor.rewrite.removeUnusedParam", missingrecv)
return a + c
}
@ -104,7 +104,7 @@ type Missing struct{}
var r2 int
func (Missing) M(a, c, r0 int) (r1 int) { //@codeaction("b", "b", "refactor.rewrite", missingrecv)
func (Missing) M(a, c, r0 int) (r1 int) { //@codeaction("b", "b", "refactor.rewrite.removeUnusedParam", missingrecv)
return a + c
}

Просмотреть файл

@ -20,14 +20,14 @@ go 1.18
-- a/a.go --
package a
func A(x, unused int) int { //@codeaction("unused", "unused", "refactor.rewrite", a)
func A(x, unused int) int { //@codeaction("unused", "unused", "refactor.rewrite.removeUnusedParam", a)
return x
}
-- @a/a/a.go --
package a
func A(x int) int { //@codeaction("unused", "unused", "refactor.rewrite", a)
func A(x int) int { //@codeaction("unused", "unused", "refactor.rewrite.removeUnusedParam", a)
return x
}
@ -110,7 +110,7 @@ func _() {
-- field/field.go --
package field
func Field(x int, field int) { //@codeaction("int", "int", "refactor.rewrite", field, "Refactor: remove unused parameter")
func Field(x int, field int) { //@codeaction("int", "int", "refactor.rewrite.removeUnusedParam", field)
}
func _() {
@ -119,7 +119,7 @@ func _() {
-- @field/field/field.go --
package field
func Field(field int) { //@codeaction("int", "int", "refactor.rewrite", field, "Refactor: remove unused parameter")
func Field(field int) { //@codeaction("int", "int", "refactor.rewrite.removeUnusedParam", field)
}
func _() {
@ -128,7 +128,7 @@ func _() {
-- ellipsis/ellipsis.go --
package ellipsis
func Ellipsis(...any) { //@codeaction("any", "any", "refactor.rewrite", ellipsis)
func Ellipsis(...any) { //@codeaction("any", "any", "refactor.rewrite.removeUnusedParam", ellipsis)
}
func _() {
@ -149,7 +149,7 @@ func i() []any
-- @ellipsis/ellipsis/ellipsis.go --
package ellipsis
func Ellipsis() { //@codeaction("any", "any", "refactor.rewrite", ellipsis)
func Ellipsis() { //@codeaction("any", "any", "refactor.rewrite.removeUnusedParam", ellipsis)
}
func _() {
@ -173,7 +173,7 @@ func i() []any
-- ellipsis2/ellipsis2.go --
package ellipsis2
func Ellipsis2(_, _ int, rest ...int) { //@codeaction("_", "_", "refactor.rewrite", ellipsis2, "Refactor: remove unused parameter")
func Ellipsis2(_, _ int, rest ...int) { //@codeaction("_", "_", "refactor.rewrite.removeUnusedParam", ellipsis2)
}
func _() {
@ -187,7 +187,7 @@ func h() (int, int)
-- @ellipsis2/ellipsis2/ellipsis2.go --
package ellipsis2
func Ellipsis2(_ int, rest ...int) { //@codeaction("_", "_", "refactor.rewrite", ellipsis2, "Refactor: remove unused parameter")
func Ellipsis2(_ int, rest ...int) { //@codeaction("_", "_", "refactor.rewrite.removeUnusedParam", ellipsis2)
}
func _() {
@ -202,7 +202,7 @@ func h() (int, int)
-- overlapping/overlapping.go --
package overlapping
func Overlapping(i int) int { //@codeactionerr(re"(i) int", re"(i) int", "refactor.rewrite", re"overlapping")
func Overlapping(i int) int { //@codeactionerr(re"(i) int", re"(i) int", "refactor.rewrite.removeUnusedParam", re"overlapping")
return 0
}
@ -214,7 +214,7 @@ func _() {
-- effects/effects.go --
package effects
func effects(x, y int) int { //@codeaction("y", "y", "refactor.rewrite", effects), diag("y", re"unused")
func effects(x, y int) int { //@codeaction("y", "y", "refactor.rewrite.removeUnusedParam", effects), diag("y", re"unused")
return x
}
@ -228,7 +228,7 @@ func _() {
-- @effects/effects/effects.go --
package effects
func effects(x int) int { //@codeaction("y", "y", "refactor.rewrite", effects), diag("y", re"unused")
func effects(x int) int { //@codeaction("y", "y", "refactor.rewrite.removeUnusedParam", effects), diag("y", re"unused")
return x
}
@ -246,13 +246,13 @@ func _() {
-- recursive/recursive.go --
package recursive
func Recursive(x int) int { //@codeaction("x", "x", "refactor.rewrite", recursive)
func Recursive(x int) int { //@codeaction("x", "x", "refactor.rewrite.removeUnusedParam", recursive)
return Recursive(1)
}
-- @recursive/recursive/recursive.go --
package recursive
func Recursive() int { //@codeaction("x", "x", "refactor.rewrite", recursive)
func Recursive() int { //@codeaction("x", "x", "refactor.rewrite.removeUnusedParam", recursive)
return Recursive()
}

Просмотреть файл

@ -21,7 +21,7 @@ package rm
type T int
func (t T) Foo(x int) { //@codeaction("x", "x", "refactor.rewrite", basic)
func (t T) Foo(x int) { //@codeaction("x", "x", "refactor.rewrite.removeUnusedParam", basic)
}
-- use/use.go --
@ -44,7 +44,7 @@ package rm
type T int
func (t T) Foo() { //@codeaction("x", "x", "refactor.rewrite", basic)
func (t T) Foo() { //@codeaction("x", "x", "refactor.rewrite.removeUnusedParam", basic)
}
-- @basic/use/use.go --

Просмотреть файл

@ -3,7 +3,7 @@ This test checks that we can't remove parameters for packages with errors.
-- p.go --
package p
func foo(unused int) { //@codeactionerr("unused", "unused", "refactor.rewrite", re"found 0")
func foo(unused int) { //@codeactionerr("unused", "unused", "refactor.rewrite.removeUnusedParam", re"found 0")
}
func _() {

Просмотреть файл

@ -9,7 +9,7 @@ go 1.18
-- func_arg/func_arg.go --
package func_arg
func A(a string, b, c int64, x int, y int) (r1 string, r2, r3 int64, r4 int, r5 int) { //@codeaction("x", "x", "refactor.rewrite", func_arg)
func A(a string, b, c int64, x int, y int) (r1 string, r2, r3 int64, r4 int, r5 int) { //@codeaction("x", "x", "refactor.rewrite.splitLines", func_arg)
return a, b, c, x, y
}
@ -21,14 +21,14 @@ func A(
b, c int64,
x int,
y int,
) (r1 string, r2, r3 int64, r4 int, r5 int) { //@codeaction("x", "x", "refactor.rewrite", func_arg)
) (r1 string, r2, r3 int64, r4 int, r5 int) { //@codeaction("x", "x", "refactor.rewrite.splitLines", func_arg)
return a, b, c, x, y
}
-- func_ret/func_ret.go --
package func_ret
func A(a string, b, c int64, x int, y int) (r1 string, r2, r3 int64, r4 int, r5 int) { //@codeaction("r1", "r1", "refactor.rewrite", func_ret)
func A(a string, b, c int64, x int, y int) (r1 string, r2, r3 int64, r4 int, r5 int) { //@codeaction("r1", "r1", "refactor.rewrite.splitLines", func_ret)
return a, b, c, x, y
}
@ -40,14 +40,14 @@ func A(a string, b, c int64, x int, y int) (
r2, r3 int64,
r4 int,
r5 int,
) { //@codeaction("r1", "r1", "refactor.rewrite", func_ret)
) { //@codeaction("r1", "r1", "refactor.rewrite.splitLines", func_ret)
return a, b, c, x, y
}
-- functype_arg/functype_arg.go --
package functype_arg
type A func(a string, b, c int64, x int, y int) (r1 string, r2, r3 int64, r4 int, r5 int) //@codeaction("x", "x", "refactor.rewrite", functype_arg)
type A func(a string, b, c int64, x int, y int) (r1 string, r2, r3 int64, r4 int, r5 int) //@codeaction("x", "x", "refactor.rewrite.splitLines", functype_arg)
-- @functype_arg/functype_arg/functype_arg.go --
package functype_arg
@ -57,12 +57,12 @@ type A func(
b, c int64,
x int,
y int,
) (r1 string, r2, r3 int64, r4 int, r5 int) //@codeaction("x", "x", "refactor.rewrite", functype_arg)
) (r1 string, r2, r3 int64, r4 int, r5 int) //@codeaction("x", "x", "refactor.rewrite.splitLines", functype_arg)
-- functype_ret/functype_ret.go --
package functype_ret
type A func(a string, b, c int64, x int, y int) (r1 string, r2, r3 int64, r4 int, r5 int) //@codeaction("r1", "r1", "refactor.rewrite", functype_ret)
type A func(a string, b, c int64, x int, y int) (r1 string, r2, r3 int64, r4 int, r5 int) //@codeaction("r1", "r1", "refactor.rewrite.splitLines", functype_ret)
-- @functype_ret/functype_ret/functype_ret.go --
package functype_ret
@ -72,7 +72,7 @@ type A func(a string, b, c int64, x int, y int) (
r2, r3 int64,
r4 int,
r5 int,
) //@codeaction("r1", "r1", "refactor.rewrite", functype_ret)
) //@codeaction("r1", "r1", "refactor.rewrite.splitLines", functype_ret)
-- func_call/func_call.go --
package func_call
@ -80,7 +80,7 @@ package func_call
import "fmt"
func a() {
fmt.Println(1, 2, 3, fmt.Sprintf("hello %d", 4)) //@codeaction("1", "1", "refactor.rewrite", func_call)
fmt.Println(1, 2, 3, fmt.Sprintf("hello %d", 4)) //@codeaction("1", "1", "refactor.rewrite.splitLines", func_call)
}
-- @func_call/func_call/func_call.go --
@ -94,7 +94,7 @@ func a() {
2,
3,
fmt.Sprintf("hello %d", 4),
) //@codeaction("1", "1", "refactor.rewrite", func_call)
) //@codeaction("1", "1", "refactor.rewrite.splitLines", func_call)
}
-- indent/indent.go --
@ -103,7 +103,7 @@ package indent
import "fmt"
func a() {
fmt.Println(1, 2, 3, fmt.Sprintf("hello %d", 4)) //@codeaction("hello", "hello", "refactor.rewrite", indent, "Split arguments into separate lines")
fmt.Println(1, 2, 3, fmt.Sprintf("hello %d", 4)) //@codeaction("hello", "hello", "refactor.rewrite.splitLines", indent)
}
-- @indent/indent/indent.go --
@ -115,7 +115,7 @@ func a() {
fmt.Println(1, 2, 3, fmt.Sprintf(
"hello %d",
4,
)) //@codeaction("hello", "hello", "refactor.rewrite", indent, "Split arguments into separate lines")
)) //@codeaction("hello", "hello", "refactor.rewrite.splitLines", indent)
}
-- indent2/indent2.go --
@ -125,7 +125,7 @@ import "fmt"
func a() {
fmt.
Println(1, 2, 3, fmt.Sprintf("hello %d", 4)) //@codeaction("1", "1", "refactor.rewrite", indent2, "Split arguments into separate lines")
Println(1, 2, 3, fmt.Sprintf("hello %d", 4)) //@codeaction("1", "1", "refactor.rewrite.splitLines", indent2)
}
-- @indent2/indent2/indent2.go --
@ -140,7 +140,7 @@ func a() {
2,
3,
fmt.Sprintf("hello %d", 4),
) //@codeaction("1", "1", "refactor.rewrite", indent2, "Split arguments into separate lines")
) //@codeaction("1", "1", "refactor.rewrite.splitLines", indent2)
}
-- structelts/structelts.go --
@ -152,7 +152,7 @@ type A struct{
}
func a() {
_ = A{a: 1, b: 2} //@codeaction("b", "b", "refactor.rewrite", structelts)
_ = A{a: 1, b: 2} //@codeaction("b", "b", "refactor.rewrite.splitLines", structelts)
}
-- @structelts/structelts/structelts.go --
@ -167,14 +167,14 @@ func a() {
_ = A{
a: 1,
b: 2,
} //@codeaction("b", "b", "refactor.rewrite", structelts)
} //@codeaction("b", "b", "refactor.rewrite.splitLines", structelts)
}
-- sliceelts/sliceelts.go --
package sliceelts
func a() {
_ = []int{1, 2} //@codeaction("1", "1", "refactor.rewrite", sliceelts)
_ = []int{1, 2} //@codeaction("1", "1", "refactor.rewrite.splitLines", sliceelts)
}
-- @sliceelts/sliceelts/sliceelts.go --
@ -184,14 +184,14 @@ func a() {
_ = []int{
1,
2,
} //@codeaction("1", "1", "refactor.rewrite", sliceelts)
} //@codeaction("1", "1", "refactor.rewrite.splitLines", sliceelts)
}
-- mapelts/mapelts.go --
package mapelts
func a() {
_ = map[string]int{"a": 1, "b": 2} //@codeaction("1", "1", "refactor.rewrite", mapelts)
_ = map[string]int{"a": 1, "b": 2} //@codeaction("1", "1", "refactor.rewrite.splitLines", mapelts)
}
-- @mapelts/mapelts/mapelts.go --
@ -201,13 +201,13 @@ func a() {
_ = map[string]int{
"a": 1,
"b": 2,
} //@codeaction("1", "1", "refactor.rewrite", mapelts)
} //@codeaction("1", "1", "refactor.rewrite.splitLines", mapelts)
}
-- starcomment/starcomment.go --
package starcomment
func A(/*1*/ x /*2*/ string /*3*/, /*4*/ y /*5*/ int /*6*/) (string, int) { //@codeaction("x", "x", "refactor.rewrite", starcomment)
func A(/*1*/ x /*2*/ string /*3*/, /*4*/ y /*5*/ int /*6*/) (string, int) { //@codeaction("x", "x", "refactor.rewrite.splitLines", starcomment)
return x, y
}
@ -217,7 +217,7 @@ package starcomment
func A(
/*1*/ x /*2*/ string /*3*/,
/*4*/ y /*5*/ int /*6*/,
) (string, int) { //@codeaction("x", "x", "refactor.rewrite", starcomment)
) (string, int) { //@codeaction("x", "x", "refactor.rewrite.splitLines", starcomment)
return x, y
}