11// Copyright (c) .NET Foundation. All rights reserved.
22// Licensed under the MIT license. See License.txt in the project root for license information.
33
4- using System . Diagnostics ;
54using System . Text ;
65using Microsoft . CodeAnalysis ;
76using Microsoft . CodeAnalysis . ExternalAccess . Razor ;
7+ using Microsoft . CodeAnalysis . Razor . Protocol ;
88using Microsoft . CodeAnalysis . Text ;
99
1010namespace Microsoft . VisualStudioCode . RazorExtension . Services ;
1111
1212internal class LspTextChangesTextLoader (
1313 TextDocument ? document ,
14- IEnumerable < RazorDynamicFileUpdate > updates ,
14+ RazorTextChange change ,
1515 byte [ ] checksum ,
1616 SourceHashAlgorithm checksumAlgorithm ,
1717 int ? codePage ,
@@ -21,7 +21,7 @@ internal class LspTextChangesTextLoader(
2121 private const string ProvideRazorDynamicFileInfoMethodName = "razor/provideDynamicFileInfo" ;
2222
2323 private readonly TextDocument ? _document = document ;
24- private readonly IEnumerable < RazorDynamicFileUpdate > _updates = updates ;
24+ private readonly RazorTextChange _change = change ;
2525 private readonly byte [ ] _checksum = checksum ;
2626 private readonly SourceHashAlgorithm _checksumAlgorithm = checksumAlgorithm ;
2727 private readonly int ? _codePage = codePage ;
@@ -37,7 +37,7 @@ public override async Task<TextAndVersion> LoadTextAndVersionAsync(LoadTextOptio
3737 {
3838 if ( _document is null )
3939 {
40- var text = UpdateSourceTextWithEdits ( _emptySourceText . Value , _updates ) ;
40+ var text = _emptySourceText . Value . WithChanges ( _change . ToTextChange ( ) ) ;
4141 return TextAndVersion . Create ( text , VersionStamp . Default . GetNewerVersion ( ) ) ;
4242 }
4343
@@ -47,7 +47,7 @@ public override async Task<TextAndVersion> LoadTextAndVersionAsync(LoadTextOptio
4747 if ( IsSourceTextMatching ( sourceText ) )
4848 {
4949 var version = await _document . GetTextVersionAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
50- var newText = UpdateSourceTextWithEdits ( sourceText , _updates ) ;
50+ var newText = sourceText . WithChanges ( _change . ToTextChange ( ) ) ;
5151 return TextAndVersion . Create ( newText , version . GetNewerVersion ( ) ) ;
5252 }
5353
@@ -88,20 +88,7 @@ private async Task<TextAndVersion> GetFullDocumentFromServerAsync(CancellationTo
8888 } ,
8989 cancellationToken ) . ConfigureAwait ( false ) ;
9090
91- Debug . Assert ( response . Updates ? . SingleOrDefault ( ) is not null ) ;
92-
93- var text = UpdateSourceTextWithEdits ( _emptySourceText . Value , response . Updates ) ;
91+ var text = _emptySourceText . Value . WithChanges ( response . Edit . ToTextChange ( ) ) ;
9492 return TextAndVersion . Create ( text , VersionStamp . Default . GetNewerVersion ( ) ) ;
9593 }
96-
97- private static SourceText UpdateSourceTextWithEdits ( SourceText sourceText , IEnumerable < RazorDynamicFileUpdate > updates )
98- {
99- foreach ( var update in updates )
100- {
101- var changes = update . Edits . Select ( e => new TextChange ( e . Span . ToTextSpan ( ) , e . NewText ) ) ;
102- sourceText = sourceText . WithChanges ( changes ) ;
103- }
104-
105- return sourceText ;
106- }
10794}
0 commit comments