Skip to content

feat: client-side support for incremental diagnostics#752

Merged
mhuisi merged 3 commits intoleanprover:masterfrom
mhuisi:push-lknxxwnmvuto
Apr 15, 2026
Merged

feat: client-side support for incremental diagnostics#752
mhuisi merged 3 commits intoleanprover:masterfrom
mhuisi:push-lknxxwnmvuto

Conversation

@mhuisi
Copy link
Copy Markdown
Collaborator

@mhuisi mhuisi commented Apr 1, 2026

This PR adds client-side support for 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.

@mhuisi mhuisi marked this pull request as draft April 1, 2026 15:50
@mhuisi mhuisi marked this pull request as ready for review April 7, 2026 11:25
@mhuisi mhuisi force-pushed the push-lknxxwnmvuto branch from 971e8ef to a7ffb3a Compare April 7, 2026 13:41
@mhuisi mhuisi force-pushed the push-lknxxwnmvuto branch from 3622e15 to a306f70 Compare April 13, 2026 13:37
@mhuisi mhuisi force-pushed the push-lknxxwnmvuto branch from ad748d0 to 3e583ff Compare April 14, 2026 12:18
@mhuisi mhuisi merged commit d6087e8 into leanprover:master Apr 15, 2026
9 checks passed
pull Bot pushed a commit to VitalyAnkh/lean4 that referenced this pull request Apr 21, 2026
This PR adds server-side support for incremental diagnostics via a new
`isIncremental` field on `PublishDiagnosticsParams` that is only used by
the language server when clients set `incrementalDiagnosticSupport` in
`LeanClientCapabilities`.

### 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.incrementalDiagnosticSupport` is set, the
language server will set `PublishDiagnosticsParams.isIncremental` when
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:
- If `PublishDiagnosticsParams.isIncremental` is `false` or 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.
- If `PublishDiagnosticsParams.isIncremental` is `true`, the current
diagnostic report for a specific document should append to the previous
diagnostic report for that document instead of replacing it.
- Versions should be ignored when deciding whether to replace or append
to a previous set of diagnostics. The language server ensures that the
`isIncremental` flag is set correctly.

### Client-side implementation

A client-side implementation for the VS Code extension can be found at
[vscode-lean4#752](leanprover/vscode-lean4#752).

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Wojciech Nawrocki <13901751+Vtec234@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants