From 342ee1054f63741a619c7a66a27b65fe215860d4 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Fri, 24 Jul 2020 02:45:47 -0400 Subject: [PATCH] internal/lsp: check URIs of all workspace folders We can prevent crashing on non-file URIs by checking the URIs of the workspace folders, as well as the root URI. Updates golang/go#40272 Change-Id: Ieddc6d6053fbb3d61e4c26fc8831c092328f6f33 Reviewed-on: https://go-review.googlesource.com/c/tools/+/244602 Run-TryBot: Rebecca Stambler TryBot-Result: Gobot Gobot Reviewed-by: Heschi Kreinick --- internal/lsp/general.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/lsp/general.go b/internal/lsp/general.go index dacce21351..003aef7cff 100644 --- a/internal/lsp/general.go +++ b/internal/lsp/general.go @@ -41,9 +41,18 @@ func (s *Server) initialize(ctx context.Context, params *protocol.ParamInitializ source.SetOptions(&options, params.InitializationOptions) options.ForClientCapabilities(params.Capabilities) + // gopls only supports URIs with a file:// scheme. Any other URIs will not + // work, so fail to initialize. See golang/go#40272. if params.RootURI != "" && !params.RootURI.SpanURI().IsFile() { return nil, fmt.Errorf("unsupported URI scheme: %v (gopls only supports file URIs)", params.RootURI) } + for _, folder := range params.WorkspaceFolders { + uri := span.URIFromURI(folder.URI) + if !uri.IsFile() { + return nil, fmt.Errorf("unsupported URI scheme: %q (gopls only supports file URIs)", folder.URI) + } + } + s.pendingFolders = params.WorkspaceFolders if len(s.pendingFolders) == 0 { if params.RootURI != "" {