Skip to content

Commit

Permalink
Merge pull request #1717 from riganti/log-warning-fix-padding
Browse files Browse the repository at this point in the history
Fix whitespace padding width with tabs and Unicode combining characters
  • Loading branch information
tomasherceg authored Oct 22, 2023
2 parents 8e8ce4d + a598b29 commit c599b7f
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using DotVVM.Framework.Compilation.ControlTree;
using DotVVM.Framework.Compilation.ControlTree.Resolved;
Expand Down Expand Up @@ -148,10 +149,19 @@ public override string ToString()
""
);
string error;
if (ContextLine is {})
if (ContextLine is {} contextLine)
{
var errorHighlight = new string(' ', CharPosition ?? 1) + new string('^', HighlightLength);
error = $"{fileLocation}: Dotvvm Compilation Warning\n{ContextLine}\n{errorHighlight} {Message}";
var graphemeIndices = StringInfo.ParseCombiningCharacters(contextLine.Substring(0, Math.Min(contextLine.Length, CharPosition ?? 0)));
var padding = string.Concat(
graphemeIndices.Select(
startIndex => contextLine[startIndex] switch {
'\t' => "\t",
_ => " "
}
)
);
var errorHighlight = padding + new string('^', HighlightLength);
error = $"{fileLocation}: Dotvvm Compilation Warning\n{contextLine}\n{errorHighlight} {Message}";
}
else
{
Expand Down

0 comments on commit c599b7f

Please sign in to comment.