Skip to content

Commit 6dd6151

Browse files
committed
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]>
1 parent ea181f5 commit 6dd6151

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
@@ -392,16 +392,23 @@ func basename(filename string) string {
392392
}
393393

394394
func (v *view) relevantChange(c source.FileModification) bool {
395-
if v.contains(c.URI) {
396-
return true
395+
// If the file is known to the view, the change is relevant.
396+
known := v.knownFile(c.URI)
397+
398+
// If the file is not known to the view, and the change is only on-disk,
399+
// we should not invalidate the snapshot. This is necessary because Emacs
400+
// sends didChangeWatchedFiles events for temp files.
401+
if !known && c.OnDisk && (c.Action == source.Change || c.Action == source.Delete) {
402+
return false
397403
}
404+
return v.contains(c.URI) || known
405+
}
398406

399-
// Check if the view is already aware of this file.
400-
// If so, the change is relevant.
407+
func (v *view) knownFile(uri span.URI) bool {
401408
v.mu.Lock()
402409
defer v.mu.Unlock()
403410

404-
f, err := v.findFile(c.URI)
411+
f, err := v.findFile(uri)
405412
return f != nil && err == nil
406413
}
407414

0 commit comments

Comments
 (0)