Skip to content

Commit 351fb22

Browse files
committed
internal/lsp: invalidate directories if we have no direct IDs
Previously, we were only invalidating packages in directories if we didn't have a file handle. We should also invalidate if we have an unparseable file handle - that is, a file with no content or no package name. Fixes golang/go#36608. Change-Id: Ia12fad962c06ddeeac382185d3220961f5c584e0 Reviewed-on: https://go-review.googlesource.com/c/tools/+/215318 Run-TryBot: Rebecca Stambler <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 95ece92 commit 351fb22

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

internal/lsp/cache/load.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (s *snapshot) load(ctx context.Context, scopes ...interface{}) ([]*metadata
7474
return nil, ctx.Err()
7575
}
7676

77-
log.Print(ctx, "go/packages.Load", tag.Of("query", query), tag.Of("packages", len(pkgs)))
77+
log.Print(ctx, "go/packages.Load", tag.Of("snapshot", s.ID()), tag.Of("query", query), tag.Of("packages", len(pkgs)))
7878
if len(pkgs) == 0 {
7979
if err == nil {
8080
err = errors.Errorf("no packages found for query %s", query)

internal/lsp/cache/snapshot.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"context"
99
"os"
1010
"path/filepath"
11-
"strings"
1211
"sync"
1312

1413
"golang.org/x/tools/go/analysis"
@@ -629,10 +628,10 @@ func (s *snapshot) clone(ctx context.Context, withoutURI span.URI) *snapshot {
629628
// Make a rough estimate of what metadata to invalidate by finding the package IDs
630629
// of all of the files in the same directory as this one.
631630
// TODO(rstambler): Speed this up by mapping directories to filenames.
632-
if originalFH == nil {
633-
if dirStat, err := os.Stat(dir(withoutURI.Filename())); err == nil {
631+
if len(directIDs) == 0 {
632+
if dirStat, err := os.Stat(filepath.Dir(withoutURI.Filename())); err == nil {
634633
for uri := range s.files {
635-
if fdirStat, err := os.Stat(dir(uri.Filename())); err == nil {
634+
if fdirStat, err := os.Stat(filepath.Dir(uri.Filename())); err == nil {
636635
if os.SameFile(dirStat, fdirStat) {
637636
for _, id := range s.ids[uri] {
638637
directIDs[id] = struct{}{}
@@ -643,13 +642,6 @@ func (s *snapshot) clone(ctx context.Context, withoutURI span.URI) *snapshot {
643642
}
644643
}
645644

646-
// If there is no known FileHandle and no known IDs for the given file,
647-
// there is nothing to invalidate.
648-
if len(directIDs) == 0 && originalFH == nil {
649-
// TODO(heschi): clone anyway? Seems like this is just setting us up for trouble.
650-
return s
651-
}
652-
653645
// Invalidate reverse dependencies too.
654646
// TODO(heschi): figure out the locking model and use transitiveReverseDeps?
655647
transitiveIDs := make(map[packageID]struct{})
@@ -743,10 +735,6 @@ func (s *snapshot) clone(ctx context.Context, withoutURI span.URI) *snapshot {
743735
return result
744736
}
745737

746-
func dir(filename string) string {
747-
return strings.ToLower(filepath.Dir(filename))
748-
}
749-
750738
func (s *snapshot) ID() uint64 {
751739
return s.id
752740
}

0 commit comments

Comments
 (0)