Skip to content

x/tools/gopls: "only" refactor codeAction requests returns null #49263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
obonobo opened this issue Oct 29, 2021 · 2 comments
Closed

x/tools/gopls: "only" refactor codeAction requests returns null #49263

obonobo opened this issue Oct 29, 2021 · 2 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@obonobo
Copy link

obonobo commented Oct 29, 2021

Is your feature request related to a problem? Please describe.

vscode is my main editor for golang, but one area where it is sorely lacking is the refactoring support.

One example of an improvement I'd love to have is for the golang extension to respond to the Refactor... command in the editor.

The command I'm talking about is the one that gets triggered by the following actions:

  1. Opening command palette, ctrl+shift+p, typing "Refactor...", hitting enter
  2. Right clicking some code and selecting "Refactor..." from the context menu
  3. Keyboard shortcut ctrl+shift+r

For most languages, triggering this command opens a context menu with different refactoring options like Extract method, Extract variable, etc.

For example:
python-extract-method

But the golang extension doesn't respond to this command... It always says No refactorings available...

go-extract-function

Personally, I use this command all the time in other languages - it saves many keystrokes moving around bits of code.

Describe the solution you'd like

gopls does actually have refactorings available, it just doesn't respond to Refactor...

What I'd like to see is a context menu with all applicable refactorings upon issuing the Refactor... command.

I'm not very familiar with the anatomy of LSP and vscode extensions, so I couldn't say if this is a deficiency of the golang extension or of gopls. I would suspect both.

Describe alternatives you've considered

The next best alternative is to use the command palette (and/or keybindings) to manually search for the refactoring operation you want to run.

But this is unwieldy and much less useful since refactoring is context-dependent and the commands often fail - it would help if the editor was able to tell you what refactorings it knows are possible on the code you selected.

@suzmue
Copy link
Contributor

suzmue commented Nov 1, 2021

This appears to be a gopls issue. There is a request sent for all codeActions that have kind "refactor", but gopls does not return any code actions:

[Trace - 12:57:48.217 PM] Sending request 'textDocument/codeAction - (25)'.
Params: {"textDocument":{"uri":"file:///Users/suzmue/gophercon/butterflies/butterflies.go"},"range":{"start":{"line":16,"character":1},"end":{"line":21,"character":2}},"context":{"diagnostics":[],"only":["refactor"]}}

[Trace - 12:57:48.217 PM] Received response 'textDocument/codeAction - (25)' in 0ms.
Result: null

Transferring this to gopls.

@suzmue suzmue changed the title Better refactor support: respond to Refactor... command x/tools/gopls: support "only" filtered codeAction requests Nov 1, 2021
@suzmue suzmue transferred this issue from golang/vscode-go Nov 1, 2021
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Nov 1, 2021
@gopherbot gopherbot added this to the Unreleased milestone Nov 1, 2021
@suzmue suzmue modified the milestones: Unreleased, gopls/unplanned Nov 2, 2021
@suzmue suzmue self-assigned this Nov 5, 2021
@suzmue suzmue changed the title x/tools/gopls: support "only" filtered codeAction requests x/tools/gopls: "only" refactor codeAction requests returns null Nov 5, 2021
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/361834 mentions this issue: internal/lsp: return all code action kinds with context.only prefix

@rsc rsc unassigned suzmue Jun 23, 2022
@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants