Source file user_message.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
let pp_to_string pp =
let buffer = Buffer.create 23 in
let formatter = Stdlib.Format.formatter_of_buffer buffer in
Stdlib.Format.fprintf formatter "%a%!" Pp.to_fmt pp;
let contents =
Buffer.contents buffer
|> String.split_lines
|> List.map ~f:(fun s -> String.rstrip s ^ "\n")
|> String.concat
in
contents
;;
let emit_github_annotation ~severity ~loc ~messages ~hints =
let message_text = String.concat ~sep:"" (List.map messages ~f:pp_to_string) in
let hints_text =
match hints with
| None -> ""
| Some hints -> "Hints: " ^ String.concat ~sep:" " (List.map hints ~f:pp_to_string)
in
let github_annotation =
Github_annotation.create
~loc:(Option.value loc ~default:Loc.none)
~severity
~title:"crs"
~message:(String.strip (message_text ^ hints_text))
in
prerr_endline (Github_annotation.to_string github_annotation)
;;
let warning ?loc ~emit_github_annotations ?hints messages =
Err.warning ?loc ?hints messages;
if emit_github_annotations
then emit_github_annotation ~severity:Warning ~loc ~messages ~hints
;;
let error ?loc ~emit_github_annotations ?hints messages =
Err.error ?loc ?hints messages;
if emit_github_annotations
then emit_github_annotation ~severity:Error ~loc ~messages ~hints
;;