1
0
mirror of https://github.com/golang/go synced 2024-11-18 12:44:49 -07:00

internal/lsp: don't clear file contents on save

CL 212037 introduced a bug with saving overlays. Since VS Code sends nil
contents for a file on save, we were deleting overlay contents on save.
This resulted in very strange behavior.

Also rename overlay.data to overlay.text to match variable names.

Fixes golang/go#36224

Change-Id: I7f2d12e369aa7f6daa2c9f36c33468ec6bf61930
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212199
Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
Rebecca Stambler 2019-12-19 17:50:08 -05:00
parent 145a1e401f
commit 5e752206af
2 changed files with 11 additions and 7 deletions

View File

@ -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,
}

View File

@ -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
}