Skip to content

fix: send the result ID of the last pulled report as previousResultId - #1735

Merged
angelozerr merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/pull-diagnostics-previous-result-id
Oct 20, 2026
Merged

angelozerr merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/pull-diagnostics-previous-result-id

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

Pulled diagnostics now send previousResultId, the result ID of the last report applied to the document, so that a server can answer that its result is still accurate.

Problem

DocumentContentSynchronizer.refreshPullDiagnostic never set previousResultId. Every textDocument/diagnostic request therefore asked for a full report, and a server could not answer with an unchanged report, which LSP4IJ already handles.

Why this is a fix

Change

  • The synchronizer keeps the result ID of the last report it applied, full or unchanged, and sends it as previousResultId with the next pull of its document.
  • A report it discards, because the document changed or the synchronizer was retired while the request was pending, does not change it: an unchanged reply to that ID would vouch for diagnostics that were never applied.
  • The synchronizer's lifetime is one connection of one document, so closing and reopening the document, or restarting the server, starts with no previous result.

Validation

New PullResultIdTest:

Step main With the fix
first pull no previousResultId no previousResultId
pull after a full report with result-1 fails: none (expected:<result-1> but was:<null>) result-1
after an unchanged report with result-2 the first report's diagnostics stay
next pull result-2

MockTextDocumentService records the diagnostic requests, and the synchronizer has a @TestOnly accessor for the kept result ID: the test waits for an unchanged report to be applied, which shows nothing otherwise. ./gradlew check: 604 tests, 0 failures, the 3 existing skips.

Not included

  • The result IDs in a report's relatedDocuments are not kept, since those documents are not pulled through this synchronizer.
  • workspace/diagnostic is not part of this.

A textDocument/diagnostic pull never sent previousResultId, so a server could not answer that
the result it gave is still accurate (an unchanged report), and had to send the full report each
time; LSP4IJ already handles unchanged reports.

The synchronizer, whose lifetime is one connection of one document, keeps the result ID of the
last report it applied, full or unchanged, and sends it with the next pull. A report that is
discarded, because the document changed or the synchronizer was retired while the request was
pending, does not change it: an unchanged reply to that ID would vouch for diagnostics that
were never applied. Closing and reopening the document starts with a new synchronizer, so with
no previous result.

New PullResultIdTest: the first pull sends no previousResultId; after a full report "result-1",
the next pull sends it; after an unchanged report "result-2", the diagnostics of the first report
stay, and the next pull sends "result-2". On main the second pull sends none (expected:<result-1>
but was:<null>). MockTextDocumentService records the diagnostic requests, and the synchronizer
has a @testonly accessor for the kept result ID. ./gradlew check: 604 tests, 0 failures, the 3
existing skips.
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a511db50-3f1c-4639-99a9-c5d79f07cc65
📥 Commits

Reviewing files that changed from the base of the PR and between 94f48a7 and e0fc79e.

📒 Files selected for processing: 3
  • src/main/java/com/redhat/devtools/lsp4ij/DocumentContentSynchronizer.java
  • src/test/java/com/redhat/devtools/lsp4ij/PullResultIdTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/mock/MockTextDocumentService.java

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

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved pull diagnostics synchronization by linking subsequent requests to the latest diagnostic result.
    • Correctly handles unchanged diagnostic reports while preserving existing diagnostics.
    • Ensures document edits trigger refreshed diagnostic requests.

The synchronizer now sends the latest pull-diagnostic result ID with subsequent requests and stores IDs returned by full and unchanged reports. Integration tests verify result-ID chaining and diagnostic preservation.

Changes: Pull diagnostic result ID chaining

Layer / File(s) Summary
Track pull-diagnostic result IDs
src/main/java/com/redhat/devtools/lsp4ij/DocumentContentSynchronizer.java
The synchronizer sends the stored result ID as previousResultId and updates it from full and unchanged reports. A test-only accessor exposes the stored ID.
Record requests and verify result ID chaining
src/test/java/com/redhat/devtools/lsp4ij/mock/MockTextDocumentService.java, src/test/java/com/redhat/devtools/lsp4ij/PullResultIdTest.java
The mock service records diagnostic requests and clears the records on reset. The integration test checks initial and subsequent request IDs, unchanged reports, document edits, and applied diagnostics.

Priority: ⬇️ Low

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

Change: Bug fix

Suggested reviewers: angelozerr

Merge Risk: ⚪ Minimal · up to e0fc7

Pull diagnostics now send the previous result ID on follow-up requests, as the LSP specification describes. No actionable merge-blocking risk was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 18.75% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: sending the last pulled report result ID as previousResultId.
Description check Passed The description directly explains the previousResultId fix, its behavior, scope, and validation.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI

Comment @coderabbitai help to get the list of available commands.

@angelozerr angelozerr added bug Something isn't working diagnostic labels Oct 20, 2026
@angelozerr angelozerr added this to the 0.21.1 milestone Oct 20, 2026
@angelozerr angelozerr moved this to In Progress in Java Tooling Oct 20, 2026
@angelozerr

Copy link
Copy Markdown
Contributor

LGTM, thanks @lagergren !

@angelozerr
angelozerr merged commit 6ad24b5 into redhat-developer:main Oct 20, 2026
7 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Java Tooling Oct 20, 2026
@lagergren
lagergren deleted the fix/pull-diagnostics-previous-result-id branch October 26, 2026 21:43
angelozerr pushed a commit that referenced this pull request Nov 4, 2026
* docs: describe the 0.30.0 LSP and DAP changes that the docs miss

Several changes merged for 0.30.0 changed behavior that the docs
describe, or added behavior that they don't. LSPSupport.md still said
that pull diagnostics don't support related documents, which #1723
changed.

LSP:
- LSPSupport.md, Pull Diagnostics: previousResultId, and the
  relatedDocuments of either kind of report (#1723, #1735), in place
  of "It doesn't support the related documents."
- LSPSupport.md, Inline Completion: the trigger kind and the selected
  completion item (#1715).
- LSPSupport.md, Signature Help: the retrigger, the active parameter
  of each signature, and signatures without parameters (#1712, #1734).
- LSPSupport.md, Formatting: a file without an open editor (#1707).
- LSPSupport.md, new Did Change Watched Files section: the directories
  outside the project that watchers name, and the watchers of a stopped
  server (#1742). The support list links to it.
- UserGuide.md, Formatting: the Do not format patterns (#1817).
- UserDefinedLanguageServer.md, Configuration tab: null properties
  (#1710, #1847) and invalid JSON (#1828).
- DeveloperGuide.md, Workspace Configuration: null members of
  createSettings() (#1710, #1847).

DAP, dap/UserGuide.md:
- Exception breakpoint: the hint built from exceptionInfo (#1761). The
  screenshot of the stop at the exception moves back after the example
  it shows; the Smart Step Into section had come between them.
- Large variables: a page with fewer children than asked for is the
  last one (#1851).

Validation: each statement was checked against the code at d1a281d:
DocumentContentSynchronizer.refreshPullDiagnostic,
LSPInlineCompletionProvider.createParams, LSPParameterInfoHandler,
ClientCapabilitiesFactory, AbstractLSPFormattingService.canFormat,
LSPFormattingSupport, FileSystemWatchRoots, LanguageServerPanel
.validateJsonFields, JsonSettingsTypeAdapterFactory,
DAPClient.getExceptionHint and DAPVariableChildren. The other changes
merged for 0.30.0 are already documented, by their own PRs, #1784 and
#1810, or change nothing that the docs describe.

Limits: docs only, no new screenshots, no build run.

* docs: say that the JSON fields of a language server are read leniently

CodeRabbit noted that "must be valid JSON" is stricter than what
LSP4IJ accepts. The dialog's check (LanguageServerPanel.jsonError,
JsonParser.parseString) and the readers at run time
(SettingsHelper.parseJson, JsonParser.parseReader for the
initialization options, experimental and installer, Gson.fromJson for
the client configuration and workspace folders) all read leniently.

The paragraph now says which JSON is accepted and which isn't.

Validation: probed Gson 2.15.0's JsonParser.parseString and
Gson.fromJson. Both accept // and /* */ and # comments, unquoted names
and single-quoted strings, and both reject a trailing comma, a missing
brace and an unescaped backslash, such as in C:\Users.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working diagnostic

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants