Skip to content

Commit

Permalink
split multiline error messages for lsp-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
wies committed Nov 21, 2024
1 parent 1af4ae6 commit 7bbb882
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/util/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(library
(name util)
(libraries base logs fmt logs.fmt stdio library)
(libraries base str logs fmt logs.fmt stdio library)
(preprocess
(pps ppx_hash ppx_compare ppx_sexp_conv ppx_custom_printf)))
7 changes: 5 additions & 2 deletions lib/util/error.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ let to_string (kind, (loc : Loc.t), msg) =
Printf.sprintf !"%{Loc}%{String}%{String}." loc label msg

let to_lsp_string ppf (kind, (loc : Loc.t), msg) =
Stdlib.Format.fprintf ppf !"@\n{ \"file\": \"%{String}\", \"start_line\": %d, \"start_col\": %d, \"end_line\": %d, \"end_col\": %d, \"kind\": \"%s\", \"message\": \"%s\" }"
(Loc.file_name loc) (Loc.start_line loc) (Loc.start_col loc) (Loc.end_line loc) (Loc.end_col loc) (error_kind_to_lsp_string kind) msg
let r = Str.regexp "\n" in
let split_msg = Str.split r msg in
let pr_string ppf s = Stdlib.Format.fprintf ppf "%s" s in
Stdlib.Format.fprintf ppf !"@\n{ \"file\": \"%{String}\", \"start_line\": %d, \"start_col\": %d, \"end_line\": %d, \"end_col\": %d, \"kind\": \"%s\", \"message\": [\"%a\"] }"
(Loc.file_name loc) (Loc.start_line loc) (Loc.start_col loc) (Loc.end_line loc) (Loc.end_col loc) (error_kind_to_lsp_string kind) (Print.pr_list_sep "\", \"" pr_string) split_msg

let errors_to_lsp_string errs =
let print_list ppf errs = Stdlib.Format.fprintf ppf "[@[<2>%a@]]" (Print.pr_list_comma to_lsp_string) errs in
Expand Down

0 comments on commit 7bbb882

Please sign in to comment.