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

[elastic] Try invoke 'go list ...' again if we get nothing from… #85

Merged
Merged
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
5 changes: 5 additions & 0 deletions go/packages/golist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions internal/lsp/cache/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down