Skip to content

Commit c903d32

Browse files
committed
Fix edit mapping for Html documents
1 parent 2ed235b commit c903d32

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/DocumentMapping/AbstractEditMappingService.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ private async Task<Dictionary<string, TextEdit[]>> RemapDocumentEditsAsync(IDocu
5555
{
5656
var generatedDocumentUri = new Uri(uriString);
5757

58+
// For Html we just map the Uri, the range will be the same
59+
if (_filePathService.IsVirtualHtmlFile(generatedDocumentUri))
60+
{
61+
var razorUri = _filePathService.GetRazorDocumentUri(generatedDocumentUri);
62+
remappedChanges[razorUri.AbsoluteUri] = edits;
63+
}
64+
5865
// Check if the edit is actually for a generated document, because if not we don't need to do anything
5966
if (!_filePathService.IsVirtualCSharpFile(generatedDocumentUri))
6067
{
@@ -111,6 +118,18 @@ private async Task<TextDocumentEdit[]> RemapTextDocumentEditsAsync(IDocumentSnap
111118
{
112119
var generatedDocumentUri = entry.TextDocument.DocumentUri.GetRequiredParsedUri();
113120

121+
// For Html we just map the Uri, the range will be the same
122+
if (_filePathService.IsVirtualHtmlFile(generatedDocumentUri))
123+
{
124+
var razorUri = _filePathService.GetRazorDocumentUri(generatedDocumentUri);
125+
entry.TextDocument = new OptionalVersionedTextDocumentIdentifier()
126+
{
127+
DocumentUri = new(razorUri),
128+
};
129+
remappedDocumentEdits.Add(entry);
130+
continue;
131+
}
132+
114133
// Check if the edit is actually for a generated document, because if not we don't need to do anything
115134
if (!_filePathService.IsVirtualCSharpFile(generatedDocumentUri))
116135
{

0 commit comments

Comments
 (0)