fix(lsp): remove code_action/diagnostics deadlock #10555
Merged
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.
Fixes: #10368
This PR refactors the whole of
lsp/diagnostics.rs
to clean it up as well as remove situations where the language server can end up in a deadlock while processing code actions. Code actions require access to the current TypeScript diagnostics for a given file to determine if there are multiple fixable diagnostics it can perform for a given action. Previously when the language server was running slow (a slow machine or complex TypeScript project) it could end up in a situation where there was a request to update the diagnostics locking the diagnostic collection at the same time a code action was trying to acquire a lock to read the diagnostics and this would "hang" the language server.There is no easy test for this, but the symptom was actually evident in the tests when the refactor "broke" the
test_code_actions
. The request for thecode_actions
would be blocked until the diagnostic refresh completed, which then ran a risk that we would get into a deadlock state if another refresh were to start while the code actions were being processed. A delay now has to be added to ensure the diagnostics are updated as an update to diagnostics is now non-blocking forcode_actions
which is the way it should have always been.