mirror of https://github.com/golang/go.git
internal/lsp: use the analyzer's pointer instead of name
Analyzer names are not guaranteed to be unique. Change-Id: I4d4cc9fa746cbfbea9926f2cae0eb5dfc41027a5 Reviewed-on: https://go-review.googlesource.com/c/tools/+/201217 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
parent
f936694f27
commit
9c6d90b5a7
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue