refactor: protect scanned files against closing by LSP #4735
+394
−94
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
By having both project scanning inside the workspace server, and explicit opening/closing of files through the workspace protocol, we run into a risk: What if a file was opened by the scanner, but for instance the LSP Proxy asks it to be closed? If we really close it, the analyzer wouldn't be able to extract information from it anymore.
With this PR, we protect against this scenario by tracking whether files have been opened by the scanner, and we keep them loaded in the server even when they're being closed through the workspace protocol.
I also re-added the ability to persist the node cache, but made it an option, so that the LSP Proxy can request a persistent node cache to speed up reparsing during editing, while we don't add overhead for any of the other open files in the workspace. When a file is closed through the workspace protocol, even if we keep it loaded because of the scanner, at least we can clean up the node cache.
Test Plan
Added a test case.