mirror of
https://github.com/golang/go
synced 2024-11-18 16:34:51 -07:00
internal/lsp/cache: include session IDs in some cache keys
When caching file data specific to a session (anything with a Version or tied to a view), we now need to be more careful about the existence of multiple sessions. This change fixes a few places where we appear to cache session data without explicitly referring to the session. In principal this could cause data corruption in multi-session gopls instances, but I have not been able to force this to occur in either manual or automated testing. Also fix a data race to the unsaved overlays: https://storage.googleapis.com/go-build-log/588ee798/linux-amd64-race_d0762522.log Updates golang/go#34111 Change-Id: I47117da1aba1afc2e211785544ad3f8b3416d15d Reviewed-on: https://go-review.googlesource.com/c/tools/+/222059 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rohan Challa <rohan@golang.org>
This commit is contained in:
parent
6a641547f5
commit
bc073721ad
21
internal/lsp/cache/mod.go
vendored
21
internal/lsp/cache/mod.go
vendored
@ -32,12 +32,14 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type modKey struct {
|
type modKey struct {
|
||||||
cfg string
|
sessionID string
|
||||||
gomod string
|
cfg string
|
||||||
view string
|
gomod string
|
||||||
|
view string
|
||||||
}
|
}
|
||||||
|
|
||||||
type modTidyKey struct {
|
type modTidyKey struct {
|
||||||
|
sessionID string
|
||||||
cfg string
|
cfg string
|
||||||
gomod string
|
gomod string
|
||||||
imports string
|
imports string
|
||||||
@ -137,9 +139,10 @@ func (s *snapshot) ModHandle(ctx context.Context, fh source.FileHandle) source.M
|
|||||||
cfg := s.Config(ctx)
|
cfg := s.Config(ctx)
|
||||||
|
|
||||||
key := modKey{
|
key := modKey{
|
||||||
cfg: hashConfig(cfg),
|
sessionID: s.view.session.id,
|
||||||
gomod: fh.Identity().String(),
|
cfg: hashConfig(cfg),
|
||||||
view: folder,
|
gomod: fh.Identity().String(),
|
||||||
|
view: folder,
|
||||||
}
|
}
|
||||||
h := s.view.session.cache.store.Bind(key, func(ctx context.Context) interface{} {
|
h := s.view.session.cache.store.Bind(key, func(ctx context.Context) interface{} {
|
||||||
ctx, done := trace.StartSpan(ctx, "cache.ModHandle", telemetry.File.Of(uri))
|
ctx, done := trace.StartSpan(ctx, "cache.ModHandle", telemetry.File.Of(uri))
|
||||||
@ -295,10 +298,14 @@ func (s *snapshot) ModTidyHandle(ctx context.Context, realfh source.FileHandle)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
s.mu.Lock()
|
||||||
|
overlayHash := hashUnsavedOverlays(s.files)
|
||||||
|
s.mu.Unlock()
|
||||||
key := modTidyKey{
|
key := modTidyKey{
|
||||||
|
sessionID: s.view.session.id,
|
||||||
view: folder,
|
view: folder,
|
||||||
imports: imports,
|
imports: imports,
|
||||||
unsavedOverlays: hashUnsavedOverlays(s.files),
|
unsavedOverlays: overlayHash,
|
||||||
gomod: realfh.Identity().Identifier,
|
gomod: realfh.Identity().Identifier,
|
||||||
cfg: hashConfig(cfg),
|
cfg: hashConfig(cfg),
|
||||||
}
|
}
|
||||||
|
1
internal/lsp/cache/session.go
vendored
1
internal/lsp/cache/session.go
vendored
@ -54,6 +54,7 @@ func (o *overlay) Identity() source.FileIdentity {
|
|||||||
return source.FileIdentity{
|
return source.FileIdentity{
|
||||||
URI: o.uri,
|
URI: o.uri,
|
||||||
Identifier: o.hash,
|
Identifier: o.hash,
|
||||||
|
SessionID: o.session.id,
|
||||||
Version: o.version,
|
Version: o.version,
|
||||||
Kind: o.kind,
|
Kind: o.kind,
|
||||||
}
|
}
|
||||||
|
@ -327,7 +327,11 @@ type FileHandle interface {
|
|||||||
type FileIdentity struct {
|
type FileIdentity struct {
|
||||||
URI span.URI
|
URI span.URI
|
||||||
|
|
||||||
// Version is the version of the file, as specified by the client.
|
// SessionID is the ID of the LSP session.
|
||||||
|
SessionID string
|
||||||
|
|
||||||
|
// Version is the version of the file, as specified by the client. It should
|
||||||
|
// only be set in combination with SessionID.
|
||||||
Version float64
|
Version float64
|
||||||
|
|
||||||
// Identifier represents a unique identifier for the file.
|
// Identifier represents a unique identifier for the file.
|
||||||
|
Loading…
Reference in New Issue
Block a user