@@ -419,7 +419,13 @@ public Document WithFilePath(string? filePath)
419419 /// Get the text changes between this document and a prior version of the same document.
420420 /// The changes, when applied to the text of the old document, will produce the text of the current document.
421421 /// </summary>
422- public async Task < IEnumerable < TextChange > > GetTextChangesAsync ( Document oldDocument , CancellationToken cancellationToken = default )
422+ public Task < IEnumerable < TextChange > > GetTextChangesAsync ( Document oldDocument , CancellationToken cancellationToken = default )
423+ {
424+ return Task . FromResult < IEnumerable < TextChange > > ( GetTextChangesSynchronously ( oldDocument , cancellationToken ) ) ;
425+ }
426+
427+ internal ImmutableArray < TextChange > GetTextChangesSynchronously (
428+ Document oldDocument , CancellationToken cancellationToken )
423429 {
424430 try
425431 {
@@ -443,10 +449,10 @@ public async Task<IEnumerable<TextChange>> GetTextChangesAsync(Document oldDocum
443449 var container = text . Container ;
444450 if ( container != null )
445451 {
446- var textChanges = text . GetTextChanges ( oldText ) . ToList ( ) ;
452+ var textChanges = text . GetTextChanges ( oldText ) . ToImmutableArray ( ) ;
447453
448454 // if changes are significant (not the whole document being replaced) then use these changes
449- if ( textChanges . Count > 1 || ( textChanges . Count == 1 && textChanges [ 0 ] . Span != new TextSpan ( 0 , oldText . Length ) ) )
455+ if ( textChanges . Length > 1 || ( textChanges . Length == 1 && textChanges [ 0 ] . Span != new TextSpan ( 0 , oldText . Length ) ) )
450456 {
451457 return textChanges ;
452458 }
@@ -456,17 +462,18 @@ public async Task<IEnumerable<TextChange>> GetTextChangesAsync(Document oldDocum
456462 // get changes by diffing the trees
457463 if ( this . SupportsSyntaxTree )
458464 {
459- var tree = ( await this . GetSyntaxTreeAsync ( cancellationToken ) . ConfigureAwait ( false ) ) ! ;
460- var oldTree = await oldDocument . GetSyntaxTreeAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
465+ var tree = this . GetSyntaxTreeSynchronously ( cancellationToken ) ;
466+ var oldTree = oldDocument . GetSyntaxTreeSynchronously ( cancellationToken ) ;
461467
468+ RoslynDebug . Assert ( tree is object ) ;
462469 RoslynDebug . Assert ( oldTree is object ) ;
463- return tree . GetChanges ( oldTree ) ;
470+ return tree . GetChanges ( oldTree ) . ToImmutableArray ( ) ;
464471 }
465472
466- text = await this . GetValueTextAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
467- oldText = await oldDocument . GetValueTextAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
473+ text = this . GetTextSynchronously ( cancellationToken ) ;
474+ oldText = oldDocument . GetTextSynchronously ( cancellationToken ) ;
468475
469- return text . GetTextChanges ( oldText ) . ToList ( ) ;
476+ return text . GetTextChanges ( oldText ) . ToImmutableArray ( ) ;
470477 }
471478 }
472479 catch ( Exception e ) when ( FatalError . ReportAndPropagateUnlessCanceled ( e , cancellationToken ) )
0 commit comments