Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: protect scanned files against closing by LSP #4735

Merged

Conversation

arendjr
Copy link
Contributor

@arendjr arendjr commented Dec 14, 2024

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.

@arendjr arendjr requested a review from a team December 14, 2024 15:40
@github-actions github-actions bot added A-CLI Area: CLI A-Core Area: core A-Project Area: project A-LSP Area: language server protocol labels Dec 14, 2024
@arendjr arendjr merged commit e77fb9d into biomejs:next Dec 15, 2024
10 checks passed
Comment on lines +197 to +199
pub fn to_path_buf(&self) -> PathBuf {
self.path.clone()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think there's a need for this function? &BiomePath already exposes this function, because BiomePath implements Deref, which returns &Path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good catch. Then I’ll remove it again 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-CLI Area: CLI A-Core Area: core A-LSP Area: language server protocol A-Project Area: project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants