Skip to content

Commit 0248714

Browse files
findleyrgopherbot
authored andcommitted
internal/lsp: add additional instrumentation around package loading
Add some additional logging to help debug golang/go#53586 For golang/go#53586 Change-Id: I0574fb01be47b265cd6e412855794bc2cb836dff Reviewed-on: https://go-review.googlesource.com/c/tools/+/414854 gopls-CI: kokoro <[email protected]> Reviewed-by: Alan Donovan <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Robert Findley <[email protected]> Auto-Submit: Robert Findley <[email protected]>
1 parent e5b3324 commit 0248714

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

internal/lsp/cache/load.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"path/filepath"
1616
"sort"
1717
"strings"
18+
"sync/atomic"
1819
"time"
1920

2021
"golang.org/x/tools/go/packages"
@@ -28,12 +29,17 @@ import (
2829
"golang.org/x/tools/internal/span"
2930
)
3031

32+
var loadID uint64 // atomic identifier for loads
33+
3134
// load calls packages.Load for the given scopes, updating package metadata,
3235
// import graph, and mapped files with the result.
3336
//
3437
// The resulting error may wrap the moduleErrorMap error type, representing
3538
// errors associated with specific modules.
3639
func (s *snapshot) load(ctx context.Context, allowNetwork bool, scopes ...interface{}) (err error) {
40+
id := atomic.AddUint64(&loadID, 1)
41+
eventName := fmt.Sprintf("go/packages.Load #%d", id) // unique name for logging
42+
3743
var query []string
3844
var containsDir bool // for logging
3945

@@ -138,9 +144,9 @@ func (s *snapshot) load(ctx context.Context, allowNetwork bool, scopes ...interf
138144
return ctx.Err()
139145
}
140146
if err != nil {
141-
event.Error(ctx, "go/packages.Load", err, tag.Snapshot.Of(s.ID()), tag.Directory.Of(cfg.Dir), tag.Query.Of(query), tag.PackageCount.Of(len(pkgs)))
147+
event.Error(ctx, eventName, err, tag.Snapshot.Of(s.ID()), tag.Directory.Of(cfg.Dir), tag.Query.Of(query), tag.PackageCount.Of(len(pkgs)))
142148
} else {
143-
event.Log(ctx, "go/packages.Load", tag.Snapshot.Of(s.ID()), tag.Directory.Of(cfg.Dir), tag.Query.Of(query), tag.PackageCount.Of(len(pkgs)))
149+
event.Log(ctx, eventName, tag.Snapshot.Of(s.ID()), tag.Directory.Of(cfg.Dir), tag.Query.Of(query), tag.PackageCount.Of(len(pkgs)))
144150
}
145151
if len(pkgs) == 0 {
146152
if err == nil {
@@ -168,7 +174,7 @@ func (s *snapshot) load(ctx context.Context, allowNetwork bool, scopes ...interf
168174
}
169175

170176
if !containsDir || s.view.Options().VerboseOutput {
171-
event.Log(ctx, "go/packages.Load",
177+
event.Log(ctx, eventName,
172178
tag.Snapshot.Of(s.ID()),
173179
tag.Package.Of(pkg.ID),
174180
tag.Files.Of(pkg.CompiledGoFiles))
@@ -209,6 +215,8 @@ func (s *snapshot) load(ctx context.Context, allowNetwork bool, scopes ...interf
209215
loadedIDs = append(loadedIDs, id)
210216
}
211217

218+
event.Log(ctx, fmt.Sprintf("%s: updating metadata for %d packages", eventName, len(updates)))
219+
212220
s.mu.Lock()
213221

214222
// invalidate the reverse transitive closure of packages that have changed.

internal/lsp/source/completion/completion.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ func Completion(ctx context.Context, snapshot source.Snapshot, fh source.FileHan
441441
items, surrounding, innerErr := packageClauseCompletions(ctx, snapshot, fh, protoPos)
442442
if innerErr != nil {
443443
// return the error for GetParsedFile since it's more relevant in this situation.
444-
return nil, nil, fmt.Errorf("getting file for Completion: %w (package completions: %v)", err, innerErr)
444+
return nil, nil, fmt.Errorf("getting file %s for Completion: %w (package completions: %v)", fh.URI(), err, innerErr)
445445
}
446446
return items, surrounding, nil
447447
}

0 commit comments

Comments
 (0)