Skip to content

Commit

Permalink
add more helpful message when module is not in required modules
Browse files Browse the repository at this point in the history
  • Loading branch information
exapsy committed Jan 26, 2024
1 parent 3d49bd5 commit adde017
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
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

0 comments on commit adde017

Please sign in to comment.