Skip to content

Commit f7a49db

Browse files
author
Andrew Hall
committed
Reuse types
1 parent 76ee9d5 commit f7a49db

File tree

4 files changed

+9
-31
lines changed

4 files changed

+9
-31
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,11 @@ file sealed class LspDynamicFileProvider(IRazorClientLanguageServerManager clien
4242
requestParams,
4343
cancellationToken).ConfigureAwait(false);
4444

45-
if (response.Updates is null)
46-
{
47-
return null;
48-
}
49-
5045
var textDocument = await WorkspaceExtensions.GetTextDocumentAsync(workspace, response.CSharpDocument.Uri, cancellationToken).ConfigureAwait(false);
5146
var checksum = Convert.FromBase64String(response.Checksum);
5247
var textLoader = new LspTextChangesTextLoader(
5348
textDocument,
54-
response.Updates,
49+
response.Edit,
5550
checksum,
5651
response.ChecksumAlgorithm,
5752
response.SourceEncodingCodePage,

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

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
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;
54
using System.Text;
65
using Microsoft.CodeAnalysis;
76
using Microsoft.CodeAnalysis.ExternalAccess.Razor;
7+
using Microsoft.CodeAnalysis.Razor.Protocol;
88
using Microsoft.CodeAnalysis.Text;
99

1010
namespace Microsoft.VisualStudioCode.RazorExtension.Services;
1111

1212
internal 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
}

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("edits")]
17-
public RazorTextChange[]? Edits { get; set; }
16+
[JsonPropertyName("edit")]
17+
public required RazorTextChange Edit { get; set; }
1818

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

src/Razor/test/Microsoft.CodeAnalysis.Razor.Workspaces.Test/Microsoft.CodeAnalysis.Razor.Workspaces.Test.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,4 @@
1414
<ProjectReference Include="..\Microsoft.AspNetCore.Razor.Test.Common.Tooling\Microsoft.AspNetCore.Razor.Test.Common.Tooling.csproj" />
1515
</ItemGroup>
1616

17-
<ItemGroup>
18-
<Folder Include="ProjectEngineHost\" />
19-
</ItemGroup>
20-
2117
</Project>

0 commit comments

Comments
 (0)