Skip to content

Commit ed936f2

Browse files
author
Andrew Hall
committed
Fix and add test
1 parent ac9bd79 commit ed936f2

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Mapping/RazorMapToDocumentRangesEndpoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public Uri GetTextDocumentIdentifier(RazorMapToDocumentRangesParams request)
7272
}
7373

7474
ranges[i] = originalRange;
75-
spans[i] = originalRange.ToRazorTextSpan(generatedDocument.Text);
75+
spans[i] = originalRange.ToRazorTextSpan(codeDocument.Source.Text);
7676
}
7777

7878
return new RazorMapToDocumentRangesResponse()

src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Mapping/RazorMapToDocumentRangesEndpointTest.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,44 @@ public async Task Handle_MapToDocumentRanges_Razor()
190190
Assert.Null(response);
191191
}
192192

193+
[Fact]
194+
public async Task Handle_MapToDocumentRanges_CSharp_LargeFile()
195+
{
196+
// Arrange
197+
var csharpSource = """
198+
class C
199+
{
200+
public void M()
201+
{
202+
var currentTime = DateTime.Now;
203+
}
204+
}
205+
""";
206+
var documentPath = new Uri("C:/path/to/document.cshtml");
207+
var codeDocument = CreateCodeDocumentWithCSharpProjection(
208+
razorSource: "<p>@DateTime.Now</p>",
209+
projectedCSharpSource: csharpSource,
210+
sourceMappings: [new SourceMapping(new SourceSpan(4, 12), new SourceSpan(66, 12))]);
211+
var documentContext = CreateDocumentContext(documentPath, codeDocument);
212+
var languageEndpoint = new RazorMapToDocumentRangesEndpoint(_documentMappingService);
213+
var request = new RazorMapToDocumentRangesParams()
214+
{
215+
Kind = RazorLanguageKind.CSharp,
216+
ProjectedRanges = [LspFactory.CreateSingleLineRange(line: 4, character: 26, length: 12)],
217+
RazorDocumentUri = documentPath,
218+
};
219+
var expectedRange = LspFactory.CreateSingleLineRange(line: 0, character: 4, length: 12);
220+
221+
var requestContext = CreateRazorRequestContext(documentContext);
222+
223+
// Act
224+
var response = await languageEndpoint.HandleRequestAsync(request, requestContext, DisposalToken);
225+
226+
// Assert
227+
Assert.NotNull(response);
228+
Assert.Equal(expectedRange, response.Ranges[0]);
229+
}
230+
193231
private static RazorCodeDocument CreateCodeDocumentWithCSharpProjection(string razorSource, string projectedCSharpSource, ImmutableArray<SourceMapping> sourceMappings)
194232
{
195233
var codeDocument = CreateCodeDocument(razorSource, tagHelpers: []);

0 commit comments

Comments
 (0)