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>
diff --git a/internal/lsp/fake/editor.go b/internal/lsp/fake/editor.go
index 58a13ec..725c596 100644
--- a/internal/lsp/fake/editor.go
+++ b/internal/lsp/fake/editor.go
@@ -57,12 +57,12 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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