Skip to content

Commit

Permalink
Add warning notification and add utility function to passes (#743)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-botbol authored Nov 5, 2024
2 parents 1a9eab4 + 5f57f4b commit eeb820c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
23 changes: 21 additions & 2 deletions compiler/catala_utils/message.ml
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ open Content
exception CompilerError of Content.t
exception CompilerErrors of Content.t list

type lsp_error_kind = Lexing | Parsing | Typing | Generic
type lsp_error_kind = Lexing | Parsing | Typing | Generic | Warning

type lsp_error = {
kind : lsp_error_kind;
Expand Down Expand Up @@ -448,7 +448,6 @@ let debug = make ~level:Debug ~cont:emit
let log = make ~level:Log ~cont:emit
let result = make ~level:Result ~cont:emit
let results r = emit (List.flatten (List.map of_result r)) Result
let warning = make ~level:Warning ~cont:emit

let join_pos ~pos ~fmt_pos ~extra_pos =
(* Error positioning might be provided using multiple options. Thus, we look
Expand All @@ -459,6 +458,26 @@ let join_pos ~pos ~fmt_pos ~extra_pos =
Some pos
| _ -> None

let warning
?header
?internal
?pos
?pos_msg
?extra_pos
?fmt_pos
?outcome
?suggestion
fmt =
make ?header ?internal ?pos ?pos_msg ?extra_pos ?fmt_pos ?outcome ?suggestion
fmt ~level:Warning ~cont:(fun m x ->
Option.iter
(fun f ->
let message ppf = Content.emit ~ppf m Warning in
let pos = join_pos ~pos ~fmt_pos ~extra_pos in
f { kind = Warning; message; pos; suggestion })
!global_error_hook;
emit m x)

let error ?(kind = Generic) : ('a, 'exn) emitter =
fun ?header ?internal ?pos ?pos_msg ?extra_pos ?fmt_pos ?outcome ?suggestion
fmt ->
Expand Down
2 changes: 1 addition & 1 deletion compiler/catala_utils/message.mli
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ end
exception CompilerError of Content.t
exception CompilerErrors of Content.t list

type lsp_error_kind = Lexing | Parsing | Typing | Generic
type lsp_error_kind = Lexing | Parsing | Typing | Generic | Warning

type lsp_error = {
kind : lsp_error_kind;
Expand Down

0 comments on commit eeb820c

Please sign in to comment.