-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Highlighting locations in lines with unicode on dumb terminals #11918
Description
In #11899, @hhugo points out that our current approach of highlighting locations using ^^^^ on the line below is fragile in presence of unicode characters with a non-obvious display width.
$ cat c.ml
let (s : string) = "npiπππ" ^ 2
$ ocamlc -c c.ml
File "c.ml", line 1, characters 33-34:
1 | let (s : string) = "npiπππ" ^ 2
^
Error: This expression has type int but an expression was expected of type
stringThe discussion of #11899 clarifies that it seems unrealistic to be able to compute the "right" width at which to place the ^ on the line below (especially within the compiler distribution with a minimal library footprint).
For dumb terminals, typical "on-line" formatting approaches (text font, weight or color, underlining, etc.) are not available.
Proposal 1: conditionally disable the ^s on the line below when there is a "funny" unicode character in the location or on the line to its left. (I assume that a reasonable heuristic for "width-1 characters" can be implemented somewhat easily.)
Proposal 2: un-conditionally use a somewhat-ugly on-line notation using comments, for example one of:
1 | let (s : string) = "npiπππ" ^ (*HERE*)2(*/HERE*)
1 | let (s : string) = "npiπππ" ^ (*here:*)2(**)
1 | let (s : string) = "npiπππ" ^ (*<*)2(*>*)