package asai
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=07d2bc322d4da2c3f261205b021d7e8d
sha512=52dc5937a2b319c4b893026aafe1e77f3e3cfe57a420f9d64685fc2b89bfbbeffba7e7428e14ffce531ebaedba28d27eaa87321123ab3e32bf808106c6dd9ace
doc/asai/Asai/Diagnostic/index.html
Module Asai.Diagnostic
Source
The definition of diagnostics and some utility functions.
Types
type severity =
| Hint
(*This 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 andInfo
. 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.| Info
(*This 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 andHint
.| Warning
(*Something 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.
*)| Error
(*A serious error caused by the end user (the user of your proof assistant or compiler) or other external factors (e.g., internet not working).
*)| Bug
(*A 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:
- All string (and character) literals must be encoded using UTF-8.
- All string (and character) literals must not contain control characters (such as the newline character
\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, usetext
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_text
A loctext is a text
with location information. "loctext" is a portmanteau of "locate" and "text".
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.
Constructing Messages
text str
converts the string str
into a text, converting each '\n'
into a call to Format.pp_force_newline
.
textf 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).
ktextf kont format ...
is kont (textf format ...)
. It is an alias of Format.kdprintf
.
loctext str
converts the string str
into a loctext.
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, Format.formatter, unit, 'b) format4 ->
'a
kloctextf kont format ...
is kont (loctextf format ...)
.
Constructing Diagnostics
val of_text :
?loc:Range.t ->
?backtrace:backtrace ->
?extra_remarks:loctext list ->
severity ->
'message ->
text ->
'message t
of_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 t
of_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 t
make 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, Format.formatter, unit, 'message t) format4 ->
'a
makef 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, Format.formatter, unit, 'b) format4 ->
'a
kmakef kont severity message format ...
is kont (makef severity message format ...)
.
Other Helper Functions
A convenience function that maps the message of a diagnostic. This is helpful when using Reporter.S.adopt
.