Skip to content

Commit

Permalink
Ensure we include the line count and end char index in remapped spans (
Browse files Browse the repository at this point in the history
…#9863) (#9887)

* Ensure we include the line count and end char index in remapped spans
* Make the source span in tests have non-default values to ensure they get mapped too
  • Loading branch information
chsienki authored Jan 31, 2024
1 parent d129813 commit 9f6f809
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ private static SourceSpan RemapFilePathIfNecessary(SourceSpan sourceSpan, CodeRe
// If you try and use the line pragma in the design time docs to map back to the original file it will fail,
// as the path isn't actually valid on windows. As a workaround we apply a simple heuristic to switch the
// paths back when writing out the design time paths.
sourceSpan = new SourceSpan(sourceSpan.FilePath.Replace("/", "\\"), sourceSpan.AbsoluteIndex, sourceSpan.LineIndex, sourceSpan.CharacterIndex, sourceSpan.Length);
sourceSpan = new SourceSpan(sourceSpan.FilePath.Replace("/", "\\"), sourceSpan.AbsoluteIndex, sourceSpan.LineIndex, sourceSpan.CharacterIndex, sourceSpan.Length, sourceSpan.LineCount, sourceSpan.EndCharacterIndex);
}
return sourceSpan;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,8 @@ public void LinePragma_Enhanced_Is_Adjusted_On_Windows(string fileName, string e

var node = new CSharpExpressionIntermediateNode()
{
Source = new SourceSpan(fileName, 0, 0, 0, 3),
// Create a fake source span, so we can check it correctly maps in the #line below
Source = new SourceSpan(fileName, 0, 2, 3, 6, 1, 2),
};
var builder = IntermediateNodeBuilder.Create(node);
builder.Add(new IntermediateToken()
Expand All @@ -540,7 +541,7 @@ public void LinePragma_Enhanced_Is_Adjusted_On_Windows(string fileName, string e
$"""
#nullable restore
#line (1,1)-(1,1) 6 "{expectedFileName}"
#line (3,4)-(4,3) 6 "{expectedFileName}"
Write(i++);
#line default
Expand All @@ -552,6 +553,7 @@ public void LinePragma_Enhanced_Is_Adjusted_On_Windows(string fileName, string e
ignoreLineEndingDifferences: true);
}


private DocumentIntermediateNode Lower(RazorCodeDocument codeDocument)
{
var projectEngine = CreateProjectEngine();
Expand Down

0 comments on commit 9f6f809

Please sign in to comment.