[ty] Avoid rechecking the entire project when changing the opened files #19463
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
I noticed when playing with the extension that ty always reparses all AST nodes
after I changed the open files in the editor.
The reason for this is that
check_file_impl
depends ondb.open_files
to check if it should evict the AST or not. However, that means that all
project files will be rechecked after changing the open project files.
This PR prevents this by moving the AST eviction out of the
check_file_impl
function. This has the downsidethat it requires an extra
parsed_module
call but thatshould be relatively cheap (we make thousends of those when checking a single file).
Test Plan
I verified that opening an other file doesn't result in re-checking every single project file.