diff --git a/apps/rebar/src/rebar_compiler_format.erl b/apps/rebar/src/rebar_compiler_format.erl index a8992a67b..f27d5f64a 100644 --- a/apps/rebar/src/rebar_compiler_format.erl +++ b/apps/rebar/src/rebar_compiler_format.erl @@ -23,7 +23,7 @@ format(Source, {Line, Column}, Extra, Desc, Config) -> [LnPad, Source, LnPad, Line, colorize(LnBin, Column), - LnPad, lists:duplicate(max(0, Column-1), " "), Arrow, Extra, Desc]); + LnPad, indent(max(0, Column-1), LnBin), Arrow, Extra, Desc]); _ -> ?FMT("~ts:~w:~w: ~ts~ts~n", [Source, Line, Column, Extra, Desc]) end. @@ -37,6 +37,10 @@ find_line(Nth, Source) -> error:X -> {error, X} end. +indent(0, _) -> ""; +indent(N, <<"\t", Rest/binary>>) -> [$\t | indent(N-1, Rest)]; +indent(N, <<_/utf8, Rest/binary>>) -> [$\s | indent(N-1, Rest)]. + compiler_error_format(Opts) -> %% `Opts' can be passed in both as a list or a dictionary depending %% on whether the first call to rebar_erlc_compiler was done with diff --git a/apps/rebar/test/rebar_compiler_format_SUITE.erl b/apps/rebar/test/rebar_compiler_format_SUITE.erl index e35f5b888..1a7d297f9 100644 --- a/apps/rebar/test/rebar_compiler_format_SUITE.erl +++ b/apps/rebar/test/rebar_compiler_format_SUITE.erl @@ -37,7 +37,7 @@ oracle() -> ++ lists:duplicate(9, $\n) ++ "first character on line 11.\n" ++ lists:duplicate(99, $\n) ++ - "case X of ^whatever % on line 111\n". + "case \tX of ^whatever % on line 111\n". minimal() -> [{doc, "showing minimal (default) output"}]. @@ -48,8 +48,8 @@ minimal(Config) -> rebar_compiler_format:format(Path, {1,20}, "=> ", "unexpected token: ;", Conf)), ?assertEqual(Path++":11:1: some message"++?EOL, rebar_compiler_format:format(Path, {11,1}, "", "some message", Conf)), - ?assertEqual(Path++":111:11: the character '^' is not expected here."++?EOL, - rebar_compiler_format:format(Path, {111,11}, "", "the character '^' is not expected here.", Conf)), + ?assertEqual(Path++":111:12: the character '^' is not expected here."++?EOL, + rebar_compiler_format:format(Path, {111,12}, "", "the character '^' is not expected here.", Conf)), ?assertEqual(Path++":-23:-42: invalid ranges."++?EOL, rebar_compiler_format:format(Path, {-23,-42}, "", "invalid ranges.", Conf)), ?assertEqual(Path++":-23:-42: invalid ranges."++?EOL, @@ -78,9 +78,9 @@ nocolor(Config) -> rebar_compiler_format:format(Path, {11,1}, "", "some message", Conf)), ?assertEqual(" ┌─ "++Path++":"++?EOL++ " │"++?EOL++ - " 111 │ case X of ^whatever % on line 111"++?EOL++ - " │ ╰── the character '^' is not expected here."++?EOL++?EOL, - rebar_compiler_format:format(Path, {111,11}, "", "the character '^' is not expected here.", Conf)), + " 111 │ case \tX of ^whatever % on line 111"++?EOL++ + " │ \t ╰── the character '^' is not expected here."++?EOL++?EOL, + rebar_compiler_format:format(Path, {111,12}, "", "the character '^' is not expected here.", Conf)), %% invalid cases fall back to minimal mode ?assertEqual(Path++":-23:-42: invalid ranges."++?EOL, rebar_compiler_format:format(Path, {-23,-42}, "", "invalid ranges.", Conf)),