internal/lsp/cache: fix module paths in nested module error messages
The existing test didn't catch it because it doesn't look for specific
warning messages.
Change-Id: I1ec7f7a75c1055c960cdd7545331c2fd655e3aa8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/281860
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
diff --git a/internal/lsp/cache/load.go b/internal/lsp/cache/load.go
index d73a0d5..fb328b8 100644
--- a/internal/lsp/cache/load.go
+++ b/internal/lsp/cache/load.go
@@ -220,23 +220,24 @@
for uri := range s.workspace.getActiveModFiles() {
rootModURI = uri
}
- nestedModules := map[span.URI][]source.VersionedFileHandle{}
+ nestedModules := map[string][]source.VersionedFileHandle{}
for _, fh := range openFiles {
modURI := moduleForURI(s.workspace.knownModFiles, fh.URI())
if modURI != rootModURI {
- nestedModules[modURI] = append(nestedModules[modURI], fh)
+ modDir := filepath.Dir(modURI.Filename())
+ nestedModules[modDir] = append(nestedModules[modDir], fh)
}
}
// Add a diagnostic to each file in a nested module to mark it as
// "orphaned". Don't show a general diagnostic in the progress bar,
// because the user may still want to edit a file in a nested module.
var srcErrs []*source.Error
- for modURI, uris := range nestedModules {
+ for modDir, uris := range nestedModules {
msg := fmt.Sprintf(`This file is in %s, which is a nested module in the %s module.
gopls currently requires one module per workspace folder.
Please open %s as a separate workspace folder.
You can learn more here: https://github.com/golang/go/issues/36899.
-`, modURI.Filename(), rootModURI.Filename(), modURI.Filename())
+`, modDir, filepath.Dir(rootModURI.Filename()), modDir)
srcErrs = append(srcErrs, s.applyCriticalErrorToFiles(ctx, msg, uris)...)
}
if len(srcErrs) != 0 {