File tree Expand file tree Collapse file tree 6 files changed +66
-4
lines changed Expand file tree Collapse file tree 6 files changed +66
-4
lines changed Original file line number Diff line number Diff line change 6
6
7
7
#### Changed
8
8
9
+ - Preserve indentation in multiline OCaml blocks in .mli files (#395 , @panglesd )
10
+
9
11
#### Deprecated
10
12
11
13
#### Fixed
Original file line number Diff line number Diff line change @@ -158,15 +158,19 @@ let pp_lines syntax t =
158
158
in
159
159
Fmt. (list ~sep: (any " \n " ) pp)
160
160
161
- let lstrip string =
162
- let hpad = Misc. hpad_of_lines [ string ] in
163
- Astring.String. with_index_range string ~first: hpad
161
+ let lstrip strings =
162
+ let hpad = Misc. hpad_of_lines strings in
163
+ List. map
164
+ (fun string ->
165
+ let first = Util.Int. min (Misc. hpad_of_lines [ string ]) hpad in
166
+ Astring.String. with_index_range string ~first )
167
+ strings
164
168
165
169
let pp_contents ?syntax ppf t =
166
170
match (syntax, t.contents) with
167
171
| Some Syntax. Mli , [ line ] -> Fmt. pf ppf " %s" line
168
172
| Some Syntax. Mli , lines ->
169
- Fmt. pf ppf " @\n %a@\n " (pp_lines syntax t) (List. map lstrip lines)
173
+ Fmt. pf ppf " @\n %a@\n " (pp_lines syntax t) (lstrip lines)
170
174
| (Some Cram | Some Normal | None ), [] -> ()
171
175
| (Some Cram | Some Normal | None ), _ ->
172
176
Fmt. pf ppf " %a\n " (pp_lines syntax t) t.contents
Original file line number Diff line number Diff line change @@ -116,3 +116,7 @@ module Process = struct
116
116
let wait ~pid =
117
117
match snd (Unix. waitpid [] pid) with WEXITED n -> n | _ -> 255
118
118
end
119
+
120
+ module Int = struct
121
+ let min a b = if a < b then a else b
122
+ end
Original file line number Diff line number Diff line change @@ -77,3 +77,7 @@ module Process : sig
77
77
Exit code is the same as the child process if it exits normally, or 255
78
78
otherwise. *)
79
79
end
80
+
81
+ module Int : sig
82
+ val min : int -> int -> int
83
+ end
Original file line number Diff line number Diff line change 275
275
(alias runtest)
276
276
(action (diff multilines/test-case .md multilines.actual)))
277
277
278
+ (rule
279
+ (target multilines-mli.actual)
280
+ (deps (package mdx) (source_tree multilines-mli))
281
+ (action
282
+ (with -stdout-to %{ target}
283
+ (chdir multilines-mli
284
+ (run ocaml-mdx test -- output - test-case.mli)))))
285
+
286
+ (rule
287
+ (alias runtest)
288
+ (action (diff multilines-mli/test-case .mli multilines-mli.actual)))
289
+
278
290
(rule
279
291
(target non-det.actual)
280
292
(deps (package mdx) (source_tree non-det))
Original file line number Diff line number Diff line change
1
+ (* *
2
+
3
+ In OCaml docstring everything is indented with two spaces
4
+
5
+ Test multi-lines shell commands:
6
+
7
+ {@sh[
8
+ $ for i in `seq 1 10`; do \
9
+ > echo $i; \
10
+ > done
11
+ 1
12
+ ...
13
+ 10
14
+ ]}
15
+
16
+ This works for normal OCaml fragments:
17
+
18
+ {[
19
+ let rec fact = function
20
+ | 1 -> 1
21
+ | n -> n * fact (n-1)
22
+ ]}
23
+
24
+ The formatting for multilines in .mli files is the following:
25
+ - The first line is indented two spaces after the comment opening
26
+ - The other lines are indented to keep the original indentation relative to the
27
+ first line
28
+
29
+ {[
30
+ match None with
31
+ | None -> ()
32
+ | Some a -> match a with
33
+ | None -> ()
34
+ | Some b -> b
35
+ ]}
36
+ *)
You can’t perform that action at this time.
0 commit comments