diff --git a/internal/lsp/cache/debug.go b/internal/lsp/cache/debug.go index 6f670b0799..95d3fa21e2 100644 --- a/internal/lsp/cache/debug.go +++ b/internal/lsp/cache/debug.go @@ -32,7 +32,7 @@ func (s debugSession) Files() []*debug.File { seen[overlay.uri] = f files = append(files, f) } - f.Data = string(overlay.data) + f.Data = string(overlay.text) f.Error = nil f.Hash = overlay.hash } @@ -50,7 +50,7 @@ func (s debugSession) File(hash string) *debug.File { return &debug.File{ Session: s, URI: overlay.uri, - Data: string(overlay.data), + Data: string(overlay.text), Error: nil, Hash: overlay.hash, } diff --git a/internal/lsp/cache/overlay.go b/internal/lsp/cache/overlay.go index 96e36e5afb..8e6b794cf2 100644 --- a/internal/lsp/cache/overlay.go +++ b/internal/lsp/cache/overlay.go @@ -15,7 +15,7 @@ import ( type overlay struct { session *session uri span.URI - data []byte + text []byte hash string version float64 kind source.FileKind @@ -38,7 +38,7 @@ func (o *overlay) Identity() source.FileIdentity { } } func (o *overlay) Read(ctx context.Context) ([]byte, string, error) { - return o.data, o.hash, nil + return o.text, o.hash, nil } func (s *session) updateOverlay(ctx context.Context, c source.FileModification) error { @@ -69,7 +69,11 @@ func (s *session) updateOverlay(ctx context.Context, c source.FileModification) } // If the file is on disk, check if its content is the same as the overlay. - hash := hashContents(c.Text) + text := c.Text + if text == nil { + text = o.text + } + hash := hashContents(text) var sameContentOnDisk bool switch c.Action { case source.Open: @@ -88,8 +92,8 @@ func (s *session) updateOverlay(ctx context.Context, c source.FileModification) s.overlays[c.URI] = &overlay{ session: s, uri: c.URI, - data: c.Text, version: c.Version, + text: text, kind: kind, hash: hash, sameContentOnDisk: sameContentOnDisk, @@ -118,7 +122,7 @@ func (s *session) buildOverlay() map[string][]byte { if overlay.sameContentOnDisk { continue } - overlays[uri.Filename()] = overlay.data + overlays[uri.Filename()] = overlay.text } return overlays }