diff --git a/go/packages/golist.go b/go/packages/golist.go index b6f3365ad12..65523eef89c 100644 --- a/go/packages/golist.go +++ b/go/packages/golist.go @@ -653,6 +653,11 @@ func golistDriverLRUCached(cfg *Config, rootsDirs func() *goInfo, words ...strin h.Write([]byte(cfg.Dir)) h.Write([]byte(words[len(words)-1])) hashKey := h.Sum32() + // If this is a temporary `go list ...` invoke, i.e. without deps information query. Don't entangle it with the go + // list cache. + if cfg.Mode&(NeedImports|NeedTypes|NeedSyntax|NeedTypesInfo) == 0 { + return golistDriver(cfg, rootsDirs, words...) + } if val, ok := goListLRUCache.Get(hashKey); ok { res := val.(goListResult) return res.response, res.err diff --git a/internal/lsp/cache/load.go b/internal/lsp/cache/load.go index ae095f1746a..c6af7aeb94c 100644 --- a/internal/lsp/cache/load.go +++ b/internal/lsp/cache/load.go @@ -86,6 +86,16 @@ func (v *view) checkMetadata(ctx context.Context, f *goFile) (map[packageID]*met ctx, done := trace.StartSpan(ctx, "packages.Load", telemetry.File.Of(f.filename())) defer done() pkgs, err := packages.Load(v.Config(ctx), fmt.Sprintf("file=%s", f.filename())) + // Give another try with loose mode to load the packages for current file. + if len(pkgs) == 0 { + cfg := v.Config(ctx) + cfg.Tests = false + // Remove any dependency require mode. + cfg.Mode = packages.NeedName | + packages.NeedFiles | + packages.NeedCompiledGoFiles + pkgs, err = packages.Load(cfg, fmt.Sprintf("file=%s", f.filename())) + } if len(pkgs) == 0 { if err == nil { err = errors.Errorf("go/packages.Load: no packages found for %s", f.filename())