From 3e17c62e37b686d70c24a370a51cd33f8aa52df2 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Fri, 30 Apr 2021 17:15:57 -0400 Subject: [PATCH] internal/lsp: warn users who have built gopls with go-diff v1.2.0 I considered having gopls not initialize at all, but VS Code Go intercepts those error messages and they get buried. We should probably fix that in VS Code Go, but for now just show a warning. Updates golang/go#45732 Change-Id: I214974e5a96231c96b1583af8ac245de03cea5d8 Reviewed-on: https://go-review.googlesource.com/c/tools/+/315852 Trust: Rebecca Stambler Run-TryBot: Rebecca Stambler Reviewed-by: Robert Findley gopls-CI: kokoro TryBot-Result: Go Bot --- internal/lsp/general.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/internal/lsp/general.go b/internal/lsp/general.go index 6603e47c12..7165db9b89 100644 --- a/internal/lsp/general.go +++ b/internal/lsp/general.go @@ -96,7 +96,24 @@ func (s *Server) initialize(ctx context.Context, params *protocol.ParamInitializ } } - goplsVersion, err := json.Marshal(debug.VersionInfo()) + versionInfo := debug.VersionInfo() + + // golang/go#45732: Warn users who've installed sergi/go-diff@v1.2.0, since + // it will corrupt the formatting of their files. + for _, dep := range versionInfo.Deps { + if dep.Path == "github.com/sergi/go-diff" && dep.Version == "v1.2.0" { + if err := s.eventuallyShowMessage(ctx, &protocol.ShowMessageParams{ + Message: `It looks like you have a bad gopls installation. +Please reinstall gopls by running 'GO111MODULE=on go get golang.org/x/tools/gopls@latest'. +See https://github.com/golang/go/issues/45732 for more information.`, + Type: protocol.Error, + }); err != nil { + return nil, err + } + } + } + + goplsVersion, err := json.Marshal(versionInfo) if err != nil { return nil, err }