Skip to content

Commit

Permalink
boxify: Inline small sexp values (but not when subtrees)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukstafi committed Jan 18, 2024
1 parent eab8578 commit b41c4f0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Include the variable name in the open-log line (just as function name for functions).
- Output the description of a for loop body as `<for [identifier]>` rather than just `[identifier]`.
- `Debug_runtime` functions now take an `~entry_id` parameter, set to a per-entry ID generated by `get_entry_id`.
- Small non-atomic sexp values can now be printed inline with the variable name (like sexp atoms) rather than spread out as trees.

## [0.8.0] -- 2024-01-16

Expand Down
20 changes: 15 additions & 5 deletions minidebug_runtime.ml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ module PrintBox (Log_to : Debug_ch) = struct
let highlighted_roots = ref false
let exclude_on_path = ref None
let values_first_mode = ref false
let max_inline_sexp_size = ref 20
let max_inline_sexp_length = ref 50

module B = PrintBox

Expand Down Expand Up @@ -429,11 +431,19 @@ module PrintBox (Log_to : Debug_ch) = struct
let hls, bs = List.split @@ List.map loop l in
(List.exists (fun x -> x) hls, B.vlist bs)
in
match sexp with
| Atom s | List [ Atom s ] ->
highlight_box @@ B.text_with_style B.Style.preformatted (descr ^ " = " ^ s)
| List [] -> highlight_box @@ B.line descr
| List l -> loop ~as_tree:true @@ List (Atom (descr ^ " =") :: l)
let str =
if sexp_size sexp < min !boxify_sexp_from_size !max_inline_sexp_size then
Sexplib0.Sexp.to_string_hum sexp
else ""
in
if String.length str > 0 && String.length str < !max_inline_sexp_length then
highlight_box @@ B.text_with_style B.Style.preformatted (descr ^ " = " ^ str)
else
match sexp with
| Atom s | List [ Atom s ] ->
highlight_box @@ B.text_with_style B.Style.preformatted (descr ^ " = " ^ s)
| List [] -> highlight_box @@ B.line descr
| List l -> loop ~as_tree:true @@ List (Atom (descr ^ " =") :: l)

let num_children () = match !stack with [] -> 0 | { body; _ } :: _ -> List.length body

Expand Down
6 changes: 6 additions & 0 deletions minidebug_runtime.mli
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ module PrintBox : functor (_ : Debug_ch) -> sig

val values_first_mode : bool ref
(** *)

val max_inline_sexp_size : int ref
(** *)

val max_inline_sexp_length : int ref
(** *)
end

val debug_html :
Expand Down

0 comments on commit b41c4f0

Please sign in to comment.