mirror of
https://github.com/CatalaLang/catala.git
synced 2024-11-08 07:51:43 +03:00
Globals: add an LSP message format kind
This commit is contained in:
parent
2754bc33d5
commit
ec4c1a260e
@ -18,7 +18,7 @@ type file = string
|
||||
type raw_file = file
|
||||
type backend_lang = En | Fr | Pl
|
||||
type when_enum = Auto | Always | Never
|
||||
type message_format_enum = Human | GNU
|
||||
type message_format_enum = Human | GNU | Lsp
|
||||
|
||||
type 'file input_src =
|
||||
| FileName of 'file
|
||||
|
@ -29,9 +29,8 @@ type backend_lang = En | Fr | Pl
|
||||
(** The usual auto/always/never option argument *)
|
||||
type when_enum = Auto | Always | Never
|
||||
|
||||
type message_format_enum =
|
||||
| Human
|
||||
| GNU (** Format of error and warning messages output by the compiler. *)
|
||||
(** Format of error and warning messages output by the compiler. *)
|
||||
type message_format_enum = Human | GNU | Lsp
|
||||
|
||||
(** Sources for program input *)
|
||||
type 'file input_src =
|
||||
|
@ -317,6 +317,18 @@ module Content = struct
|
||||
ppf content;
|
||||
Format.pp_print_newline ppf ()
|
||||
|
||||
let lsp_msg ppf content =
|
||||
(* Hypothesis: [MainMessage] is always part of a content list. *)
|
||||
let rec retrieve_message acc = function
|
||||
| [] -> acc
|
||||
| MainMessage m :: _ -> Some m
|
||||
| Outcome m :: t ->
|
||||
retrieve_message (match acc with None -> Some m | _ -> acc) t
|
||||
| (Position _ | Suggestion _) :: t -> retrieve_message acc t
|
||||
in
|
||||
let msg = retrieve_message None content in
|
||||
Option.iter (fun msg -> Format.fprintf ppf "%s" (unformat msg)) msg
|
||||
|
||||
let emit ?ppf ?(pp_marker = pp_marker) (content : t) (target : level) : unit =
|
||||
let ppf = Option.value ~default:(get_ppf target) ppf in
|
||||
match Global.options.message_format with
|
||||
@ -325,6 +337,7 @@ module Content = struct
|
||||
| Debug | Log -> basic_msg ~pp_marker ppf target content
|
||||
| Result | Warning | Error -> fancy_msg ~pp_marker ppf target content)
|
||||
| GNU -> gnu_msg ~pp_marker ppf target content
|
||||
| Lsp -> lsp_msg ppf content
|
||||
|
||||
let emit_n ?ppf (target : level) = function
|
||||
| [content] -> emit content target
|
||||
|
Loading…
Reference in New Issue
Block a user