gopls/internal/lsp/cache: remove nested module warning
The "you are working in a nested module" warning is often misleading,
and is now redundant with the more accurate orphaned file diagnostics
added in https://go.dev/cl/494675. Remove it.
Change-Id: I22b506de914702adea98449f5e166a6dff06e045
Reviewed-on: https://go-review.googlesource.com/c/tools/+/497956
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
diff --git a/gopls/internal/lsp/cache/load.go b/gopls/internal/lsp/cache/load.go
index 111b074..939d084 100644
--- a/gopls/internal/lsp/cache/load.go
+++ b/gopls/internal/lsp/cache/load.go
@@ -378,53 +378,6 @@
return fmt.Errorf(msg), s.applyCriticalErrorToFiles(ctx, msg, openFiles)
}
- // If the user has one active go.mod file, they may still be editing files
- // in nested modules. Check the module of each open file and add warnings
- // that the nested module must be opened as a workspace folder.
- if len(s.workspaceModFiles) == 1 {
- // Get the active root go.mod file to compare against.
- var rootMod string
- for uri := range s.workspaceModFiles {
- rootMod = uri.Filename()
- }
- rootDir := filepath.Dir(rootMod)
- nestedModules := make(map[string][]*Overlay)
- for _, fh := range openFiles {
- mod, err := findRootPattern(ctx, filepath.Dir(fh.URI().Filename()), "go.mod", s)
- if err != nil {
- if ctx.Err() != nil {
- return ctx.Err(), nil
- }
- continue
- }
- if mod == "" {
- continue
- }
- if mod != rootMod && source.InDir(rootDir, mod) {
- modDir := filepath.Dir(mod)
- nestedModules[modDir] = append(nestedModules[modDir], fh)
- }
- }
- var multiModuleMsg string
- if s.view.goversion >= 18 {
- multiModuleMsg = `To work on multiple modules at once, please use a go.work file.
-See https://github.com/golang/tools/blob/master/gopls/doc/workspace.md for more information on using workspaces.`
- } else {
- multiModuleMsg = `To work on multiple modules at once, please upgrade to Go 1.18 and use a go.work file.
-See https://github.com/golang/tools/blob/master/gopls/doc/workspace.md for more information on using workspaces.`
- }
- // 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 srcDiags []*source.Diagnostic
- for modDir, files := range nestedModules {
- msg := fmt.Sprintf("This file is in %s, which is a nested module in the %s module.\n%s", modDir, rootMod, multiModuleMsg)
- srcDiags = append(srcDiags, s.applyCriticalErrorToFiles(ctx, msg, files)...)
- }
- if len(srcDiags) != 0 {
- return fmt.Errorf("You have opened a nested module.\n%s", multiModuleMsg), srcDiags
- }
- }
return nil, nil
}
diff --git a/gopls/internal/regtest/diagnostics/diagnostics_test.go b/gopls/internal/regtest/diagnostics/diagnostics_test.go
index c765cb0..de675a5 100644
--- a/gopls/internal/regtest/diagnostics/diagnostics_test.go
+++ b/gopls/internal/regtest/diagnostics/diagnostics_test.go
@@ -1701,8 +1701,7 @@
env.OpenFile("nested/hello/hello.go")
env.AfterChange(
Diagnostics(env.AtRegexp("nested/hello/hello.go", "helloHelper")),
- Diagnostics(env.AtRegexp("nested/hello/hello.go", "package hello"), WithMessage("nested module")),
- OutstandingWork(lsp.WorkspaceLoadFailure, "nested module"),
+ Diagnostics(env.AtRegexp("nested/hello/hello.go", "package (hello)"), WithMessage("not included in your workspace")),
)
})
}
diff --git a/gopls/internal/regtest/workspace/workspace_test.go b/gopls/internal/regtest/workspace/workspace_test.go
index 88f9f2c..02e3a8c 100644
--- a/gopls/internal/regtest/workspace/workspace_test.go
+++ b/gopls/internal/regtest/workspace/workspace_test.go
@@ -1054,7 +1054,7 @@
// package declaration.
env.AfterChange(
NoDiagnostics(ForFile("main.go")),
- Diagnostics(AtPosition("b/main.go", 0, 0)),
+ Diagnostics(env.AtRegexp("b/main.go", "package (main)")),
)
env.WriteWorkspaceFile("go.work", `go 1.16
@@ -1080,7 +1080,7 @@
env.AfterChange(
NoDiagnostics(ForFile("main.go")),
- Diagnostics(AtPosition("b/main.go", 0, 0)),
+ Diagnostics(env.AtRegexp("b/main.go", "package (main)")),
)
})
}