diff --git a/gopls/internal/golang/codeaction.go b/gopls/internal/golang/codeaction.go index a9aae821be8..5c6163cef12 100644 --- a/gopls/internal/golang/codeaction.go +++ b/gopls/internal/golang/codeaction.go @@ -106,7 +106,7 @@ func CodeActions(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle, } if want[protocol.RefactorInline] { - rewrites, err := getInlineCodeActions(pkg, pgf, rng) + rewrites, err := getInlineCodeActions(pkg, pgf, rng, snapshot.Options()) if err != nil { return nil, err } @@ -381,7 +381,7 @@ func canRemoveParameter(pkg *cache.Package, pgf *ParsedGoFile, rng protocol.Rang } // getInlineCodeActions returns refactor.inline actions available at the specified range. -func getInlineCodeActions(pkg *cache.Package, pgf *ParsedGoFile, rng protocol.Range) ([]protocol.CodeAction, error) { +func getInlineCodeActions(pkg *cache.Package, pgf *ParsedGoFile, rng protocol.Range, options *settings.Options) ([]protocol.CodeAction, error) { start, end, err := pgf.RangePos(rng) if err != nil { return nil, err @@ -391,9 +391,10 @@ func getInlineCodeActions(pkg *cache.Package, pgf *ParsedGoFile, rng protocol.Ra 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, + Fix: fixInlineCall, + URI: pgf.URI, + Range: rng, + ResolveEdits: supportsResolveEdits(options), }) if err != nil { return nil, err @@ -404,11 +405,7 @@ func getInlineCodeActions(pkg *cache.Package, pgf *ParsedGoFile, rng protocol.Ra // Convert commands to actions. var actions []protocol.CodeAction for i := range commands { - actions = append(actions, protocol.CodeAction{ - Title: commands[i].Title, - Kind: protocol.RefactorInline, - Command: &commands[i], - }) + actions = append(actions, newCodeAction(commands[i].Title, protocol.RefactorInline, &commands[i], nil, options)) } return actions, nil } diff --git a/gopls/internal/test/marker/testdata/codeaction/inline.txt b/gopls/internal/test/marker/testdata/codeaction/inline.txt index 339a05b0c41..0c5bcb41658 100644 --- a/gopls/internal/test/marker/testdata/codeaction/inline.txt +++ b/gopls/internal/test/marker/testdata/codeaction/inline.txt @@ -1,4 +1,5 @@ -This is a minimal test of the refactor.inline code action. +This is a minimal test of the refactor.inline code action, without resolve support. +See inline_resolve.txt for same test with resolve support. -- go.mod -- module example.com/codeaction diff --git a/gopls/internal/test/marker/testdata/codeaction/inline_resolve.txt b/gopls/internal/test/marker/testdata/codeaction/inline_resolve.txt new file mode 100644 index 00000000000..02c27e6505b --- /dev/null +++ b/gopls/internal/test/marker/testdata/codeaction/inline_resolve.txt @@ -0,0 +1,35 @@ +This is a minimal test of the refactor.inline code actions, with resolve support. +See inline.txt for same test without resolve support. + +-- capabilities.json -- +{ + "textDocument": { + "codeAction": { + "dataSupport": true, + "resolveSupport": { + "properties": ["edit"] + } + } + } +} +-- go.mod -- +module example.com/codeaction +go 1.18 + +-- a/a.go -- +package a + +func _() { + println(add(1, 2)) //@codeaction("add", ")", "refactor.inline", inline) +} + +func add(x, y int) int { return x + y } + +-- @inline/a/a.go -- +package a + +func _() { + println(1 + 2) //@codeaction("add", ")", "refactor.inline", inline) +} + +func add(x, y int) int { return x + y }