Skip to content

Commit a961d10

Browse files
author
Andrew Hall
authored
Add more information to dynamic file publish (#11267)
1 parent 14238b2 commit a961d10

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/GeneratedDocumentPublisher.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ public void PublishCSharp(ProjectKey projectKey, string filePath, SourceText sou
101101
ProjectKeyId = projectKey.Id,
102102
Changes = textChanges.Select(static t => t.ToRazorTextChange()).ToArray(),
103103
HostDocumentVersion = hostDocumentVersion,
104-
PreviousWasEmpty = previouslyPublishedData.SourceText.Length == 0
104+
PreviousWasEmpty = previouslyPublishedData.SourceText.Length == 0,
105+
Checksum = Convert.ToBase64String(sourceText.GetChecksum().ToArray()),
106+
ChecksumAlgorithm = sourceText.ChecksumAlgorithm,
107+
SourceEncodingCodePage = sourceText.Encoding?.CodePage
105108
};
106109

107110
_clientConnection.SendNotificationAsync(CustomMessageNames.RazorUpdateCSharpBufferEndpoint, request, CancellationToken.None).Forget();
@@ -145,7 +148,10 @@ public void PublishHtml(ProjectKey projectKey, string filePath, SourceText sourc
145148
ProjectKeyId = projectKey.Id,
146149
Changes = textChanges.Select(static t => t.ToRazorTextChange()).ToArray(),
147150
HostDocumentVersion = hostDocumentVersion,
148-
PreviousWasEmpty = previouslyPublishedData.SourceText.Length == 0
151+
PreviousWasEmpty = previouslyPublishedData.SourceText.Length == 0,
152+
Checksum = Convert.ToBase64String(sourceText.GetChecksum().ToArray()),
153+
ChecksumAlgorithm = sourceText.ChecksumAlgorithm,
154+
SourceEncodingCodePage = sourceText.Encoding?.CodePage
149155
};
150156

151157
_clientConnection.SendNotificationAsync(CustomMessageNames.RazorUpdateHtmlBufferEndpoint, request, CancellationToken.None).Forget();

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Protocol/UpdateBufferRequest.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license. See License.txt in the project root for license information.
33

44
using System.Text.Json.Serialization;
5+
using Microsoft.CodeAnalysis.Text;
56

67
namespace Microsoft.CodeAnalysis.Razor.Protocol;
78

@@ -21,4 +22,13 @@ internal sealed class UpdateBufferRequest
2122

2223
[JsonPropertyName("previousWasEmpty")]
2324
public bool PreviousWasEmpty { get; set; }
25+
26+
[JsonPropertyName("checksum")]
27+
public required string Checksum { get; set; }
28+
29+
[JsonPropertyName("checksumAlgorithm")]
30+
public SourceHashAlgorithm ChecksumAlgorithm { get; set; }
31+
32+
[JsonPropertyName("encodingCodePage")]
33+
public int? SourceEncodingCodePage { get; set; }
2434
}

src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/LanguageClient/RazorCustomMessageTargetTest.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Microsoft.CodeAnalysis.Razor.Protocol.CodeActions;
1818
using Microsoft.CodeAnalysis.Razor.Workspaces;
1919
using Microsoft.CodeAnalysis.Razor.Workspaces.Protocol.SemanticTokens;
20+
using Microsoft.CodeAnalysis.Text;
2021
using Microsoft.VisualStudio.LanguageServer.ContainedLanguage;
2122
using Microsoft.VisualStudio.LanguageServer.Protocol;
2223
using Microsoft.VisualStudio.Razor.LanguageClient.Cohost;
@@ -71,7 +72,10 @@ public async Task UpdateCSharpBuffer_CannotLookupDocument_NoopsGracefully()
7172
var request = new UpdateBufferRequest()
7273
{
7374
HostDocumentFilePath = "C:/path/to/file.razor",
74-
Changes = null
75+
Changes = null,
76+
Checksum = "",
77+
ChecksumAlgorithm = SourceHashAlgorithm.Sha256,
78+
SourceEncodingCodePage = null,
7579
};
7680

7781
// Act & Assert
@@ -115,6 +119,9 @@ public async Task UpdateCSharpBuffer_UpdatesDocument()
115119
HostDocumentFilePath = "C:/path/to/file.razor",
116120
HostDocumentVersion = 1337,
117121
Changes = [],
122+
Checksum = "",
123+
ChecksumAlgorithm = SourceHashAlgorithm.Sha256,
124+
SourceEncodingCodePage = null,
118125
};
119126

120127
// Act
@@ -169,6 +176,9 @@ public async Task UpdateCSharpBuffer_UpdatesCorrectDocument()
169176
HostDocumentFilePath = "C:/path/to/file.razor",
170177
HostDocumentVersion = 1337,
171178
Changes = [],
179+
Checksum = "",
180+
ChecksumAlgorithm = SourceHashAlgorithm.Sha256,
181+
SourceEncodingCodePage = null,
172182
};
173183

174184
// Act

0 commit comments

Comments
 (0)