mirror of
https://github.com/golang/go
synced 2024-11-18 14:14:46 -07:00
internal/lsp: fix some cases of stuck files
If typeCheck() returned an error, we could get into a state where a package had an entry in the pcache, but the package's files had an empty "pkgs" map. When we got a DidChange event for one of the files, no packages would get invalidated since the file's "pkgs" was empty. This resulted in the cached typeCheck() error persisting indefinitely. Fix by never caching pcache entries on error. An easy way to reproduce the problem was to delete the package name from a file. For example, edit "package foo" to be just "package". This caused the package to get stuck with an "AST for %s has an invalid position" error. Change-Id: I330bf9e419852dffa0f2dee94b56226367488dd1 GitHub-Last-Rev: 18be7078521b942694c76f799a2d520eee47167d GitHub-Pull-Request: golang/tools#135 Reviewed-on: https://go-review.googlesource.com/c/tools/+/185839 Reviewed-by: Rebecca Stambler <rstambler@golang.org> Run-TryBot: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
d5f455491e
commit
63f37bb4d3
16
internal/lsp/cache/check.go
vendored
16
internal/lsp/cache/check.go
vendored
@ -68,18 +68,22 @@ func (imp *importer) getPkg(ctx context.Context, id packageID) (*pkg, error) {
|
||||
// This goroutine becomes responsible for populating
|
||||
// the entry and broadcasting its readiness.
|
||||
e.pkg, e.err = imp.typeCheck(ctx, id)
|
||||
if e.err != nil {
|
||||
// Don't cache failed packages. If we didn't successfully cache the package
|
||||
// in each file, then this pcache entry won't get invalidated as those files
|
||||
// change.
|
||||
imp.view.pcache.mu.Lock()
|
||||
if imp.view.pcache.packages[id] == e {
|
||||
delete(imp.view.pcache.packages, id)
|
||||
}
|
||||
imp.view.pcache.mu.Unlock()
|
||||
}
|
||||
close(e.ready)
|
||||
}
|
||||
|
||||
if e.err != nil {
|
||||
// If the import had been previously canceled, and that error cached, try again.
|
||||
if e.err == context.Canceled && ctx.Err() == nil {
|
||||
imp.view.pcache.mu.Lock()
|
||||
// Clear out canceled cache entry if it is still there.
|
||||
if imp.view.pcache.packages[id] == e {
|
||||
delete(imp.view.pcache.packages, id)
|
||||
}
|
||||
imp.view.pcache.mu.Unlock()
|
||||
return imp.getPkg(ctx, id)
|
||||
}
|
||||
return nil, e.err
|
||||
|
Loading…
Reference in New Issue
Block a user