Skip to content

Commit 4d74ba7

Browse files
committed
Clean up json printing.
1 parent 620f91c commit 4d74ba7

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/EmitJson.ml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,18 @@ let finish () = Format.fprintf Format.std_formatter "\n]\n"
77
let emitClose () =
88
Format.fprintf Format.std_formatter (if !items = 0 then "\n}" else "\n}")
99

10-
let emitItem ~isFirst ~isClosing ~name ~kind ~file ~range ~message =
10+
let emitItem ~name ~kind ~file ~range ~message =
1111
let open Format in
1212
items := !items + 1;
1313
let ppf = std_formatter in
1414
let startLine, startCharacter, endLine, endCharacter = range in
15-
fprintf ppf "%s{\n" (if isFirst then "\n" else ",\n");
15+
fprintf ppf "%s{\n" (if !items = 1 then "\n" else ",\n");
1616
fprintf ppf " \"name\": \"%s\",@." name;
1717
fprintf ppf " \"kind\": \"%s\",@." kind;
1818
fprintf ppf " \"file\": \"%s\",@." file;
1919
fprintf ppf " \"range\": [%d,%d,%d,%d],@." startLine startCharacter endLine
2020
endCharacter;
21-
fprintf ppf " \"message\": \"%s\"" message;
22-
if isClosing then emitClose ()
21+
fprintf ppf " \"message\": \"%s\"" message
2322

2423
let emitAnnotate ~line ~character ~text =
2524
Format.fprintf Format.std_formatter

src/Log_.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,21 @@ let first = ref true
145145
let logKind ~count ~kind ~(loc : CL.Location.t) ~name ~notFinished body =
146146
if Suppress.filter loc.loc_start then (
147147
let open Format in
148-
let isFirst = !first in
149148
first := false;
150149
if count then Stats.count name;
151-
if !Common.Cli.json then
152-
let kind = match kind with Warning -> "warning" | Error -> "error" in
150+
if !Common.Cli.json then (
153151
let file = Json.escape loc.loc_start.pos_fname in
154152
let startLine = loc.loc_start.pos_lnum - 1 in
155153
let startCharacter = loc.loc_start.pos_cnum - loc.loc_start.pos_bol in
156154
let endLine = loc.loc_end.pos_lnum - 1 in
157155
let endCharacter = loc.loc_end.pos_cnum - loc.loc_start.pos_bol in
158156
let message = Json.escape (asprintf "%a" body ()) in
159-
EmitJson.emitItem ~isFirst ~isClosing:(notFinished = false) ~name ~kind
157+
EmitJson.emitItem ~name
158+
~kind:(match kind with Warning -> "warning" | Error -> "error")
160159
~file
161160
~range:(startLine, startCharacter, endLine, endCharacter)
162-
~message
161+
~message;
162+
if notFinished = false then EmitJson.emitClose ())
163163
else
164164
let color =
165165
match kind with Warning -> Color.info | Error -> Color.error

0 commit comments

Comments
 (0)