Skip to content

Commit be26139

Browse files
author
Andrew Hall
committed
Allow multiple updates to be applied since we allow that in the vs code side
1 parent 6c7b39b commit be26139

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

src/Razor/src/Microsoft.VisualStudioCode.RazorExtension/Services/DynamicFileInfoProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ file sealed class LspDynamicFileProvider(IRazorClientLanguageServerManager clien
4646
var checksum = Convert.FromBase64String(response.Checksum);
4747
var textLoader = new LspTextChangesTextLoader(
4848
textDocument,
49-
response.Edit,
49+
response.Edits,
5050
checksum,
5151
response.ChecksumAlgorithm,
5252
response.SourceEncodingCodePage,

src/Razor/src/Microsoft.VisualStudioCode.RazorExtension/Services/LspTextChangesTextLoader.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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.Collections.Immutable;
45
using System.Text;
56
using Microsoft.CodeAnalysis;
67
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
@@ -11,7 +12,7 @@ namespace Microsoft.VisualStudioCode.RazorExtension.Services;
1112

1213
internal class LspTextChangesTextLoader(
1314
TextDocument? document,
14-
RazorTextChange change,
15+
RazorTextChange[] changes,
1516
byte[] checksum,
1617
SourceHashAlgorithm checksumAlgorithm,
1718
int? codePage,
@@ -21,13 +22,13 @@ internal class LspTextChangesTextLoader(
2122
private const string ProvideRazorDynamicFileInfoMethodName = "razor/provideDynamicFileInfo";
2223

2324
private readonly TextDocument? _document = document;
24-
private readonly RazorTextChange _change = change;
25+
private readonly ImmutableArray<TextChange> _changes = changes.SelectAsArray(c => c.ToTextChange());
2526
private readonly byte[] _checksum = checksum;
2627
private readonly SourceHashAlgorithm _checksumAlgorithm = checksumAlgorithm;
2728
private readonly int? _codePage = codePage;
2829
private readonly Uri _razorUri = razorUri;
2930
private readonly IRazorClientLanguageServerManager _razorClientLanguageServerManager = razorClientLanguageServerManager;
30-
private readonly Lazy<SourceText> _emptySourceText = new Lazy<SourceText>(() =>
31+
private readonly Lazy<SourceText> _emptySourceText = new(() =>
3132
{
3233
var encoding = codePage is null ? null : Encoding.GetEncoding(codePage.Value);
3334
return SourceText.From("", checksumAlgorithm: checksumAlgorithm, encoding: encoding);
@@ -37,7 +38,7 @@ public override async Task<TextAndVersion> LoadTextAndVersionAsync(LoadTextOptio
3738
{
3839
if (_document is null)
3940
{
40-
var text = _emptySourceText.Value.WithChanges(_change.ToTextChange());
41+
var text = ApplyChanges(_emptySourceText.Value, _changes);
4142
return TextAndVersion.Create(text, VersionStamp.Default.GetNewerVersion());
4243
}
4344

@@ -47,7 +48,7 @@ public override async Task<TextAndVersion> LoadTextAndVersionAsync(LoadTextOptio
4748
if (IsSourceTextMatching(sourceText))
4849
{
4950
var version = await _document.GetTextVersionAsync(cancellationToken).ConfigureAwait(false);
50-
var newText = sourceText.WithChanges(_change.ToTextChange());
51+
var newText = ApplyChanges(sourceText, _changes);
5152
return TextAndVersion.Create(newText, version.GetNewerVersion());
5253
}
5354

@@ -88,7 +89,17 @@ private async Task<TextAndVersion> GetFullDocumentFromServerAsync(CancellationTo
8889
},
8990
cancellationToken).ConfigureAwait(false);
9091

91-
var text = _emptySourceText.Value.WithChanges(response.Edit.ToTextChange());
92+
var text = ApplyChanges(_emptySourceText.Value, response.Edits.SelectAsArray(e => e.ToTextChange()));
9293
return TextAndVersion.Create(text, VersionStamp.Default.GetNewerVersion());
9394
}
95+
96+
private static SourceText ApplyChanges(SourceText sourceText, ImmutableArray<TextChange> changes)
97+
{
98+
foreach (var change in changes)
99+
{
100+
sourceText = sourceText.WithChanges(change);
101+
}
102+
103+
return sourceText;
104+
}
94105
}

src/Razor/src/Microsoft.VisualStudioCode.RazorExtension/Services/RazorProvideDynamicFileResponse.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ internal sealed class RazorProvideDynamicFileResponse
1313
[JsonPropertyName("csharpDocument")]
1414
public required TextDocumentIdentifier CSharpDocument { get; set; }
1515

16-
[JsonPropertyName("edit")]
17-
public required RazorTextChange Edit { get; set; }
16+
[JsonPropertyName("edits")]
17+
public required RazorTextChange[] Edits { get; set; }
1818

1919
[JsonPropertyName("checksum")]
2020
public required string Checksum { get; set; }

0 commit comments

Comments
 (0)