From 6dd6151793f7ca4e4c7e87d7f2f5363f2615a446 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Wed, 12 Feb 2020 15:18:16 -0500 Subject: [PATCH] internal/lsp: ignore irrelevant on-disk changes Change-Id: Ibdceadbfc822a64066d9370eefa9ff5f7988d0a2 Reviewed-on: https://go-review.googlesource.com/c/tools/+/219202 Run-TryBot: Rebecca Stambler Reviewed-by: Heschi Kreinick TryBot-Result: Gobot Gobot --- internal/lsp/cache/view.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/internal/lsp/cache/view.go b/internal/lsp/cache/view.go index 542dedc208..29a6910c44 100644 --- a/internal/lsp/cache/view.go +++ b/internal/lsp/cache/view.go @@ -392,16 +392,23 @@ func basename(filename string) string { } func (v *view) relevantChange(c source.FileModification) bool { - if v.contains(c.URI) { - return true - } + // If the file is known to the view, the change is relevant. + known := v.knownFile(c.URI) - // Check if the view is already aware of this file. - // If so, the change is relevant. + // If the file is not known to the view, and the change is only on-disk, + // we should not invalidate the snapshot. This is necessary because Emacs + // sends didChangeWatchedFiles events for temp files. + if !known && c.OnDisk && (c.Action == source.Change || c.Action == source.Delete) { + return false + } + return v.contains(c.URI) || known +} + +func (v *view) knownFile(uri span.URI) bool { v.mu.Lock() defer v.mu.Unlock() - f, err := v.findFile(c.URI) + f, err := v.findFile(uri) return f != nil && err == nil }