Skip to content

Commit 05ac751

Browse files
authored
Fix source mappings not appearing in fuse: (#10310)
* Fix source mappings not appearing in fuse: - Move windows path remapping later in the process so that path comparisons for source mappings are unaffected - Add mapping check to test
1 parent 5947b70 commit 05ac751

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/DesignTimeNodeWriterTest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ public void LinePragma_Is_Adjusted_On_Windows(string fileName, string expectedFi
553553
public void LinePragma_Enhanced_Is_Adjusted_On_Windows(string fileName, string expectedFileName)
554554
{
555555
var writer = new RuntimeNodeWriter();
556-
var context = TestCodeRenderingContext.CreateDesignTime();
556+
var context = TestCodeRenderingContext.CreateDesignTime(source: RazorSourceDocument.Create("", fileName));
557557

558558
Assert.True(context.Options.RemapLinePragmaPathsOnWindows);
559559
Assert.True(context.Options.UseEnhancedLinePragma);
@@ -586,6 +586,8 @@ public void LinePragma_Enhanced_Is_Adjusted_On_Windows(string fileName, string e
586586
""",
587587
csharp,
588588
ignoreLineEndingDifferences: true);
589+
590+
Assert.Single(((DefaultCodeRenderingContext)context).SourceMappings);
589591
}
590592

591593

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/CodeGeneration/CodeWriterExtensions.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,7 @@ public static IDisposable BuildLinePragma(this CodeWriter writer, SourceSpan? sp
592592
return NullDisposable.Default;
593593
}
594594

595-
var sourceSpan = RemapFilePathIfNecessary(span.Value, context);
596-
return new LinePragmaWriter(writer, sourceSpan, context, 0, useEnhancedLinePragma: false, suppressLineDefaultAndHidden);
595+
return new LinePragmaWriter(writer, span.Value, context, 0, useEnhancedLinePragma: false, suppressLineDefaultAndHidden);
597596
}
598597

599598
public static IDisposable BuildEnhancedLinePragma(this CodeWriter writer, SourceSpan? span, CodeRenderingContext context, int characterOffset = 0, bool suppressLineDefaultAndHidden = false)
@@ -604,8 +603,7 @@ public static IDisposable BuildEnhancedLinePragma(this CodeWriter writer, Source
604603
return NullDisposable.Default;
605604
}
606605

607-
var sourceSpan = RemapFilePathIfNecessary(span.Value, context);
608-
return new LinePragmaWriter(writer, sourceSpan, context, characterOffset, useEnhancedLinePragma: true, suppressLineDefaultAndHidden);
606+
return new LinePragmaWriter(writer, span.Value, context, characterOffset, useEnhancedLinePragma: true, suppressLineDefaultAndHidden);
609607
}
610608

611609
private static SourceSpan RemapFilePathIfNecessary(SourceSpan sourceSpan, CodeRenderingContext context)
@@ -804,13 +802,14 @@ public LinePragmaWriter(
804802
_writer.WriteLine("#nullable restore");
805803
}
806804

805+
var sourceSpan = RemapFilePathIfNecessary(span, context);
807806
if (useEnhancedLinePragma && _context.Options.UseEnhancedLinePragma)
808807
{
809-
WriteEnhancedLineNumberDirective(writer, span, characterOffset);
808+
WriteEnhancedLineNumberDirective(writer, sourceSpan, characterOffset);
810809
}
811810
else
812811
{
813-
WriteLineNumberDirective(writer, span);
812+
WriteLineNumberDirective(writer, sourceSpan);
814813
}
815814

816815
// Capture the line index after writing the #line directive.

0 commit comments

Comments
 (0)