Repository navigation
Description
Problem
DocumentContentSynchronizer.refreshPullDiagnostic applies the relatedDocuments of a textDocument/diagnostic report only when the report itself is unchanged. When the report is full, the usual case, it applies the document's own items and ignores relatedDocuments. See DocumentContentSynchronizer.java#L519-L540 on main (20df566):
isLeft(), theRelatedFullDocumentDiagnosticReport, callsupdatePullDiagnostics(file, fileReport)only.isRight(), theRelatedUnchangedDocumentDiagnosticReport(namedallFilesReportthere), walksrelatedDocuments.
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. An example of such a language is C/C++ where marco definitions in a file a.cpp and result in errors in a header file b.hpp.
So with a full report, diagnostics that the server reports for other files are lost.
LSP4J cannot parse these reports either
LSP4J 1.0.0 cannot parse a report that has relatedDocuments at all; it fails with "Ambiguous Either type: token BEGIN_OBJECT matches both alternatives".
- The LSP4J issue is Parsing a textDocument/diagnostic report with relatedDocuments fails: Ambiguous Either type eclipse-lsp4j/lsp4j#990, with a fix in Add type adapter for the relatedDocuments of document diagnostic reports eclipse-lsp4j/lsp4j#991.
- In LSP4IJ's test harness, a pull whose reply has related documents never completes: the parse fails before LSP4IJ sees the reply.
Fix
The LSP4IJ change is small. Apply relatedDocuments for both report kinds, from one method:
- for a full report, after the document's own items;
- for an unchanged report, as now.
An unchanged related entry needs no update, since it means the last report for that file is still valid.
The fix is in #1723 and can be merged now. Until LSP4J releases eclipse-lsp4j/lsp4j#991, it registers a temporary compatibility adapter, so that LSP4J 1.0.0 can parse these reports.
Its test opens one file and has the mock answer the pull with a full report, and in a second test with an unchanged one. Each carries diagnostics for a second file that stays closed, and the test requires those diagnostics to be stored.
Activity
fix: apply the relatedDocuments of pull diagnostic reports