Skip to content

Commit

Permalink
preserve tabs in rich compiler output
Browse files Browse the repository at this point in the history
  • Loading branch information
ferd committed Apr 16, 2024
1 parent bfc6839 commit 017fe3c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 5 additions & 1 deletion apps/rebar/src/rebar_compiler_format.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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, <<_:1/binary, 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
Expand Down
12 changes: 6 additions & 6 deletions apps/rebar/test/rebar_compiler_format_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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"}].
Expand All @@ -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,
Expand Down Expand Up @@ -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)),
Expand Down

0 comments on commit 017fe3c

Please sign in to comment.