Skip to content

fix: apply the relatedDocuments of pull diagnostic reports - #1723

Merged
angelozerr merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/pull-related-documents
Oct 19, 2026
Merged

angelozerr merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/pull-related-documents

Conversation

@lagergren

@lagergren lagergren commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1722. Pull diagnostics now apply the relatedDocuments of a report of either kind. Until LSP4J can parse such reports, LSP4IJ parses them itself.

Problem

There are two bugs, and with both present no related document's diagnostics are ever applied.

  1. LSP4J cannot parse the reply. In LSP4J 1.0.0, a textDocument/diagnostic reply with relatedDocuments fails with "Ambiguous Either type: token BEGIN_OBJECT matches both alternatives" (Parsing a textDocument/diagnostic report with relatedDocuments fails: Ambiguous Either type eclipse-lsp4j/lsp4j#990, fixed in Add type adapter for the relatedDocuments of document diagnostic reports eclipse-lsp4j/lsp4j#991, not yet released). In LSP4IJ's test harness such a pull never completes.
  2. LSP4IJ ignores half of them. DocumentContentSynchronizer.refreshPullDiagnostic applies relatedDocuments only for an unchanged report. For a full report, the usual case, it applies the document's own items and drops the related documents.

LSP defines relatedDocuments on both report kinds:

Diagnostics of related documents. This information is useful in programming languages where code in a file A can generate diagnostics in a file B which A depends on.

Change

  • refreshPullDiagnostic applies the related documents of both report kinds, through one new method, updateRelatedPullDiagnostics.
  • New RelatedDocumentsTypeAdapterFactory is registered in JSONUtils.configureCompatibilityAdapters, next to LSP4IJ's other LSP4J compatibility adapters.

Validation

  • New PullRelatedDocumentsTest opens a file, and the mock server answers the pull with a full report and, in a second test, with an unchanged report. Each carries diagnostics for a second file that stays closed, and the test requires those diagnostics to be stored.

  • New RelatedDocumentsSerializationTest round-trips a textDocument/diagnostic response with related documents through MessageJsonHandler with configureCompatibilityAdapters.

  • Each part was run on its own:

    Present Unchanged report Full report Serialization
    neither (main) fails fails fails: "Ambiguous Either type"
    handling fix only fails fails fails
    adapter only passes fails passes
    both passes passes passes
  • ./gradlew check: 579 tests, 0 failures, the 3 existing skips.

Related

Fixes redhat-developer#1722. Two bugs together kept the diagnostics of related documents
from ever being applied:

- LSP4J 1.0.0 cannot parse a textDocument/diagnostic reply with
  relatedDocuments: "Ambiguous Either type: token BEGIN_OBJECT matches both
  alternatives" (eclipse-lsp4j/lsp4j#990, fixed in eclipse-lsp4j/lsp4j#991,
  not yet released). In LSP4IJ's test harness such a pull never completed.
- DocumentContentSynchronizer.refreshPullDiagnostic applied relatedDocuments
  only for an unchanged report, and dropped them from a full one.

refreshPullDiagnostic now applies the related documents of both report kinds,
through updateRelatedPullDiagnostics. RelatedDocumentsTypeAdapterFactory,
registered in JSONUtils.configureCompatibilityAdapters beside the other LSP4J
compatibility adapters, reads each relatedDocuments value by its kind, as LSP4J
does for the report itself. It only matches the exact field type, so LSP4J's
own field adapter takes precedence once LSP4IJ uses a release with redhat-developer#991, and
the factory can then be removed.

Validation:
- New PullRelatedDocumentsTest: the mock answers the opened file's pull with a
  full report, and in a second test an unchanged one. Each carries diagnostics
  for a second, closed file, which must be stored.
- New RelatedDocumentsSerializationTest round-trips such a
  textDocument/diagnostic response through MessageJsonHandler with
  configureCompatibilityAdapters.
- With neither part, or with only the handling fix, all three tests fail. With
  only the adapter, the unchanged-report and serialization tests pass and the
  full-report test fails. With both, all pass.
- ./gradlew check: 579 tests, 0 failures, 3 existing skips.

Signed-off-by: Marcus Lagergren <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 19, 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: c7149387-dd98-4460-8eba-0f64b55ba0d1
📥 Commits

Reviewing files that changed from the base of the PR and between 20df566 and 2b2c268.

📒 Files selected for processing: 5
  • src/main/java/com/redhat/devtools/lsp4ij/DocumentContentSynchronizer.java
  • src/main/java/com/redhat/devtools/lsp4ij/JSONUtils.java
  • src/main/java/com/redhat/devtools/lsp4ij/internal/adapters/RelatedDocumentsTypeAdapterFactory.java
  • src/test/java/com/redhat/devtools/lsp4ij/RelatedDocumentsSerializationTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/features/diagnostics/PullRelatedDocumentsTest.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
    • Diagnostics returned for related documents are now applied to those documents when processing pull-diagnostic responses.
    • Related-document diagnostic reports are now parsed and preserved when responses are read or written.

The pull-diagnostic response parser now supports related-document reports. The synchronizer applies full related reports for both full and unchanged top-level reports. Tests cover parsing, serialization, and diagnostic updates.

Changes: Related pull diagnostics

Layer / File(s) Summary
Parse related diagnostic reports
src/main/java/com/redhat/devtools/lsp4ij/internal/adapters/RelatedDocumentsTypeAdapterFactory.java, src/main/java/com/redhat/devtools/lsp4ij/JSONUtils.java, src/test/java/com/redhat/devtools/lsp4ij/RelatedDocumentsSerializationTest.java
A compatibility adapter reads and writes related-report maps, and JSON compatibility configuration registers it. A serialization test checks full and unchanged related reports in a round trip.
Apply related diagnostics
src/main/java/com/redhat/devtools/lsp4ij/DocumentContentSynchronizer.java, src/test/java/com/redhat/devtools/lsp4ij/features/diagnostics/PullRelatedDocumentsTest.java
The synchronizer processes full related-document reports for full and unchanged top-level reports. Tests check that the related diagnostics are applied in both cases.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: angelozerr

Merge Risk: ⚪ Minimal · up to 2b2c2

This change lets related-document diagnostics from pull reports be applied and parsed. No actionable merge-blocking risk remains in the supplied review.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 5 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 identifies the main change: applying related documents from pull diagnostic reports.
Description check Passed The description directly explains the relatedDocuments handling fix, compatibility adapter, tests, and validation results.
Linked Issues check Passed The changes satisfy issue #1722. DocumentContentSynchronizer sends related-document maps from both full and unchanged top-level reports to updateRelatedPullDiagnostics. The helper updates diagnost…
Out of Scope Changes check Passed The changed files stay within issue #1722. They modify pull-diagnostic handling, add the temporary LSP4J compatibility adapter, and add focused automated tests. No unrelated product behavior or unrela…
Full details: Linked Issues check

Explanation

The changes satisfy issue #1722. DocumentContentSynchronizer sends related-document maps from both full and unchanged top-level reports to updateRelatedPullDiagnostics. The helper updates diagnostics for related full reports and correctly does not update unchanged related entries. RelatedDocumentsTypeAdapterFactory decodes each related value by kind and is registered in JSONUtils. PullRelatedDocumentsTest covers full and unchanged reports with a closed related file. RelatedDocumentsSerializationTest covers the LSP4J 1.0.0 parsing workaround.

Full details: Out of Scope Changes check

Explanation

The changed files stay within issue #1722. They modify pull-diagnostic handling, add the temporary LSP4J compatibility adapter, and add focused automated tests. No unrelated product behavior or unrelated test coverage is shown.

  • Fix all pre-merge checks with AI

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

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@angelozerr

Copy link
Copy Markdown
Contributor

Nice fix @lagergren !

@angelozerr angelozerr added this to the 0.21.1 milestone Oct 19, 2026
@angelozerr angelozerr added bug Something isn't working diagnostic labels Oct 19, 2026
@angelozerr angelozerr moved this to In Progress in Java Tooling Oct 19, 2026
@angelozerr
angelozerr merged commit d9d45d8 into redhat-developer:main Oct 19, 2026
8 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Java Tooling Oct 19, 2026
@lagergren
lagergren deleted the fix/pull-related-documents 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.

Pull diagnostics ignore the relatedDocuments of a full report

2 participants