From e2a38c836335266bbd5f77dd95b90b60396304f2 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Mon, 10 Feb 2020 14:45:18 -0500 Subject: [PATCH] internal/lsp: propagate file invalidations to all views We were previously only invalidating files if they were contained within a subdirectory of a view, but we should really be invalidating all files that are known to a view. Fixes golang/go#34955 Change-Id: I2eb1476e6b5f74a64dbb6d47459f4009648c720d Reviewed-on: https://go-review.googlesource.com/c/tools/+/218859 Run-TryBot: Rebecca Stambler Reviewed-by: Heschi Kreinick TryBot-Result: Gobot Gobot --- internal/lsp/cache/session.go | 17 +++++++---------- internal/lsp/cache/view.go | 11 ++++++++--- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/internal/lsp/cache/session.go b/internal/lsp/cache/session.go index 8763c4de6e..77d19f3463 100644 --- a/internal/lsp/cache/session.go +++ b/internal/lsp/cache/session.go @@ -290,19 +290,16 @@ func (s *session) DidModifyFiles(ctx context.Context, changes []source.FileModif if s.isOpen(c.URI) && c.OnDisk { continue } - for _, view := range s.viewsOf(c.URI) { + // Look through all of the session's views, invalidating the file for + // all of the views to which it is known. + for _, view := range s.views { if view.Ignore(c.URI) { return nil, errors.Errorf("ignored file %v", c.URI) } - // If the file change is on-disk and not a create, - // make sure the file is known to the view already. - if c.OnDisk { - switch c.Action { - case source.Change, source.Delete: - if !view.knownFile(c.URI) { - continue - } - } + // Don't propagate changes that are outside of the view's scope + // or knowledge. + if !view.relevantChange(c) { + continue } // Make sure that the file is added to the view. if _, err := view.getFile(c.URI); err != nil { diff --git a/internal/lsp/cache/view.go b/internal/lsp/cache/view.go index c034ea5f77..542dedc208 100644 --- a/internal/lsp/cache/view.go +++ b/internal/lsp/cache/view.go @@ -391,12 +391,17 @@ func basename(filename string) string { return strings.ToLower(filepath.Base(filename)) } -// knownFile returns true if the given URI is already a part of the view. -func (v *view) knownFile(uri span.URI) bool { +func (v *view) relevantChange(c source.FileModification) bool { + if v.contains(c.URI) { + return true + } + + // Check if the view is already aware of this file. + // If so, the change is relevant. v.mu.Lock() defer v.mu.Unlock() - f, err := v.findFile(uri) + f, err := v.findFile(c.URI) return f != nil && err == nil }