|
5 | 5 | using System;
|
6 | 6 | using System.Linq;
|
7 | 7 | using System.Threading.Tasks;
|
| 8 | +using Microsoft.CodeAnalysis.LanguageServer.Handler.DocumentChanges; |
8 | 9 | using Roslyn.Test.Utilities;
|
9 | 10 | using Xunit;
|
10 | 11 | using Xunit.Abstractions;
|
@@ -245,7 +246,7 @@ void M()
|
245 | 246 | }
|
246 | 247 |
|
247 | 248 | [Theory, CombinatorialData]
|
248 |
| - public async Task DidChange_MultipleChanges1(bool mutatingLspWorkspace) |
| 249 | + public async Task DidChange_MultipleChanges_ForwardOrder(bool mutatingLspWorkspace) |
249 | 250 | {
|
250 | 251 | var source =
|
251 | 252 | """
|
@@ -285,7 +286,7 @@ void M()
|
285 | 286 | }
|
286 | 287 |
|
287 | 288 | [Theory, CombinatorialData]
|
288 |
| - public async Task DidChange_MultipleChanges2(bool mutatingLspWorkspace) |
| 289 | + public async Task DidChange_MultipleChanges_Overlapping(bool mutatingLspWorkspace) |
289 | 290 | {
|
290 | 291 | var source =
|
291 | 292 | """
|
@@ -323,6 +324,89 @@ void M()
|
323 | 324 | }
|
324 | 325 | }
|
325 | 326 |
|
| 327 | + [Theory, CombinatorialData] |
| 328 | + public async Task DidChange_MultipleChanges_ReverseOrder(bool mutatingLspWorkspace) |
| 329 | + { |
| 330 | + var source = |
| 331 | + """ |
| 332 | + class A |
| 333 | + { |
| 334 | + void M() |
| 335 | + { |
| 336 | + {|type:|} |
| 337 | + } |
| 338 | + } |
| 339 | + """; |
| 340 | + var expected = |
| 341 | + """ |
| 342 | + class A |
| 343 | + { |
| 344 | + void M() |
| 345 | + { |
| 346 | + // hi there |
| 347 | + // this builds on that |
| 348 | + } |
| 349 | + } |
| 350 | + """; |
| 351 | + |
| 352 | + var (testLspServer, locationTyped, _) = await GetTestLspServerAndLocationAsync(source, mutatingLspWorkspace); |
| 353 | + |
| 354 | + await using (testLspServer) |
| 355 | + { |
| 356 | + await DidOpen(testLspServer, locationTyped.Uri); |
| 357 | + |
| 358 | + await DidChange(testLspServer, locationTyped.Uri, (5, 0, " // this builds on that\r\n"), (4, 8, "// hi there")); |
| 359 | + |
| 360 | + var document = testLspServer.GetTrackedTexts().FirstOrDefault(); |
| 361 | + |
| 362 | + AssertEx.NotNull(document); |
| 363 | + Assert.Equal(expected, document.ToString()); |
| 364 | + } |
| 365 | + } |
| 366 | + |
| 367 | + private LSP.TextDocumentContentChangeEvent CreateTextDocumentContentChangeEvent(int startLine, int startCol, int endLine, int endCol, string newText) |
| 368 | + { |
| 369 | + return new LSP.TextDocumentContentChangeEvent() |
| 370 | + { |
| 371 | + Range = new LSP.Range() |
| 372 | + { |
| 373 | + Start = new LSP.Position(startLine, startCol), |
| 374 | + End = new LSP.Position(endLine, endCol) |
| 375 | + }, |
| 376 | + Text = newText |
| 377 | + }; |
| 378 | + } |
| 379 | + |
| 380 | + [Fact] |
| 381 | + public void DidChange_AreChangesInReverseOrder_True() |
| 382 | + { |
| 383 | + LSP.TextDocumentContentChangeEvent change1 = CreateTextDocumentContentChangeEvent(startLine: 0, startCol: 7, endLine: 0, endCol: 9, newText: "test3"); |
| 384 | + LSP.TextDocumentContentChangeEvent change2 = CreateTextDocumentContentChangeEvent(startLine: 0, startCol: 5, endLine: 0, endCol: 7, newText: "test2"); |
| 385 | + LSP.TextDocumentContentChangeEvent change3 = CreateTextDocumentContentChangeEvent(startLine: 0, startCol: 1, endLine: 0, endCol: 3, newText: "test1"); |
| 386 | + |
| 387 | + Assert.True(DidChangeHandler.AreChangesInReverseOrder([change1, change2, change3])); |
| 388 | + } |
| 389 | + |
| 390 | + [Fact] |
| 391 | + public void DidChange_AreChangesInReverseOrder_InForwardOrder() |
| 392 | + { |
| 393 | + LSP.TextDocumentContentChangeEvent change1 = CreateTextDocumentContentChangeEvent(startLine: 0, startCol: 1, endLine: 0, endCol: 3, newText: "test1"); |
| 394 | + LSP.TextDocumentContentChangeEvent change2 = CreateTextDocumentContentChangeEvent(startLine: 0, startCol: 5, endLine: 0, endCol: 7, newText: "test2"); |
| 395 | + LSP.TextDocumentContentChangeEvent change3 = CreateTextDocumentContentChangeEvent(startLine: 0, startCol: 7, endLine: 0, endCol: 9, newText: "test3"); |
| 396 | + |
| 397 | + Assert.False(DidChangeHandler.AreChangesInReverseOrder([change1, change2, change3])); |
| 398 | + } |
| 399 | + |
| 400 | + [Fact] |
| 401 | + public void DidChange_AreChangesInReverseOrder_Overlapping() |
| 402 | + { |
| 403 | + LSP.TextDocumentContentChangeEvent change1 = CreateTextDocumentContentChangeEvent(startLine: 0, startCol: 1, endLine: 0, endCol: 3, newText: "test1"); |
| 404 | + LSP.TextDocumentContentChangeEvent change2 = CreateTextDocumentContentChangeEvent(startLine: 0, startCol: 2, endLine: 0, endCol: 4, newText: "test2"); |
| 405 | + LSP.TextDocumentContentChangeEvent change3 = CreateTextDocumentContentChangeEvent(startLine: 0, startCol: 3, endLine: 0, endCol: 5, newText: "test3"); |
| 406 | + |
| 407 | + Assert.False(DidChangeHandler.AreChangesInReverseOrder([change1, change2, change3])); |
| 408 | + } |
| 409 | + |
326 | 410 | [Theory, CombinatorialData]
|
327 | 411 | public async Task DidChange_MultipleRequests(bool mutatingLspWorkspace)
|
328 | 412 | {
|
|
0 commit comments