Skip to content

Commit bba2a06

Browse files
committed
Fix text-diff representation of multiline item changes
Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
1 parent cce257f commit bba2a06

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

lib/text_diff.ml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,37 @@ open Types
22

33
type t = Diffutils.Diff.t String_map.t
44

5-
let vd_to_string name vd =
5+
let vd_to_lines name vd =
66
let buf = Buffer.create 256 in
77
let formatter = Format.formatter_of_buffer buf in
88
Printtyp.value_description (Ident.create_local name) formatter vd;
99
Format.pp_print_flush formatter ();
10-
Buffer.contents buf
10+
CCString.lines (Buffer.contents buf)
1111

12-
let md_to_string name md =
12+
let md_to_lines name md =
1313
let buf = Buffer.create 256 in
1414
let formatter = Format.formatter_of_buffer buf in
1515
Printtyp.modtype formatter md.md_type;
1616
Format.pp_print_flush formatter ();
17-
"module " ^ name ^ ": " ^ Buffer.contents buf
17+
let module_str = "module " ^ name ^ ": " ^ Buffer.contents buf in
18+
CCString.lines module_str
1819

1920
let process_value_diff (val_diff : Diff.value) =
2021
match val_diff.vdiff with
2122
| Added vd ->
2223
[
23-
Diffutils.Diff.Diff
24-
{ orig = []; new_ = [ vd_to_string val_diff.vname vd ] };
24+
Diffutils.Diff.Diff { orig = []; new_ = vd_to_lines val_diff.vname vd };
2525
]
2626
| Removed vd ->
2727
[
28-
Diffutils.Diff.Diff
29-
{ orig = [ vd_to_string val_diff.vname vd ]; new_ = [] };
28+
Diffutils.Diff.Diff { orig = vd_to_lines val_diff.vname vd; new_ = [] };
3029
]
3130
| Modified { reference; current } ->
3231
[
3332
Diffutils.Diff.Diff
3433
{
35-
orig = [ vd_to_string val_diff.vname reference ];
36-
new_ = [ vd_to_string val_diff.vname current ];
34+
orig = vd_to_lines val_diff.vname reference;
35+
new_ = vd_to_lines val_diff.vname current;
3736
};
3837
]
3938

@@ -50,7 +49,7 @@ let from_diff (diff : Diff.module_) : Diffutils.Diff.t String_map.t =
5049
let diff =
5150
[
5251
Diffutils.Diff.Diff
53-
{ orig = []; new_ = [ md_to_string module_diff.mname curr_md ] };
52+
{ orig = []; new_ = md_to_lines module_diff.mname curr_md };
5453
]
5554
in
5655
String_map.update module_path
@@ -61,7 +60,7 @@ let from_diff (diff : Diff.module_) : Diffutils.Diff.t String_map.t =
6160
let diff =
6261
[
6362
Diffutils.Diff.Diff
64-
{ orig = [ md_to_string module_diff.mname ref_md ]; new_ = [] };
63+
{ orig = md_to_lines module_diff.mname ref_md; new_ = [] };
6564
]
6665
in
6766
String_map.update module_path

tests/api-watch/test_text_diff.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ let%expect_test "multi-line items are represented as multi-line diffs" =
2929
{|
3030
diff module Main:
3131
+val f :
32-
some_long_labeled_argument:int ->
33-
some_other_long_labeled_arg:int * int -> string * string -> unit -> string
32+
+ some_long_labeled_argument:int ->
33+
+ some_other_long_labeled_arg:int * int -> string * string -> unit -> string
3434
+module M: sig
35-
val some_val : int -> int -> int -> string
36-
val some_other_val : string -> string -> string -> int
37-
val yet_some_other_val : string -> bool -> string
38-
end
35+
+ val some_val : int -> int -> int -> string
36+
+ val some_other_val : string -> string -> string -> int
37+
+ val yet_some_other_val : string -> bool -> string
38+
+end
3939
|}]

0 commit comments

Comments
 (0)