Skip to content

Commit e479d01

Browse files
committed
[gopls-release-branch.0.3] internal/lsp: ignore irrelevant on-disk changes
Change-Id: Ibdceadbfc822a64066d9370eefa9ff5f7988d0a2 Reviewed-on: https://go-review.googlesource.com/c/tools/+/219202 Run-TryBot: Rebecca Stambler <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> (cherry picked from commit 6dd6151) Reviewed-on: https://go-review.googlesource.com/c/tools/+/219221
1 parent 260a54f commit e479d01

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

internal/lsp/cache/view.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,16 +425,23 @@ func basename(filename string) string {
425425
}
426426

427427
func (v *view) relevantChange(c source.FileModification) bool {
428-
if v.contains(c.URI) {
429-
return true
428+
// If the file is known to the view, the change is relevant.
429+
known := v.knownFile(c.URI)
430+
431+
// If the file is not known to the view, and the change is only on-disk,
432+
// we should not invalidate the snapshot. This is necessary because Emacs
433+
// sends didChangeWatchedFiles events for temp files.
434+
if !known && c.OnDisk && (c.Action == source.Change || c.Action == source.Delete) {
435+
return false
430436
}
437+
return v.contains(c.URI) || known
438+
}
431439

432-
// Check if the view is already aware of this file.
433-
// If so, the change is relevant.
440+
func (v *view) knownFile(uri span.URI) bool {
434441
v.mu.Lock()
435442
defer v.mu.Unlock()
436443

437-
f, err := v.findFile(c.URI)
444+
f, err := v.findFile(uri)
438445
return f != nil && err == nil
439446
}
440447

0 commit comments

Comments
 (0)