Skip to content
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

x/tools/gopls: 'refactor'-only codeAction should return all available 'refactor.*' code action items #44213

Open
hyangah opened this issue Feb 10, 2021 · 1 comment
Labels
Milestone

Comments

@hyangah
Copy link
Contributor

@hyangah hyangah commented Feb 10, 2021

gopls version v0.6.5

When vscode user selects 'Refactor...' context menu entry, vscode requests codeAction with "context": { ... "only": ["refactor"]}. Gopls doesn't return anything even though there are possible refactoring actions applicable to the selected range.

[Trace - 14:38:03.583 PM] Sending request 'textDocument/codeAction - (10)'.
Params: {
  "textDocument":{"uri":"file:///Users/hakim/projects/w/main.go"},
  "range":{"start":{"line":6,"character":0},"end":{"line":8,"character":3}},
  "context":{"diagnostics":[],"only":["refactor"]}}


[Trace - 14:38:03.584 PM] Received response 'textDocument/codeAction - (10)' in 1ms.
Result: null

Compare against the result for the previous codeAction request on the same range:

[Trace - 14:37:57.484 PM] Sending request 'textDocument/codeAction - (8)'.
Params: {
   "textDocument":{"uri":"file:///Users/hakim/projects/w/main.go"},
   "range":{"start":{"line":6,"character":0},"end":{"line":8,"character":3}},
   "context":{"diagnostics":[]}}


[Trace - 14:37:57.485 PM] Received response 'textDocument/codeAction - (8)' in 0ms.
Result: [{
   "title":"Extract to function",
   "kind":"refactor.extract","edit":{},
   "command":{"title":"","command":"gopls.extract_function","arguments":["file:///Users/hakim/projects/w/main.go",{"start":{"line":6,"character":0},"end":{"line":8,"character":3}}]}}]
@gopherbot gopherbot added this to the Unreleased milestone Feb 10, 2021
@heschik
Copy link
Contributor

@heschik heschik commented Feb 10, 2021

https://cs.opensource.google/go/x/tools/+/master:internal/lsp/code_action.go;l=165-178;drc=d4590503678b9a270e7c2a91fe6dccea617322a6 does exact matches on the only attribute. It seems we should return refactor.extract for only=refactor.

@stamblerre stamblerre modified the milestones: Unreleased, gopls/v1.0.0 Feb 10, 2021
@stamblerre stamblerre changed the title x/tools/gopls: 'refactor'-only codeAction should return all available 'refactor.*' code action items. x/tools/gopls: 'refactor'-only codeAction should return all available 'refactor.*' code action items Feb 10, 2021
@stamblerre stamblerre added this to To Do in gopls: v1.0.0 Feb 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants