Asai.DiagnosticThe definition of diagnostics and some utility functions.
type severity = | HintThis corresponds to the Hint severity level from LSP (Language Server Protocol). The official specification did not give much guidance on the difference between this level and Info. However, according to the LSP developers, "the idea of the hint severity" is that "for example we in VS Code don't render in the UI as squiggles." They are often used to indicate code smell, along with edit suggestions to fix it.
| InfoThis corresponds to the Information severity level from LSP (Language Server Protocol). The official specification did not give much guidance on the difference between this level and Hint.
| WarningSomething went wrong or looked suspicious, but the end user (the user of your proof assistant or compiler) may choose to ignore the issue. For example, maybe some named arguments were not used in a definition.
*)| ErrorA serious error caused by the end user (the user of your proof assistant or compiler) or other external factors (e.g., internet not working).
*)| BugA serious error likely caused by a bug in the proof assistant. You would want the end user to report the bug back to you. This is useful for indicating that certain branches in a pattern matching should be "impossible", while printing out debugging information in case the program logic is flawed.
*)The type of severity.
The type of texts.
When we render a diagnostic, the layout engine of the diagnostic handler should be the one making layout choices. Therefore, we cannot pass already formatted strings. Instead, a text is defined to be a function that takes a formatter and uses it to render the content. A valid text must satisfy the following two conditions:
\n). It is okay to have break hints (such as @, and @ ) but not literal control characters. This means you should avoid pre-formatted strings, and if you must use them, use text to convert newline characters. Control characters include `U+0000-001F` (C0 controls), `U+007F` (backspace) and `U+0080-009F` (C1 controls). These characters are banned because they would mess up the cursor position.Pro-tip: to format a text in another text, use %t:
let t = textf "@[<2>this is what the master said:@ @[%t@]@]" inner_texttype loctext = text Range.locatedA loctext is a text with location information. "loctext" is a portmanteau of "locate" and "text".
type backtrace = loctext Bwd.bwdA backtrace is a (backward) list of loctexts.
type 'message t = {severity : severity;Severity of the diagnostic.
*)message : 'message;The (structured) message.
*)explanation : loctext;The free-form explanation.
*)backtrace : backtrace;The backtrace leading to this diagnostic.
*)extra_remarks : loctext Bwd.bwd;Additional remarks that are relevant to the main message but not part of the backtrace. It is a backward list so that new remarks can be added to its end easily.
*)}The type of diagnostics.
val text : string -> texttext str converts the string str into a text, converting each '\n' into a call to Format.pp_force_newline.
val textf : ('a, Stdlib.Format.formatter, unit, text) Stdlib.format4 -> 'atextf format ... formats a text. It is an alias of Format.dprintf. Note that there should not be any literal control characters (e.g., literal newline characters).
val ktextf :
(text -> 'b) ->
('a, Stdlib.Format.formatter, unit, 'b) Stdlib.format4 ->
'aktextf kont format ... is kont (textf format ...). It is an alias of Format.kdprintf.
loctextf format ... constructs a loctext. Note that there should not be any literal control characters (e.g., literal newline characters).
val kloctextf :
?loc:Range.t ->
(loctext -> 'b) ->
('a, Stdlib.Format.formatter, unit, 'b) Stdlib.format4 ->
'akloctextf kont format ... is kont (loctextf format ...).
val of_text :
?loc:Range.t ->
?backtrace:backtrace ->
?extra_remarks:loctext list ->
severity ->
'message ->
text ->
'message tof_text severity message text constructs a diagnostic from a text.
Example:
of_text Warning ChiError @@ text "your Ch'i is critically low"val of_loctext :
?backtrace:backtrace ->
?extra_remarks:loctext list ->
severity ->
'message ->
loctext ->
'message tof_loctext severity message loctext constructs a diagnostic from a loctext.
Example:
of_loctext Warning ChiError @@ loctext "your Ch'i is critically low"val make :
?loc:Range.t ->
?backtrace:backtrace ->
?extra_remarks:loctext list ->
severity ->
'message ->
string ->
'message tmake severity message loctext constructs a diagnostic with the loctext.
Example:
make Warning ChiError "your Ch'i is critically low"val makef :
?loc:Range.t ->
?backtrace:backtrace ->
?extra_remarks:loctext list ->
severity ->
'message ->
('a, Stdlib.Format.formatter, unit, 'message t) Stdlib.format4 ->
'amakef severity message format ... is of_loctext severity message (loctextf format ...). It formats the message and constructs a diagnostic out of it.
Example:
makef Warning ChiError "your %s is critically low" "Ch'i"val kmakef :
?loc:Range.t ->
?backtrace:backtrace ->
?extra_remarks:loctext list ->
('message t -> 'b) ->
severity ->
'message ->
('a, Stdlib.Format.formatter, unit, 'b) Stdlib.format4 ->
'akmakef kont severity message format ... is kont (makef severity message format ...).
A convenience function that maps the message of a diagnostic. This is helpful when using Reporter.S.adopt.