Skip to content

Commit

Permalink
Fix another long-standing incremental document synchronisation bug
Browse files Browse the repository at this point in the history
Most apparent on nvim for some reason.
  • Loading branch information
razzmatazz committed May 19, 2022
1 parent 969bb74 commit 396387c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`;

Expand Down
24 changes: 14 additions & 10 deletions src/CSharpLanguageServer/RoslynHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/CSharpLanguageServer/Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 396387c

Please # to comment.