internal/lsp: remove redundant didChange notifications

didSave notifications were triggering didChangeWatchedFiles, which in
turn were triggering didChange.

Change-Id: I74b0e3859aee2d8a4d971f2d4e4c91048cec2fc3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/298770
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Rebecca Stambler 2021-03-04 08:32:56 -10:00
parent 376db57240
commit 2cde57b5a5
1 changed files with 11 additions and 7 deletions

View File

@ -57,12 +57,12 @@ type CallCounts struct {
type buffer struct {
version int
path string
content []string
lines []string
dirty bool
}
func (b buffer) text() string {
return strings.Join(b.content, "\n")
return strings.Join(b.lines, "\n")
}
// EditorConfig configures the editor's LSP session. This is similar to
@ -334,6 +334,10 @@ func (e *Editor) onFileChanges(ctx context.Context, evts []FileEvent) {
if err != nil {
continue // A race with some other operation.
}
// No need to update if the buffer content hasn't changed.
if content == strings.Join(buf.lines, "\n") {
continue
}
// During shutdown, this call will fail. Ignore the error.
_ = e.setBufferContentLocked(ctx, evt.Path, false, strings.Split(content, "\n"), nil)
}
@ -378,7 +382,7 @@ func (e *Editor) createBuffer(ctx context.Context, path string, dirty bool, cont
buf := buffer{
version: 1,
path: path,
content: strings.Split(content, "\n"),
lines: strings.Split(content, "\n"),
dirty: dirty,
}
e.mu.Lock()
@ -640,8 +644,8 @@ func (e *Editor) editBufferLocked(ctx context.Context, path string, edits []Edit
if !ok {
return fmt.Errorf("unknown buffer %q", path)
}
content := make([]string, len(buf.content))
copy(content, buf.content)
content := make([]string, len(buf.lines))
copy(content, buf.lines)
content, err := editContent(content, edits)
if err != nil {
return err
@ -654,7 +658,7 @@ func (e *Editor) setBufferContentLocked(ctx context.Context, path string, dirty
if !ok {
return fmt.Errorf("unknown buffer %q", path)
}
buf.content = content
buf.lines = content
buf.version++
buf.dirty = dirty
e.buffers[path] = buf
@ -908,7 +912,7 @@ func (e *Editor) checkBufferPosition(path string, pos Pos) error {
if !ok {
return fmt.Errorf("buffer %q is not open", path)
}
if !inText(pos, buf.content) {
if !inText(pos, buf.lines) {
return fmt.Errorf("position %v is invalid in buffer %q", pos, path)
}
return nil