Skip to content

Commit

Permalink
internal/lsp: propagate file invalidations to all views
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
stamblerre committed Feb 11, 2020
1 parent f41547c commit e2a38c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
17 changes: 7 additions & 10 deletions internal/lsp/cache/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 8 additions & 3 deletions internal/lsp/cache/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit e2a38c8

Please sign in to comment.