feat: server-side support for incremental diagnostics #13260
feat: server-side support for incremental diagnostics #13260mhuisi wants to merge 6 commits intoleanprover:masterfrom
Conversation
|
Mathlib CI status (docs):
|
|
Reference manual CI status:
|
b56d320 to
6ca69d5
Compare
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
6ca69d5 to
21b8516
Compare
Vtec234
left a comment
There was a problem hiding this comment.
Looks good; I didn't review the new code in Utils very carefully.
The Lean language server always sets PublishDiagnosticParams.isIncremental = false on the first diagnostic reported for a new version, but in principle, ..
I am confused by the 'in principle' statements in the semantics. Are we saying 'the Lean server does the right thing, but clients should do the in principle part in case the Lean server is buggy'? Could that be deleted, specifying the expected behavior without qualification instead?
Co-authored-by: Wojciech Nawrocki <13901751+Vtec234@users.noreply.github.com>
We are saying "if you want to implement a correct client according to something that resembles a general specification for a general incremental diagnostic feature, you should implement these semantics, but the specific implementation of the Lean language server also fulfills a bunch of invariants". I'll just remove the note about the invariants that we fulfill; clients should ideally just implement the full spec. |
This PR adds client-side support for [lean4#13260](leanprover/lean4#13260). Currently, none of the consumers of diagnostics in the VS Code extension support incremental diagnostics, but adding client-side support for it already means that the server-side serialization overhead is reduced and we send less diagnostic data over the wire.
This PR adds server-side support for incremental diagnostics via a new
isIncrementalfield onPublishDiagnosticsParamsthat is only used by the language server when clients setincrementalDiagnosticSupportinLeanClientCapabilities.Context
The goal of this new feature is to avoid quadratic reporting of diagnostics.
LSP has two means of reporting diagnostics; pull diagnostics (where the client decides when to fetch the diagnostics of a project) and push diagnostics (where the server decides when to update the set of diagnostics of a file in the client).
Pull diagnostics have the inherent problem that clients need to heuristically decide when the set of diagnostics should be updated, and that diagnostics can only be incrementally reported per file, so the Lean language server has always stuck with push diagnostics instead.
In principle, push diagnostics were also intended to only be reported once for a full file, but all major language clients also support replacing the old set of diagnostics for a file when a new set of diagnostics is reported for the same version of the file, so we have always reported diagnostics incrementally while the file is being processed in this way.
However, this approach has a major limitation: all notifications must be a full set of diagnostics, which means that we have to report a quadratic amount of diagnostics while processing a file to the end.
Semantics
When
LeanClientCapabilities.incrementalDiagnosticSupportis set, the language server will setPublishDiagnosticsParams.isIncrementalwhen it is reporting a set of diagnostics that should simply be appended to the previously reported set of diagnostics instead of replacing it. Specifically, clients implementing this new feature should implement the following behaviour:PublishDiagnosticsParams.isIncrementalisfalseor the field is missing, the current diagnostic report for a specific document should replace the previous diagnostic report for that document instead of appending to it. This is identical to the current behavior before this PR.PublishDiagnosticsParams.isIncrementalistrue, the current diagnostic report for a specific document should append to the previous diagnostic report for that document instead of replacing it.isIncrementalflag is set correctly.Client-side implementation
A client-side implementation for the VS Code extension can be found at vscode-lean4#752.