Skip to content

Commit 40ae152

Browse files
committed
review: Misc.aligned_hint, better documentation
1 parent 6d4a103 commit 40ae152

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

utils/misc.mli

+29-8
Original file line numberDiff line numberDiff line change
@@ -452,21 +452,42 @@ val spellcheck : string list -> string -> string list
452452
val aligned_hint:
453453
prefix:string -> Format_doc.formatter ->
454454
('a, Format_doc.formatter, unit, Format_doc.t option -> unit) format4 -> 'a
455-
(** [aligned_hint ppf fmt ... hint] align the right end of
456-
[@{<ralign>...@}] box in the main error message and the hint under the
457-
assumption that there is an implicit [prefix] before the main
458-
error message. *)
455+
(** [aligned_hint ~prefix ppf fmt ... hint] vertically aligns a main message
456+
(described by the [fmt] format string) and a possible hint message. The
457+
vertical alignment is controlled by the use of [@{<ralign> ... @}] boxes:
458+
the start of one box, in either the hint or the main message, will be
459+
shifted on the left to ensure that the end of the two boxes are vertically
460+
aligned, taking in account a pre-existing [prefix] before the main message.
461+
For instance, if you have already printed ["Error: "] at the beginning of
462+
the current line
463+
464+
{[aligned_hint
465+
~prefix:"Error: " "@{<ralign>The value @}%a is not an instance variable"
466+
Style.inline_code "foobar"
467+
(Some(doc_printf
468+
"@{<ralign>Did you mean @}%a" Style.inline_code "foobaz"
469+
))]}
470+
471+
produces the following text:
472+
473+
{[
474+
Error: The value "foobaz" is not an instance variable
475+
Hint: Did you mean "foobar"?
476+
]}
477+
478+
where the main message has been shifted to the left to align ["foobaz"] and
479+
["foobar"].
480+
*)
459481

460482
val aligned_error_hint:
461483
Format_doc.formatter ->
462484
('a, Format_doc.formatter, unit, Format_doc.t option -> unit) format4 -> 'a
463485
(** Same as [aligned_hint ~prefix:"Error: "] *)
464486

465487
val did_you_mean :
466-
?pp:string Format_doc.printer ->
467-
string list -> Format_doc.t option
468-
(** [did_you_mean ~align ~pp choices] hints that the user may have meant one of
469-
the option in [choices].
488+
?pp:string Format_doc.printer -> string list -> Format_doc.t option
489+
(** [did_you_mean ~pp choices] hints that the user may have meant one of the
490+
option in [choices].
470491
471492
Each choice is printed with the [pp] function, or [Style.inline_code] if
472493
[pp]=[None].

0 commit comments

Comments
 (0)