Skip to content

fix(lsp): re-sync full-document changes as didClose+didOpen (avoid at least Roslyn C# LSP crash) - #2927

Open
sfjohansson wants to merge 2 commits into
sinelaw:masterfrom
sfjohansson:fix/lsp-roslyn-full-document-resync
Open

fix(lsp): re-sync full-document changes as didClose+didOpen (avoid at least Roslyn C# LSP crash)#2927
sfjohansson wants to merge 2 commits into
sinelaw:masterfrom
sfjohansson:fix/lsp-roslyn-full-document-resync

Conversation

@sfjohansson

@sfjohansson sfjohansson commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Bug: Roslyn negotiates INCREMENTAL sync, then throws NullReferenceException on a full-document change (range: None). That faults its request queue and closes stdout — completion/hover die on the line you're typing, while hover still works on untouched code, so the server looks healthy.

Fix: in handle_did_change_sequential (the single chokepoint for every didChange) — when a change has range: None and the negotiated sync kind isn't FULL, re-sync as didClose + didOpen. didOpen carries the whole text with no range, valid under any sync kind.

  • Generic LSP layer, not C#-gated — applies to any server that negotiated non-FULL sync, i.e. nearly all of them. Roslyn is just the one that crashes instead of silently tolerating the invalid payload.
  • Fires only on full-document paths: file reload, workspace restore, plugin edits, event_apply resync.
  • Per-keystroke ranged edits are untouched.

Tests: unit test over every TextDocumentSync capability shape, plus a behavioural one — under INCREMENTAL a full-document change resets the tracked version to 0 (proving close+open), a ranged change still bumps it, and under FULL it stays a didChange. Both fail without the fix.

Refs: LSP 3.17 — Text Document Synchronization · Roslyn ProtocolConversions.cs

sfjohansson and others added 2 commits June 20, 2026 10:18
…Roslyn crash

A `range: None` content change is a full-document replacement, valid only when the
server negotiated FULL text sync. Strict servers — notably Roslyn
(Microsoft.CodeAnalysis.LanguageServer) — negotiate INCREMENTAL and throw a
NullReferenceException in ProtocolConversions.RangeToLinePositionSpan on the null
range. That faults the request queue and closes the server's stdout (EOF), so edits
stop syncing and completion/hover die on the line being typed (hover still works on
unedited code, which made it look like the server was fine).

Fresh emits full-document changes from several paths (file reload, workspace restore,
plugin edits, event_apply resync). handle_did_change_sequential is the single
chokepoint every didChange (live and queued-replay) flows through; it now detects a
full-document change and, when the negotiated sync kind isn't FULL, re-syncs via
didClose + didOpen — didOpen carries the whole text with no range, so it is correct
under any sync kind. Per-keystroke ranged incremental edits are unaffected.

Adds a negotiated_change_sync_kind() helper and a unit test covering every
TextDocumentSync capability shape (Kind/Options/None).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The fix re-routes a `range: None` change to didClose+didOpen when the
server negotiated a sync kind other than FULL. Drive that path directly:
under INCREMENTAL the tracked document version resets to 0 (proving the
close+open), while a ranged change passes through as a didChange (version
bumps). A second test pins the other side of the condition — under FULL
sync a full-document change stays a didChange. Fails without the fix
(the full-document change bumps the version to 2 instead of resetting).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sfjohansson
sfjohansson marked this pull request as ready for review August 7, 2026 14:58
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.

1 participant