Skip to content

Commit

Permalink
Error source highlighting: align using tabs to match tabs in the source
Browse files Browse the repository at this point in the history
Fixes #9116
  • Loading branch information
Armaël Guéneau committed Nov 13, 2019
1 parent 7e842f6 commit 438ba8a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions parsing/location.ml
Expand Up @@ -464,9 +464,15 @@ let highlight_quote ppf
Format.fprintf ppf "%s | %s@," line_nb line;
Format.fprintf ppf "%*s " (String.length line_nb) "";
for pos = line_start_cnum to rightmost.pos_cnum - 1 do
let line_index = pos - line_start_cnum in
if ISet.is_start iset ~pos <> None then
Format.fprintf ppf "@{<%s>" highlight_tag;
if ISet.mem iset ~pos then Format.pp_print_char ppf '^'
else if 0 <= line_index && line_index < String.length line &&
line.[line_index] = '\t' then
(* For alignment purposes, align using a tab for each tab in the
source code *)
Format.pp_print_char ppf '\t'
else Format.pp_print_char ppf ' ';
if ISet.is_end iset ~pos <> None then
Format.fprintf ppf "@}"
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/messages/highlight_tabs.ml
Expand Up @@ -7,7 +7,7 @@
[%%expect{|
Line 1, characters 10-13:
1 | let x = abc
^^^
^^^
Error: Unbound value abc
Hint: Did you mean abs?
|}];;

0 comments on commit 438ba8a

Please sign in to comment.