Skip to content

Commit 7709873

Browse files
committed
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 <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> (cherry picked from commit e2a38c8) Reviewed-on: https://go-review.googlesource.com/c/tools/+/219125
1 parent 7aafd4d commit 7709873

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

internal/lsp/cache/session.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -258,19 +258,16 @@ func (s *session) DidModifyFiles(ctx context.Context, changes []source.FileModif
258258
return nil, err
259259
}
260260
}
261-
for _, view := range s.viewsOf(c.URI) {
261+
// Look through all of the session's views, invalidating the file for
262+
// all of the views to which it is known.
263+
for _, view := range s.views {
262264
if view.Ignore(c.URI) {
263265
return nil, errors.Errorf("ignored file %v", c.URI)
264266
}
265-
// If the file change is on-disk and not a create,
266-
// make sure the file is known to the view already.
267-
if c.OnDisk {
268-
switch c.Action {
269-
case source.Change, source.Delete:
270-
if !view.knownFile(c.URI) {
271-
continue
272-
}
273-
}
267+
// Don't propagate changes that are outside of the view's scope
268+
// or knowledge.
269+
if !view.relevantChange(c) {
270+
continue
274271
}
275272
// Make sure that the file is added to the view.
276273
if _, err := view.getFile(c.URI); err != nil {

internal/lsp/cache/view.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,12 +420,17 @@ func basename(filename string) string {
420420
return strings.ToLower(filepath.Base(filename))
421421
}
422422

423-
// knownFile returns true if the given URI is already a part of the view.
424-
func (v *view) knownFile(uri span.URI) bool {
423+
func (v *view) relevantChange(c source.FileModification) bool {
424+
if v.contains(c.URI) {
425+
return true
426+
}
427+
428+
// Check if the view is already aware of this file.
429+
// If so, the change is relevant.
425430
v.mu.Lock()
426431
defer v.mu.Unlock()
427432

428-
f, err := v.findFile(uri)
433+
f, err := v.findFile(c.URI)
429434
return f != nil && err == nil
430435
}
431436

0 commit comments

Comments
 (0)