Skip to content

Commit adde017

Browse files
committed
add more helpful message when module is not in required modules
1 parent 3d49bd5 commit adde017

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

gopls/internal/cache/check.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ import (
2222
"golang.org/x/mod/module"
2323
"golang.org/x/sync/errgroup"
2424
"golang.org/x/tools/go/ast/astutil"
25-
"golang.org/x/tools/gopls/internal/file"
26-
"golang.org/x/tools/gopls/internal/filecache"
2725
"golang.org/x/tools/gopls/internal/cache/metadata"
2826
"golang.org/x/tools/gopls/internal/cache/typerefs"
27+
"golang.org/x/tools/gopls/internal/file"
28+
"golang.org/x/tools/gopls/internal/filecache"
2929
"golang.org/x/tools/gopls/internal/protocol"
3030
"golang.org/x/tools/gopls/internal/util/bug"
3131
"golang.org/x/tools/gopls/internal/util/safetoken"
@@ -1757,7 +1757,7 @@ func missingPkgError(from PackageID, pkgPath string, moduleMode bool) error {
17571757
return fmt.Errorf("current file is not included in a workspace module")
17581758
} else {
17591759
// Previously, we would present the initialization error here.
1760-
return fmt.Errorf("no required module provides package %q", pkgPath)
1760+
return fmt.Errorf("package %q does not exist under go.mod in required modules, try running `go mod tidy`", pkgPath)
17611761
}
17621762
} else {
17631763
// Previously, we would list the directories in GOROOT and GOPATH here.

gopls/internal/test/integration/diagnostics/diagnostics_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,10 @@ func main() {
723723
env.SaveBuffer("main.go")
724724
var d protocol.PublishDiagnosticsParams
725725
env.AfterChange(
726-
Diagnostics(env.AtRegexp("main.go", `"github.com/ardanlabs/conf"`), WithMessage("no required module")),
726+
Diagnostics(
727+
env.AtRegexp("main.go", `"github.com/ardanlabs/conf"`),
728+
WithMessage("does not exist under go.mod in required modules, try running `go mod tidy`"),
729+
),
727730
ReadDiagnostics("main.go", &d),
728731
)
729732
env.ApplyQuickFixes("main.go", d.Diagnostics)
@@ -1711,7 +1714,7 @@ import (
17111714
Run(t, mod, func(t *testing.T, env *Env) {
17121715
env.OnceMet(
17131716
InitialWorkspaceLoad,
1714-
Diagnostics(env.AtRegexp("main.go", `"nosuchpkg"`), WithMessage(`could not import nosuchpkg (no required module provides package "nosuchpkg"`)),
1717+
Diagnostics(env.AtRegexp("main.go", `"nosuchpkg"`), WithMessage(`could not import nosuchpkg (package "nosuchpkg" does not exist under go.mod in required modules, try running `+"`go mod tidy`)")),
17151718
)
17161719
})
17171720
})

gopls/internal/test/integration/modfile/modfile_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ func main() {
10991099
env.AfterChange(
11001100
Diagnostics(
11011101
env.AtRegexp("main.go", `"example.com/blah"`),
1102-
WithMessage(`could not import example.com/blah (no required module provides package "example.com/blah")`),
1102+
WithMessage(`could not import example.com/blah (package "example.com/blah" does not exist under go.mod in required modules, try running `+"`go mod tidy`)"),
11031103
),
11041104
ReadDiagnostics("main.go", d),
11051105
)

0 commit comments

Comments
 (0)