diff --git a/infer/src/integration/TextReport.ml b/infer/src/integration/TextReport.ml index ddb228fcc..9383d282d 100644 --- a/infer/src/integration/TextReport.ml +++ b/infer/src/integration/TextReport.ml @@ -57,6 +57,11 @@ let pp_jsonbug fmt {Jsonbug_t.file; severity; line; bug_type; qualifier; _} = F.fprintf fmt "%s:%d: %s: %s@\n %s" file line (String.lowercase severity) bug_type qualifier +let pp_jsonbug_with_number fmt (i, {Jsonbug_t.file; severity; line; bug_type; qualifier; _}) = + F.fprintf fmt "#%d@\n%s:%d: %s: %s@\n %s" i file line (String.lowercase severity) bug_type + qualifier + + let pp_source_context ~indent fmt {Jsonbug_t.file= source_name; lnum= report_line; cnum= report_col; enum= _} = let source_name = @@ -95,8 +100,8 @@ let pp_source_context ~indent fmt let create_from_json ~quiet ~console_limit ~report_txt ~report_json = (* TOOD: possible optimisation: stream reading report.json to process each issue one by one *) let report = Atdgen_runtime.Util.Json.from_file Jsonbug_j.read_report report_json in - let one_issue_to_report_txt fmt (jsonbug : Jsonbug_t.jsonbug) = - F.fprintf fmt "%a@\n%a@\n" pp_jsonbug jsonbug (pp_source_context ~indent:2) + let one_issue_to_report_txt fmt ((_, (jsonbug : Jsonbug_t.jsonbug)) as jsonbug_n) = + F.fprintf fmt "%a@\n%a@\n" pp_jsonbug_with_number jsonbug_n (pp_source_context ~indent:2) {Jsonbug_t.file= jsonbug.file; lnum= jsonbug.line; cnum= jsonbug.column; enum= -1} in let one_issue_to_console ~console_limit i (jsonbug : Jsonbug_t.jsonbug) = @@ -125,7 +130,7 @@ let create_from_json ~quiet ~console_limit ~report_txt ~report_json = let summary = List.foldi report ~init:(ReportSummary.mk_empty ()) ~f:(fun i summary jsonbug -> let summary' = ReportSummary.add_issue summary jsonbug in - one_issue_to_report_txt report_txt_fmt jsonbug ; + one_issue_to_report_txt report_txt_fmt (i, jsonbug) ; if not quiet then one_issue_to_console ~console_limit i jsonbug ; summary' ) in diff --git a/infer/src/integration/TextReport.mli b/infer/src/integration/TextReport.mli index 09aff3fa1..9e18d19ca 100644 --- a/infer/src/integration/TextReport.mli +++ b/infer/src/integration/TextReport.mli @@ -14,4 +14,7 @@ val create_from_json : val pp_jsonbug : F.formatter -> Jsonbug_t.jsonbug -> unit +val pp_jsonbug_with_number : F.formatter -> int * Jsonbug_t.jsonbug -> unit +(** pretty-print an issue together with a number, e.g. to identify it in a list *) + val pp_source_context : indent:int -> F.formatter -> Jsonbug_t.loc -> unit diff --git a/infer/src/integration/TraceBugs.ml b/infer/src/integration/TraceBugs.ml index 0c1cd9729..25d462576 100644 --- a/infer/src/integration/TraceBugs.ml +++ b/infer/src/integration/TraceBugs.ml @@ -31,9 +31,9 @@ let pp_trace_item ~show_source_context fmt {Jsonbug_t.file= filename; lnum= line_number; cnum= column_number; enum= -1} -let pp_issue_with_trace ~show_source_context ~max_nested_level fmt - (n_issue, (issue : Jsonbug_t.jsonbug)) = - F.fprintf fmt "#%d@\n%a@\n" n_issue TextReport.pp_jsonbug issue ; +let pp_issue_with_trace ~show_source_context ~max_nested_level fmt issue_with_n = + F.fprintf fmt "%a@\n" TextReport.pp_jsonbug_with_number issue_with_n ; + let issue : Jsonbug_t.jsonbug = snd issue_with_n in if List.is_empty issue.bug_trace then F.fprintf fmt "@\nEmpty trace@\n%!" else List.iter issue.bug_trace ~f:(fun trace_item -> @@ -49,7 +49,7 @@ let user_select_issue ~selector_limit report = ~f:(fun n issue -> if is_past_limit selector_limit n then Stop () else ( - L.result "#%d@\n%a@\n" n TextReport.pp_jsonbug issue ; + L.result "%a@\n" TextReport.pp_jsonbug_with_number (n, issue) ; Continue (n + 1) ) ) ; let rec ask_until_valid_input max_report = L.result "@\nSelect report to display (0-%d) (default: 0): %!" max_report ;