Skip to content

Commit

Permalink
Fix: properly check prefix for non-sexp values
Browse files Browse the repository at this point in the history
  • Loading branch information
lukstafi committed Feb 12, 2024
1 parent cb8efda commit 035f93c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions minidebug_runtime.ml
Original file line number Diff line number Diff line change
Expand Up @@ -711,12 +711,19 @@ module PrintBox (Log_to : Debug_ch) = struct
| Some d ->
B.asprintf_with_style B.Style.preformatted "%s = %a" d Sexplib0.Sexp.pp_hum sexp

let skip_parens s =
let len = String.length s in
let pos = ref 0 in
while !pos < len && (s.[!pos] = '(' || s.[!pos] = '{' || s.[!pos] = '[') do incr pos done;
let s = String.(sub s !pos @@ (length s - !pos)) in
s

let log_value_pp ?descr ~entry_id ~pp ~is_result v =
let prefixed =
match config.log_level with
| Prefixed prefixes | Prefixed_or_result prefixes ->
(* TODO: perf-hint: cache this conversion and maybe don't re-convert. *)
let s = Format.asprintf "%a" pp v in
let s = skip_parens @@ Format.asprintf "%a" pp v in
Array.exists (fun prefix -> String.starts_with ~prefix s) prefixes
| _ -> true
in
Expand All @@ -731,7 +738,8 @@ module PrintBox (Log_to : Debug_ch) = struct
let prefixed =
match config.log_level with
| Prefixed prefixes | Prefixed_or_result prefixes ->
Array.exists (fun prefix -> String.starts_with ~prefix v) prefixes
let s = skip_parens v in
Array.exists (fun prefix -> String.starts_with ~prefix s) prefixes
| _ -> true
in
stack_next ~entry_id ~is_result ~prefixed
Expand Down

0 comments on commit 035f93c

Please sign in to comment.