Skip to content
This repository was archived by the owner on Jan 31, 2024. It is now read-only.

Commit e626746

Browse files
author
Henry Wong
authored
Merge 8e8ad48 into 37aa6c2
2 parents 37aa6c2 + 8e8ad48 commit e626746

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

go/packages/golist.go

+5
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,11 @@ func golistDriverLRUCached(cfg *Config, rootsDirs func() *goInfo, words ...strin
653653
h.Write([]byte(cfg.Dir))
654654
h.Write([]byte(words[len(words)-1]))
655655
hashKey := h.Sum32()
656+
// If this is a temporary `go list ...` invoke, i.e. without deps information query. Don't entangle it with the go
657+
// list cache.
658+
if cfg.Mode&(NeedImports|NeedTypes|NeedSyntax|NeedTypesInfo) == 0 {
659+
return golistDriver(cfg, rootsDirs, words...)
660+
}
656661
if val, ok := goListLRUCache.Get(hashKey); ok {
657662
res := val.(goListResult)
658663
return res.response, res.err

internal/lsp/cache/load.go

+10
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ func (v *view) checkMetadata(ctx context.Context, f *goFile) (map[packageID]*met
8686
ctx, done := trace.StartSpan(ctx, "packages.Load", telemetry.File.Of(f.filename()))
8787
defer done()
8888
pkgs, err := packages.Load(v.Config(ctx), fmt.Sprintf("file=%s", f.filename()))
89+
// Give another try with loose mode to load the packages for current file.
90+
if len(pkgs) == 0 {
91+
cfg := v.Config(ctx)
92+
cfg.Tests = false
93+
// Remove any dependency require mode.
94+
cfg.Mode = packages.NeedName |
95+
packages.NeedFiles |
96+
packages.NeedCompiledGoFiles
97+
pkgs, err = packages.Load(cfg, fmt.Sprintf("file=%s", f.filename()))
98+
}
8999
if len(pkgs) == 0 {
90100
if err == nil {
91101
err = errors.Errorf("go/packages.Load: no packages found for %s", f.filename())

0 commit comments

Comments
 (0)