mirror of
https://github.com/golang/go
synced 2024-11-18 16:14:46 -07:00
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 <rstambler@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
f41547ceaf
commit
e2a38c8363
17
internal/lsp/cache/session.go
vendored
17
internal/lsp/cache/session.go
vendored
@ -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 {
|
||||
|
11
internal/lsp/cache/view.go
vendored
11
internal/lsp/cache/view.go
vendored
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user