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
Open
Conversation
…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
marked this pull request as ready for review
August 7, 2026 14:58
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug: Roslyn negotiates INCREMENTAL sync, then throws
NullReferenceExceptionon 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 hasrange: Noneand 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.event_applyresync.Tests: unit test over every
TextDocumentSynccapability 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