Skip to content

Commit 20fe35f

Browse files
authored
[Super errors] Revert the colors hack (#1913)
Now that we're using a compiler patch for coloring, we can kill the old custom color logic I needed Took the occasion to clean up some comment and a deprecation warning
1 parent bf5ffb2 commit 20fe35f

File tree

8 files changed

+10
-23
lines changed

8 files changed

+10
-23
lines changed

jscomp/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ BSB_SRCS= bsb_config\
345345
oCamlRes\
346346
bsb_templates\
347347
bsb_init
348-
SUPER_ERRORS_SRCS=super_misc super_warnings super_typecore super_typetexp super_location super_main
348+
SUPER_ERRORS_SRCS=super_misc super_warnings super_location super_typecore super_typetexp super_main
349349
REASON_OUTCOME_PRINTER_SRCS=tweaked_reason_oprint reason_outcome_printer_main
350350

351351
BSB_CMXS=$(addprefix bsb/, $(addsuffix .cmx, $(BSB_SRCS)))

jscomp/super_errors/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Hello! This is the subdirectory for the new, newcomer-friendly OCaml/Reason warning & error report system. Most of the logic are lifted from the compiler (https://github.com/ocaml/ocaml/tree/4.02). The convention here is to have a `super_foo` for each corresponding compiler's file `foo`. So, for example, `warnings.ml` becomes `super_warnings.ml`. The exception is `super_main`, the entry point.
1+
Hello! This is the subdirectory for the new, newcomer-friendly OCaml/Reason warning & error report system. Most of the logic are lifted from the compiler (https://github.com/BuckleScript/ocaml/tree/master). The convention here is to have a `super_foo` for each corresponding compiler's file `foo`. So, for example, `warnings.ml` becomes `super_warnings.ml`. The exception is `super_main`, the entry point.
22

33
Feel free to submit new ones or tweak existing messages in these files! They also have more precise comments in them that tells you how they work.
44

jscomp/super_errors/super_location.ml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ let print ~is_warning intro ppf loc =
8181
end
8282
;;
8383

84-
(* taken from https://github.com/ocaml/ocaml/blob/4.02/parsing/location.ml#L337 *)
84+
(* taken from https://github.com/BuckleScript/ocaml/blob/d4144647d1bf9bc7dc3aadc24c25a7efa3a67915/parsing/location.ml#L380 *)
8585
(* This is the error report entry point. We'll replace the default reporter with this one. *)
8686
let rec super_error_reporter ppf ({Location.loc; msg; sub; if_highlight} as err) =
8787
let highlighted =
@@ -97,19 +97,17 @@ let rec super_error_reporter ppf ({Location.loc; msg; sub; if_highlight} as err)
9797
if highlighted then
9898
Format.pp_print_string ppf if_highlight
9999
else begin
100-
Super_misc.setup_colors ppf;
101100
(* open a vertical box. Everything in our message is indented 2 spaces *)
102101
Format.fprintf ppf "@[<v 2>@,%a@,%s@,@]" (print ~is_warning:false "We've found a bug for you!") loc msg;
103102
List.iter (Format.fprintf ppf "@,@[%a@]" super_error_reporter) sub;
104103
(* no need to flush here; location's report_exception (which uses this ultimately) flushes *)
105104
end
106105

107-
(* extracted from https://github.com/ocaml/ocaml/blob/4.02/parsing/location.ml#L280 *)
106+
(* extracted from https://github.com/BuckleScript/ocaml/blob/d4144647d1bf9bc7dc3aadc24c25a7efa3a67915/parsing/location.ml#L299 *)
108107
(* This is the warning report entry point. We'll replace the default printer with this one *)
109108
let super_warning_printer loc ppf w =
110109
if Warnings.is_active w then begin
111-
Super_misc.setup_colors ppf;
112-
Misc.Color.setup !Clflags.color;
110+
setup_colors ();
113111
(* open a vertical box. Everything in our message is indented 2 spaces *)
114112
Format.fprintf ppf "@[<v 2>@,%a@,%a@,@]"
115113
(print ~is_warning:true ("Warning number " ^ (Super_warnings.number w |> string_of_int)))

jscomp/super_errors/super_misc.ml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,3 @@ ppf
129129

130130
done;
131131
fprintf ppf "@]" (* v *)
132-
133-
let setup_colors ppf =
134-
Format.pp_set_formatter_tag_functions ppf
135-
({ (Format.pp_get_formatter_tag_functions ppf () ) with
136-
mark_open_tag = Ext_color.ansi_of_tag;
137-
mark_close_tag = (fun _ -> Ext_color.reset_lit);
138-
})

jscomp/super_errors/super_misc.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
(** Range coordinates all 1-indexed, like for editors. Otherwise this code
22
would have way too many off-by-one errors *)
33
val print_file: is_warning:bool -> range:(int * int) * (int * int) -> lines:string array -> Format.formatter -> unit -> unit
4-
5-
val setup_colors: Format.formatter -> unit

jscomp/super_errors/super_typecore.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ open Ctype
99
open Format
1010
open Printtyp
1111

12-
(* taken from https://github.com/ocaml/ocaml/blob/4.02/typing/typecore.ml#L3769 *)
12+
(* taken from https://github.com/BuckleScript/ocaml/blob/d4144647d1bf9bc7dc3aadc24c25a7efa3a67915/typing/typecore.ml#L3769 *)
1313
(* modified branches are commented *)
1414
let report_error env ppf = function
1515
| Typecore.Polymorphic_label lid ->
@@ -231,9 +231,7 @@ let report_error env ppf = function
231231
fprintf ppf
232232
"@[Exception patterns must be at the top level of a match case.@]"
233233

234-
(* https://github.com/ocaml/ocaml/blob/4.02/typing/typecore.ml#L3979 *)
235234
let report_error env ppf err =
236-
Super_misc.setup_colors ppf;
237235
wrap_printing_env env (fun () -> report_error env ppf err)
238236

239237
(* This will be called in super_main. This is how you'd override the default error printer from the compiler & register new error_of_exn handlers *)

jscomp/super_errors/super_typetexp.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ let spellcheck ppf fold env lid =
5454
let spellcheck ppf fold =
5555
spellcheck ppf (fun f -> fold (fun s _ _ x -> f s x))
5656

57-
(* taken from https://github.com/ocaml/ocaml/blob/4.02/typing/typetexp.ml#L911 *)
57+
(* taken from https://github.com/BuckleScript/ocaml/blob/d4144647d1bf9bc7dc3aadc24c25a7efa3a67915/typing/typetexp.ml#L918 *)
5858
(* modified branches are commented *)
5959
let report_error env ppf = function
6060
| Typetexp.Unbound_type_variable name ->

jscomp/super_errors/super_warnings.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
let fprintf = Format.fprintf
2-
(* this is lifted https://github.com/ocaml/ocaml/blob/4.02/utils/warnings.ml *)
2+
(* taken from https://github.com/BuckleScript/ocaml/blob/d4144647d1bf9bc7dc3aadc24c25a7efa3a67915/utils/warnings.ml#L251 *)
33
(* actual modified message branches are commented *)
44
let message = Warnings.(function
55
| Comment_start -> "this is the start of a comment."
66
| Comment_not_end -> "this is not the end of a comment."
7-
| Deprecated s -> "deprecated: " ^ s
7+
| Deprecated s -> s ^ " is deprecated. "
88
| Fragile_match "" ->
99
"this pattern-matching is fragile."
1010
| Fragile_match s ->
@@ -210,7 +210,7 @@ let number = Warnings.(function
210210
| Bad_docstring _ -> 50
211211
);;
212212

213-
(* helper extracted from https://github.com/ocaml/ocaml/blob/4.02/utils/warnings.ml#L396 *)
213+
(* taken from https://github.com/BuckleScript/ocaml/blob/d4144647d1bf9bc7dc3aadc24c25a7efa3a67915/utils/warnings.ml#L396 *)
214214
(* the only difference is the 2 first `let`s, where we use our own `message`
215215
and `number` functions, and the last line commented out because we don't use
216216
it (not sure what it's for, actually) *)

0 commit comments

Comments
 (0)