Skip to content

fix: include non-optional version in VersionedTextDocumentIdentifier json - #16237

Open
thorimur wants to merge 6 commits into
leanprover:masterfrom
thorimur:lsp-optional-version-null
Open

thorimur wants to merge 6 commits into
leanprover:masterfrom
thorimur:lsp-optional-version-null

Conversation

@thorimur

@thorimur thorimur commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

This PR fixes WorkspaceEdits targeting unopened files. Breaking change: the version? : Option Nat field of VersionedTextDocumentIdentifier is now version : Option Nat, as LSP requires "version": null from the JSON in the version := none case instead of an omitted version field.

Closes #16236

thorimur and others added 4 commits November 3, 2026 16:35
`VersionedTextDocumentIdentifier` omitted `version` from its JSON when
`version? = none`. It is also used for LSP's
`OptionalVersionedTextDocumentIdentifier` (the `textDocument` of a
`TextDocumentEdit`), which requires `version : integer | null`, with `null`
for documents whose version is unknown, e.g. ones not open in the editor or
being created. vscode-languageclient rejects a `TextDocumentEdit` without
`version` ("Unknown workspace edit change received"), so code actions and
`workspace/applyEdit` requests could not edit such documents. In particular, a
workspace edit could not create a file with contents.

`version? := none` is now serialized as `"version": null`. Every place where
Lean builds a `VersionedTextDocumentIdentifier` for LSP's non-optional
`VersionedTextDocumentIdentifier` sets the version, so its serialization is
unchanged there. Deserialization still accepts a missing `version`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Lean's `ToJson`/`FromJson` deriving handlers omit a field named `foo?`
when it is `none`, but serialize any other `Option` field as `null`. Since
LSP's `OptionalVersionedTextDocumentIdentifier` requires `version` (it is
`integer | null`, not optional), the field is now called `version`, and the
derived `ToJson` instance replaces the hand-written one. Deserialization
still accepts a missing `version`, as `getObjValAs?` treats a missing key
as `null`.

This is a breaking change for code that constructs or reads
`VersionedTextDocumentIdentifier.version?`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thorimur thorimur changed the title fix: include non-optional version in VersionedTextDocumentIdentifier fix: include non-optional version in VersionedTextDocumentIdentifier json Nov 3, 2026
@thorimur

thorimur commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

downstream

@downstream-lean4 downstream-lean4 Bot added the downstream Request a downstream-lean4 adaptation PR. label Nov 3, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Nov 3, 2026
@downstream-lean4

Copy link
Copy Markdown

The adaptation PR for this PR is leanprover/downstream-lean4#224.

@mhuisi mhuisi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Is this good to merge?

@thorimur
thorimur marked this pull request as ready for review November 5, 2026 17:39
@thorimur

thorimur commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

@mhuisi Now it is! :) (I've just updated the PR description.)

@thorimur

thorimur commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

changelog-server

@github-actions github-actions Bot added the changelog-server Language server, widgets, and IDE extensions label Nov 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-server Language server, widgets, and IDE extensions downstream Request a downstream-lean4 adaptation PR. toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WorkspaceEdits fail when targeting a URI without a version

2 participants