Repository navigation
fix: collect the diagnostics of a file only once its document is committed - #2031
Merged
lagergren merged 1 commit intoNov 20, 2026
Conversation
…itted LSPDiagnosticsApplier collected the diagnostics of a file in a non-blocking read action that didn't wait for the document to be committed. LSPDiagnosticFeature.createAnnotation places a diagnostic at offsets of the document but annotates the Psi file, so right after a completion inserts text, a diagnostic of the inserted text fell outside the Psi file and IntelliJ threw "Range must be inside element being annotated". The refresh now waits until the documents are committed.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2031 +/- ##
=========================================
Coverage 49.30% 49.30%
=========================================
Files 813 813
Lines 33191 33192 +1
Branches 5156 6805 +1649
=========================================
+ Hits 16364 16366 +2
- Misses 14265 14266 +1
+ Partials 2562 2560 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 #2030.
LSPDiagnosticsApplier.scheduleRefreshcollects the diagnostics of a file in a non-blocking read action, andLSPDiagnosticFeature.createAnnotationplaces them at offsets of the document while it annotates the Psi file. Until the document is committed, the two can differ: right after a completion inserts text, a diagnostic of the inserted text is outside the Psi file, IntelliJ throwsRange must be inside element being annotated, and the refresh shows nothing. The read action now runswithDocumentsCommitted(project), so it collects once the Psi file has the document's text.Test:
LSPDiagnosticsApplierTest.testARefreshWaitsUntilTheDocumentIsCommittedinserts text without committing the document, stores a diagnostic of the inserted text, and holds the UI thread so that the document can't be committed. The refresh must still be pending after a second, and shows the diagnostic once the test dispatches events. It fails without the change. The tests offeatures.diagnosticsand the code action tests (95) pass.