Skip to content

Commit

Permalink
Message: also notify warnings to LSP
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-botbol committed Nov 4, 2024
1 parent 95d9af2 commit c7c3b3c
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 c7c3b3c

Please sign in to comment.