From 5e46725290d137b2626265535d7fb33a49e166a3 Mon Sep 17 00:00:00 2001 From: Suzy Mueller Date: Fri, 5 Nov 2021 16:11:58 -0400 Subject: [PATCH] internal/lsp: return all code action kinds with context.only prefix When context.Only is passed in the codeAction request, all code actions that have a matching prefix should be returned. For example: context.Only: "refactor" want: "refactor.extract", "refactor.rewrite" Fixes golang/go#49263 Change-Id: I4bcea4a0b0097f3187f3d7055cbb73b518008107 Reviewed-on: https://go-review.googlesource.com/c/tools/+/361834 Trust: Suzy Mueller Run-TryBot: Suzy Mueller gopls-CI: kokoro TryBot-Result: Go Bot Reviewed-by: Robert Findley --- internal/lsp/code_action.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/lsp/code_action.go b/internal/lsp/code_action.go index b58e954030..526d279bb9 100644 --- a/internal/lsp/code_action.go +++ b/internal/lsp/code_action.go @@ -51,7 +51,12 @@ func (s *Server) codeAction(ctx context.Context, params *protocol.CodeActionPara } else { wanted = make(map[protocol.CodeActionKind]bool) for _, only := range params.Context.Only { - wanted[only] = supportedCodeActions[only] || explicit[only] + for k, v := range supportedCodeActions { + if only == k || strings.HasPrefix(string(k), string(only)+".") { + wanted[k] = wanted[k] || v + } + } + wanted[only] = wanted[only] || explicit[only] } } if len(supportedCodeActions) == 0 {