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

Commit ffe508d

Browse files
author
Henry Wong
authored
Merge b876567 into bf4dec8
2 parents bf4dec8 + b876567 commit ffe508d

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

go/packages/golist.go

+6
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,12 @@ 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. Separate it from the cache
657+
// mechanism.
658+
if cfg.Mode&(NeedImports|NeedTypes|NeedSyntax|NeedTypesInfo) != 0 {
659+
res, err := golistDriver(cfg, rootsDirs, words...)
660+
return res, err
661+
}
656662
if val, ok := goListLRUCache.Get(hashKey); ok {
657663
res := val.(goListResult)
658664
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 to load the packages for current file. This time won't parse the imports and anything related to
90+
// the dependencies.
91+
if len(pkgs) == 0 {
92+
cfg := v.Config(ctx)
93+
cfg.Tests = false
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)