Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gopls/internal/cache: more helpful message for non-required modules #471

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions gopls/internal/cache/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"golang.org/x/mod/module"
"golang.org/x/sync/errgroup"
"golang.org/x/tools/go/ast/astutil"
"golang.org/x/tools/gopls/internal/file"
"golang.org/x/tools/gopls/internal/filecache"
"golang.org/x/tools/gopls/internal/cache/metadata"
"golang.org/x/tools/gopls/internal/cache/typerefs"
"golang.org/x/tools/gopls/internal/file"
"golang.org/x/tools/gopls/internal/filecache"
"golang.org/x/tools/gopls/internal/protocol"
"golang.org/x/tools/gopls/internal/util/bug"
"golang.org/x/tools/gopls/internal/util/safetoken"
Expand Down Expand Up @@ -1757,7 +1757,7 @@ func missingPkgError(from PackageID, pkgPath string, moduleMode bool) error {
return fmt.Errorf("current file is not included in a workspace module")
} else {
// Previously, we would present the initialization error here.
return fmt.Errorf("no required module provides package %q", pkgPath)
return fmt.Errorf("package %q does not exist under go.mod in required modules, try running `go mod tidy`", pkgPath)
}
} else {
// Previously, we would list the directories in GOROOT and GOPATH here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,10 @@ func main() {
env.SaveBuffer("main.go")
var d protocol.PublishDiagnosticsParams
env.AfterChange(
Diagnostics(env.AtRegexp("main.go", `"github.com/ardanlabs/conf"`), WithMessage("no required module")),
Diagnostics(
env.AtRegexp("main.go", `"github.com/ardanlabs/conf"`),
WithMessage("does not exist under go.mod in required modules, try running `go mod tidy`"),
),
ReadDiagnostics("main.go", &d),
)
env.ApplyQuickFixes("main.go", d.Diagnostics)
Expand Down Expand Up @@ -1711,7 +1714,7 @@ import (
Run(t, mod, func(t *testing.T, env *Env) {
env.OnceMet(
InitialWorkspaceLoad,
Diagnostics(env.AtRegexp("main.go", `"nosuchpkg"`), WithMessage(`could not import nosuchpkg (no required module provides package "nosuchpkg"`)),
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`)")),
)
})
})
Expand Down
2 changes: 1 addition & 1 deletion gopls/internal/test/integration/modfile/modfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ func main() {
env.AfterChange(
Diagnostics(
env.AtRegexp("main.go", `"example.com/blah"`),
WithMessage(`could not import example.com/blah (no required module provides package "example.com/blah")`),
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`)"),
),
ReadDiagnostics("main.go", d),
)
Expand Down