diff --git a/internal/lsp/cache/analysis.go b/internal/lsp/cache/analysis.go index 28956b2a83..0159e179c1 100644 --- a/internal/lsp/cache/analysis.go +++ b/internal/lsp/cache/analysis.go @@ -17,11 +17,6 @@ import ( errors "golang.org/x/xerrors" ) -type actionKey struct { - pkg packageKey - analyzer string // analyzer name -} - func (s *snapshot) Analyze(ctx context.Context, id string, analyzers []*analysis.Analyzer) (map[*analysis.Analyzer][]*analysis.Diagnostic, error) { var roots []*actionHandle @@ -84,7 +79,7 @@ type packageFactKey struct { } func (s *snapshot) actionHandle(ctx context.Context, id packageID, mode source.ParseMode, a *analysis.Analyzer) (*actionHandle, error) { - ah := s.getAction(id, mode, a.Name) + ah := s.getAction(id, mode, a) if ah != nil { return ah, nil } @@ -133,6 +128,7 @@ func (s *snapshot) actionHandle(ctx context.Context, id packageID, mode source.P return data }) ah.handle = h + s.addAction(ah) return ah, nil } @@ -147,7 +143,7 @@ func (ah *actionHandle) analyze(ctx context.Context) ([]*analysis.Diagnostic, in } func buildActionKey(a *analysis.Analyzer, cph *checkPackageHandle) string { - return hashContents([]byte(fmt.Sprintf("%s %s", a, string(cph.key)))) + return hashContents([]byte(fmt.Sprintf("%p %s", a, string(cph.key)))) } func (act *actionHandle) String() string { diff --git a/internal/lsp/cache/load.go b/internal/lsp/cache/load.go index cdbe9703a8..48b89f82c4 100644 --- a/internal/lsp/cache/load.go +++ b/internal/lsp/cache/load.go @@ -19,11 +19,6 @@ import ( errors "golang.org/x/xerrors" ) -type packageKey struct { - mode source.ParseMode - id packageID -} - type metadata struct { id packageID pkgPath packagePath diff --git a/internal/lsp/cache/snapshot.go b/internal/lsp/cache/snapshot.go index 856592e688..b0a3ffc54a 100644 --- a/internal/lsp/cache/snapshot.go +++ b/internal/lsp/cache/snapshot.go @@ -4,6 +4,7 @@ import ( "context" "sync" + "golang.org/x/tools/go/analysis" "golang.org/x/tools/internal/lsp/source" "golang.org/x/tools/internal/span" ) @@ -37,6 +38,16 @@ type snapshot struct { actions map[actionKey]*actionHandle } +type packageKey struct { + mode source.ParseMode + id packageID +} + +type actionKey struct { + pkg packageKey + analyzer *analysis.Analyzer +} + func (s *snapshot) View() source.View { return s.view } @@ -96,7 +107,7 @@ func (s *snapshot) getPackage(id packageID, m source.ParseMode) *checkPackageHan return s.packages[key] } -func (s *snapshot) getAction(id packageID, m source.ParseMode, analyzer string) *actionHandle { +func (s *snapshot) getAction(id packageID, m source.ParseMode, a *analysis.Analyzer) *actionHandle { s.mu.Lock() defer s.mu.Unlock() @@ -105,7 +116,7 @@ func (s *snapshot) getAction(id packageID, m source.ParseMode, analyzer string) id: id, mode: m, }, - analyzer: analyzer, + analyzer: a, } return s.actions[key] } @@ -115,7 +126,7 @@ func (s *snapshot) addAction(ah *actionHandle) { defer s.mu.Unlock() key := actionKey{ - analyzer: ah.analyzer.Name, + analyzer: ah.analyzer, pkg: packageKey{ id: ah.pkg.id, mode: ah.pkg.mode,