From 01425d701627aeb19333a5ca68ec5478b23fcdb4 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Fri, 10 Jul 2020 20:17:16 -0400 Subject: [PATCH] internal/lsp/source: add Vendor to list of supported commands I wanted to add a regtest for this, but then immediately got stumped on how to do it well. The best I've got is to add a helper that wraps the client's call to executeCommand, but it's used in so many places that an easier fix was to put it in executeCommand itself. Fixes golang/go#40101 Change-Id: Iafb804fb77e57e6ac01e3de1d115058b21ac1954 Reviewed-on: https://go-review.googlesource.com/c/tools/+/241984 Reviewed-by: Robert Findley Reviewed-by: Heschi Kreinick --- internal/lsp/command.go | 11 +++++++++++ internal/lsp/source/options.go | 5 +++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/lsp/command.go b/internal/lsp/command.go index 98262586c9..f10b69a9b7 100644 --- a/internal/lsp/command.go +++ b/internal/lsp/command.go @@ -6,6 +6,7 @@ package lsp import ( "context" + "fmt" "io" "strings" @@ -17,6 +18,16 @@ import ( ) func (s *Server) executeCommand(ctx context.Context, params *protocol.ExecuteCommandParams) (interface{}, error) { + var found bool + for _, command := range s.session.Options().SupportedCommands { + if command == params.Command { + found = true + break + } + } + if !found { + return nil, fmt.Errorf("unsupported command detected: %s", params.Command) + } switch params.Command { case source.CommandTest: unsaved := false diff --git a/internal/lsp/source/options.go b/internal/lsp/source/options.go index b8fde36b01..6a2424295a 100644 --- a/internal/lsp/source/options.go +++ b/internal/lsp/source/options.go @@ -102,11 +102,12 @@ func DefaultOptions() Options { Sum: {}, }, SupportedCommands: []string{ + CommandGenerate, + CommandRegenerateCgo, CommandTest, CommandTidy, CommandUpgradeDependency, - CommandGenerate, - CommandRegenerateCgo, + CommandVendor, }, }, UserOptions: UserOptions{