Skip to content

fix: collect the diagnostics of a file only once its document is committed - #2031

Merged
lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/diagnostics-refresh-committed-documents
Nov 20, 2026
Merged

lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/diagnostics-refresh-committed-documents

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

Fixes #2030.

LSPDiagnosticsApplier.scheduleRefresh collects the diagnostics of a file in a non-blocking read action, and LSPDiagnosticFeature.createAnnotation places 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 throws Range must be inside element being annotated, and the refresh shows nothing. The read action now runs withDocumentsCommitted(project), so it collects once the Psi file has the document's text.

Test: LSPDiagnosticsApplierTest.testARefreshWaitsUntilTheDocumentIsCommitted inserts 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 of features.diagnostics and the code action tests (95) pass.

…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.
@lagergren lagergren added this to the 0.30.2 milestone Nov 20, 2026
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Diagnostics now reflect the latest document text, including edits that have not yet been saved.

The diagnostics refresh now waits for project documents to commit before collecting diagnostics. A test covers a diagnostic for text appended to an uncommitted document.

Changes: Diagnostics refresh

Layer / File(s) Summary
Commit documents before collecting diagnostics
src/main/java/com/redhat/devtools/lsp4ij/features/diagnostics/LSPDiagnosticsApplier.java, src/test/java/com/redhat/devtools/lsp4ij/features/diagnostics/LSPDiagnosticsApplierTest.java
The refresh waits for project documents to commit before collecting diagnostics. The test verifies that an appended-text diagnostic appears with the original diagnostic after commit.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: angelozerr

Merge Risk: Minimal · up to 2325b

This change makes diagnostics refreshes wait for documents to be committed. That should stop diagnostics from disappearing after a completion inserts text. No actionable merge-blocking risk remains, and a regression test covers the scenario.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix: collect the diagnostics of a file only once its document is committed" states the main change. The change makes LSPDiagnosticsApplier.scheduleRefresh run withDocumentsCommitted(project…
Description check Passed The description explains the cause (diagnostics use document offsets while annotating the Psi file, which differs until commit), the fix (withDocumentsCommitted in the read action), and a test (testAR…
Linked Issues check Passed Issue #2030 requires that diagnostics are not collected before the file's document is committed. At the reviewed head, LSPDiagnosticsApplier.scheduleRefresh adds .withDocumentsCommitted(project) to th…
Out of Scope Changes check Passed The change to the production code is limited to the withDocumentsCommitted call and its two-line comment in LSPDiagnosticsApplier.scheduleRefresh. The test change adds a regression test for the same r…
Full details: Title check

Explanation

The title "fix: collect the diagnostics of a file only once its document is committed" states the main change. The change makes LSPDiagnosticsApplier.scheduleRefresh run withDocumentsCommitted(project) before collecting diagnostics, which matches the title. The title is concise and specific.

Full details: Description check

Explanation

The description explains the cause (diagnostics use document offsets while annotating the Psi file, which differs until commit), the fix (withDocumentsCommitted in the read action), and a test (testARefreshWaitsUntilTheDocumentIsCommitted). It matches the changeset and the linked issue #2030.

Full details: Linked Issues check

Explanation

Issue #2030 requires that diagnostics are not collected before the file's document is committed. At the reviewed head, LSPDiagnosticsApplier.scheduleRefresh adds .withDocumentsCommitted(project) to the ReadAction.nonBlocking chain, before coalesceBy, finishOnUiThread and submit. collectDiagnostics therefore runs only after the Psi file has the document's text, which addresses the 'Range must be inside element being annotated' failure path described in the issue. The test LSPDiagnosticsApplierTest.testARefreshWaitsUntilTheDocumentIsCommitted is described in the PR and in the raw summary (+30 lines); its content was not read directly, so the test evidence rests on that description. The source change is verified at head. No active non-coding requirements exist in the issue.

Full details: Out of Scope Changes check

Explanation

The change to the production code is limited to the withDocumentsCommitted call and its two-line comment in LSPDiagnosticsApplier.scheduleRefresh. The test change adds a regression test for the same refresh path. Both changes connect directly to #2030. The other code in LSPDiagnosticsApplier at head, such as the refresh-tracking and highlighter-context logic, is not part of this PR's stated change set according to the raw summary (+3/-0 for the applier). The change-set diff could not be read, so this conclusion relies on the raw summary for the line counts.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3d3aee96-13fd-46b5-afcd-a687edf49c25
Commits

Reviewing files that changed from the base of the PR and between 9cf7de5 and 2325bf5.

Files selected for processing: 2

  • src/main/java/com/redhat/devtools/lsp4ij/features/diagnostics/LSPDiagnosticsApplier.java
  • src/test/java/com/redhat/devtools/lsp4ij/features/diagnostics/LSPDiagnosticsApplierTest.java

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 49.30%. Comparing base (9cf7de5) to head (2325bf5).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lagergren
lagergren merged commit e4518e5 into redhat-developer:main Nov 20, 2026
9 checks passed
@lagergren lagergren added the bug Something isn't working label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Range must be inside element being annotated: a diagnostic falls outside the file right after a completion

1 participant