From 396387cead17de963197f0f5af5a0d89860ec6f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saulius=20Menkevi=C4=8Dius?= Date: Thu, 19 May 2022 22:39:09 +0300 Subject: [PATCH] Fix another long-standing incremental document synchronisation bug Most apparent on nvim for some reason. --- CHANGELOG.md | 5 ++++- src/CSharpLanguageServer/RoslynHelpers.fs | 24 +++++++++++++---------- src/CSharpLanguageServer/Server.fs | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cb3d1fe..a977c1f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog -## (unreleased) +## 0.5.1 - 2022-05-19 / Straigiškė +- Fix another long-standing bug with incremental document synchronisation; + - very visible on nvim but affects all editors/clients; + - reported by @Decodetalkers https://github.com/razzmatazz/csharp-language-server/issues/31; - Improve textDocument/completion: - provide `CompletionItem.FilterText` and `CompletionItem.SortText`; diff --git a/src/CSharpLanguageServer/RoslynHelpers.fs b/src/CSharpLanguageServer/RoslynHelpers.fs index 0ad8d36c..89261d6b 100644 --- a/src/CSharpLanguageServer/RoslynHelpers.fs +++ b/src/CSharpLanguageServer/RoslynHelpers.fs @@ -70,18 +70,22 @@ let lspLocationForRoslynLocation(loc: Microsoft.CodeAnalysis.Location): Types.Lo { Uri = ""; Range = { Start = { Line=0; Character=0; }; End = { Line=0; Character=0; } } } -let lspContentChangeEventToRoslynTextChange (sourceText: SourceText) (change: Types.TextDocumentContentChangeEvent) = - let changeTextSpan = - change.Range.Value - |> roslynLinePositionSpanForLspRange - |> sourceText.Lines.GetTextSpan +let applyLspContentChangesOnRoslynSourceText + (changes: Types.TextDocumentContentChangeEvent[]) + (initialSourceText: SourceText) = - TextChange(changeTextSpan, change.Text) + let applyLspContentChangeOnRoslynSourceText (sourceText: SourceText) (change: Types.TextDocumentContentChangeEvent) = + match change.Range with + | Some changeRange -> + let changeTextSpan = + changeRange |> roslynLinePositionSpanForLspRange + |> sourceText.Lines.GetTextSpan -let applyLspContentChangesOnRoslynSourceText (changes: Types.TextDocumentContentChangeEvent[]) (sourceText: SourceText) = - changes - |> Seq.map (lspContentChangeEventToRoslynTextChange sourceText) - |> sourceText.WithChanges + TextChange(changeTextSpan, change.Text) |> sourceText.WithChanges + + | None -> SourceText.From(change.Text) + + changes |> Seq.fold applyLspContentChangeOnRoslynSourceText initialSourceText let lspDocChangesFromSolutionDiff originalSolution diff --git a/src/CSharpLanguageServer/Server.fs b/src/CSharpLanguageServer/Server.fs index 7f139694..8e1aa4f6 100644 --- a/src/CSharpLanguageServer/Server.fs +++ b/src/CSharpLanguageServer/Server.fs @@ -630,7 +630,7 @@ let setupServerHandlers options lspClient = } TextDocumentSync = Some { TextDocumentSyncOptions.Default with - OpenClose = None + OpenClose = Some true Save = Some { IncludeText = Some true } Change = Some TextDocumentSyncKind.Incremental }