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 <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
Rebecca Stambler 2020-07-24 02:45:47 -04:00
parent e7a7e3a8a0
commit 342ee1054f
1 changed files with 9 additions and 0 deletions

View File

@ -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 != "" {