diff --git a/internal/lsp/cache/session.go b/internal/lsp/cache/session.go index 8763c4de6e6..77d19f3463b 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 c034ea5f77e..542dedc2087 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 }