Globals: add an LSP message format kind

This commit is contained in:
vbot 2024-10-15 12:03:58 +02:00
parent 2754bc33d5
commit ec4c1a260e
No known key found for this signature in database
GPG Key ID: A2CE1BDBED95DA38
3 changed files with 16 additions and 4 deletions

View File

@ -18,7 +18,7 @@ type file = string
type raw_file = file type raw_file = file
type backend_lang = En | Fr | Pl type backend_lang = En | Fr | Pl
type when_enum = Auto | Always | Never type when_enum = Auto | Always | Never
type message_format_enum = Human | GNU type message_format_enum = Human | GNU | Lsp
type 'file input_src = type 'file input_src =
| FileName of 'file | FileName of 'file

View File

@ -29,9 +29,8 @@ type backend_lang = En | Fr | Pl
(** The usual auto/always/never option argument *) (** The usual auto/always/never option argument *)
type when_enum = Auto | Always | Never type when_enum = Auto | Always | Never
type message_format_enum = (** Format of error and warning messages output by the compiler. *)
| Human type message_format_enum = Human | GNU | Lsp
| GNU (** Format of error and warning messages output by the compiler. *)
(** Sources for program input *) (** Sources for program input *)
type 'file input_src = type 'file input_src =

View File

@ -317,6 +317,18 @@ module Content = struct
ppf content; ppf content;
Format.pp_print_newline ppf () 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 emit ?ppf ?(pp_marker = pp_marker) (content : t) (target : level) : unit =
let ppf = Option.value ~default:(get_ppf target) ppf in let ppf = Option.value ~default:(get_ppf target) ppf in
match Global.options.message_format with match Global.options.message_format with
@ -325,6 +337,7 @@ module Content = struct
| Debug | Log -> basic_msg ~pp_marker ppf target content | Debug | Log -> basic_msg ~pp_marker ppf target content
| Result | Warning | Error -> fancy_msg ~pp_marker ppf target content) | Result | Warning | Error -> fancy_msg ~pp_marker ppf target content)
| GNU -> gnu_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 let emit_n ?ppf (target : level) = function
| [content] -> emit content target | [content] -> emit content target