Fix diagnostic race condition when switching Python interpreters #1679
+233
−51
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:
When switching Python interpreters via workspace/didChangeConfiguration, the LSP
would sometimes show stale diagnostics because of a race condition in how config
invalidation and diagnostic publishing interacted.
The issue was that invalidate_config_and_validate_in_memory() would:
However, the RecheckFinished event handler could run and publish diagnostics
before modules had actually re-run with the new config, resulting in diagnostics
that still showed errors from the old interpreter's site-packages.
The fix is to publish diagnostics immediately after committing the config
invalidation transaction, using a fresh transaction that reflects the newly
committed state. This ensures diagnostics always use the updated configs.
Additionally, extracted the diagnostic publishing logic into a reusable
publish_diagnostics_for_handles() method to avoid code duplication.
This likely helps with #1667
Differential Revision: D87848835