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>
diff --git a/internal/lsp/general.go b/internal/lsp/general.go
index dacce21..003aef7 100644
--- a/internal/lsp/general.go
+++ b/internal/lsp/general.go
@@ -41,9 +41,18 @@
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 != "" {