|
9 | 9 | using Microsoft.CodeAnalysis.Razor.DocumentMapping;
|
10 | 10 | using Microsoft.CodeAnalysis.Razor.Protocol;
|
11 | 11 | using Microsoft.CodeAnalysis.Razor.Protocol.DocumentMapping;
|
| 12 | +using Microsoft.CodeAnalysis.Testing; |
12 | 13 | using Xunit;
|
13 | 14 | using Xunit.Abstractions;
|
14 | 15 |
|
@@ -190,6 +191,46 @@ public async Task Handle_MapToDocumentRanges_Razor()
|
190 | 191 | Assert.Null(response);
|
191 | 192 | }
|
192 | 193 |
|
| 194 | + [Fact] |
| 195 | + public async Task Handle_MapToDocumentRanges_CSharp_LargeFile() |
| 196 | + { |
| 197 | + // Arrange |
| 198 | + var chsarpAnnotatedSource = """ |
| 199 | + class C |
| 200 | + { |
| 201 | + public void M() |
| 202 | + { |
| 203 | + var currentTime = [|DateTime.Now|]; |
| 204 | + } |
| 205 | + } |
| 206 | + """; |
| 207 | + |
| 208 | + TestFileMarkupParser.GetSpan(chsarpAnnotatedSource, out var csharpSource, out var projectedRange); |
| 209 | + var documentPath = new Uri("C:/path/to/document.cshtml"); |
| 210 | + var codeDocument = CreateCodeDocumentWithCSharpProjection( |
| 211 | + razorSource: "<p>@DateTime.Now</p>", |
| 212 | + projectedCSharpSource: csharpSource, |
| 213 | + sourceMappings: [new SourceMapping(new SourceSpan(4, 12), new SourceSpan(projectedRange.Start, projectedRange.Length))]); |
| 214 | + var documentContext = CreateDocumentContext(documentPath, codeDocument); |
| 215 | + var languageEndpoint = new RazorMapToDocumentRangesEndpoint(_documentMappingService); |
| 216 | + var request = new RazorMapToDocumentRangesParams() |
| 217 | + { |
| 218 | + Kind = RazorLanguageKind.CSharp, |
| 219 | + ProjectedRanges = [LspFactory.CreateSingleLineRange(line: 4, character: 26, length: 12)], |
| 220 | + RazorDocumentUri = documentPath, |
| 221 | + }; |
| 222 | + var expectedRange = LspFactory.CreateSingleLineRange(line: 0, character: 4, length: 12); |
| 223 | + |
| 224 | + var requestContext = CreateRazorRequestContext(documentContext); |
| 225 | + |
| 226 | + // Act |
| 227 | + var response = await languageEndpoint.HandleRequestAsync(request, requestContext, DisposalToken); |
| 228 | + |
| 229 | + // Assert |
| 230 | + Assert.NotNull(response); |
| 231 | + Assert.Equal(expectedRange, response.Ranges[0]); |
| 232 | + } |
| 233 | + |
193 | 234 | private static RazorCodeDocument CreateCodeDocumentWithCSharpProjection(string razorSource, string projectedCSharpSource, ImmutableArray<SourceMapping> sourceMappings)
|
194 | 235 | {
|
195 | 236 | var codeDocument = CreateCodeDocument(razorSource, tagHelpers: []);
|
|
0 commit comments