Skip to content

Commit 9c97539

Browse files
committed
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>
1 parent d44a094 commit 9c97539

File tree

3 files changed

+3
-51
lines changed

3 files changed

+3
-51
lines changed

gopls/internal/lsp/cache/load.go

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -378,53 +378,6 @@ https://github.com/golang/tools/blob/master/gopls/doc/workspace.md.`
378378
return fmt.Errorf(msg), s.applyCriticalErrorToFiles(ctx, msg, openFiles)
379379
}
380380

381-
// If the user has one active go.mod file, they may still be editing files
382-
// in nested modules. Check the module of each open file and add warnings
383-
// that the nested module must be opened as a workspace folder.
384-
if len(s.workspaceModFiles) == 1 {
385-
// Get the active root go.mod file to compare against.
386-
var rootMod string
387-
for uri := range s.workspaceModFiles {
388-
rootMod = uri.Filename()
389-
}
390-
rootDir := filepath.Dir(rootMod)
391-
nestedModules := make(map[string][]*Overlay)
392-
for _, fh := range openFiles {
393-
mod, err := findRootPattern(ctx, filepath.Dir(fh.URI().Filename()), "go.mod", s)
394-
if err != nil {
395-
if ctx.Err() != nil {
396-
return ctx.Err(), nil
397-
}
398-
continue
399-
}
400-
if mod == "" {
401-
continue
402-
}
403-
if mod != rootMod && source.InDir(rootDir, mod) {
404-
modDir := filepath.Dir(mod)
405-
nestedModules[modDir] = append(nestedModules[modDir], fh)
406-
}
407-
}
408-
var multiModuleMsg string
409-
if s.view.goversion >= 18 {
410-
multiModuleMsg = `To work on multiple modules at once, please use a go.work file.
411-
See https://github.com/golang/tools/blob/master/gopls/doc/workspace.md for more information on using workspaces.`
412-
} else {
413-
multiModuleMsg = `To work on multiple modules at once, please upgrade to Go 1.18 and use a go.work file.
414-
See https://github.com/golang/tools/blob/master/gopls/doc/workspace.md for more information on using workspaces.`
415-
}
416-
// Add a diagnostic to each file in a nested module to mark it as
417-
// "orphaned". Don't show a general diagnostic in the progress bar,
418-
// because the user may still want to edit a file in a nested module.
419-
var srcDiags []*source.Diagnostic
420-
for modDir, files := range nestedModules {
421-
msg := fmt.Sprintf("This file is in %s, which is a nested module in the %s module.\n%s", modDir, rootMod, multiModuleMsg)
422-
srcDiags = append(srcDiags, s.applyCriticalErrorToFiles(ctx, msg, files)...)
423-
}
424-
if len(srcDiags) != 0 {
425-
return fmt.Errorf("You have opened a nested module.\n%s", multiModuleMsg), srcDiags
426-
}
427-
}
428381
return nil, nil
429382
}
430383

gopls/internal/regtest/diagnostics/diagnostics_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,8 +1701,7 @@ func helloHelper() {}
17011701
env.OpenFile("nested/hello/hello.go")
17021702
env.AfterChange(
17031703
Diagnostics(env.AtRegexp("nested/hello/hello.go", "helloHelper")),
1704-
Diagnostics(env.AtRegexp("nested/hello/hello.go", "package hello"), WithMessage("nested module")),
1705-
OutstandingWork(lsp.WorkspaceLoadFailure, "nested module"),
1704+
Diagnostics(env.AtRegexp("nested/hello/hello.go", "package (hello)"), WithMessage("not included in your workspace")),
17061705
)
17071706
})
17081707
}

gopls/internal/regtest/workspace/workspace_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ func main() {}
10541054
// package declaration.
10551055
env.AfterChange(
10561056
NoDiagnostics(ForFile("main.go")),
1057-
Diagnostics(AtPosition("b/main.go", 0, 0)),
1057+
Diagnostics(env.AtRegexp("b/main.go", "package (main)")),
10581058
)
10591059
env.WriteWorkspaceFile("go.work", `go 1.16
10601060
@@ -1080,7 +1080,7 @@ use (
10801080

10811081
env.AfterChange(
10821082
NoDiagnostics(ForFile("main.go")),
1083-
Diagnostics(AtPosition("b/main.go", 0, 0)),
1083+
Diagnostics(env.AtRegexp("b/main.go", "package (main)")),
10841084
)
10851085
})
10861086
}

0 commit comments

Comments
 (0)