internal/lsp: key GC details off package ID
Rather than using the directory of the package, store the package ID and
calculate the directory in GCOptimizationDetails. I think this is
slightly more readable/cleaner.
Change-Id: I13cac8a7552b73b2bd5d25ff582b5d4936a74827
Reviewed-on: https://go-review.googlesource.com/c/tools/+/297877
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
diff --git a/internal/lsp/command.go b/internal/lsp/command.go
index edcff12..1960270 100644
--- a/internal/lsp/command.go
+++ b/internal/lsp/command.go
@@ -613,13 +613,16 @@
progress: "Toggling GC Details",
forURI: args.URI,
}, func(ctx context.Context, deps commandDeps) error {
- pkgDir := span.URIFromPath(filepath.Dir(args.URI.SpanURI().Filename()))
+ pkg, err := deps.snapshot.PackageForFile(ctx, deps.fh.URI(), source.TypecheckWorkspace, source.NarrowestPackage)
+ if err != nil {
+ return err
+ }
c.s.gcOptimizationDetailsMu.Lock()
- if _, ok := c.s.gcOptimizationDetails[pkgDir]; ok {
- delete(c.s.gcOptimizationDetails, pkgDir)
+ if _, ok := c.s.gcOptimizationDetails[pkg.ID()]; ok {
+ delete(c.s.gcOptimizationDetails, pkg.ID())
c.s.clearDiagnosticSource(gcDetailsSource)
} else {
- c.s.gcOptimizationDetails[pkgDir] = struct{}{}
+ c.s.gcOptimizationDetails[pkg.ID()] = struct{}{}
}
c.s.gcOptimizationDetailsMu.Unlock()
c.s.diagnoseSnapshot(deps.snapshot, nil, false)