Sign in

    #diagnostic

    A Diagnostic is a code (SM-SCAN-nnn, SM-PARSE-nnn), a severity, a title, a message under its primary span, secondary labels, notes, and an optional hint and example. It is a value: with_context returns a copy. codes() lists every code.

    ///|
    test {
    debug_inspect(
    @diagnostic.description("SM-PARSE-003"),
    content="Some(\"Missing line break between statements\")",
    )
    }

    Diagnostic

    pub(all) struct Diagnostic {
    code : String
    severity : Severity
    title : String
    message : String
    span :
    Span

    labels : ArrayView[Label]
    notes : ArrayView[String]
    hint : String?
    example : String?
    } derive(Eq,
    Debug
    )

    A problem found while scanning or parsing, with everything a rich report needs: a title in capitals (UNFINISHED SHAPE), a one-line message under the primary span, secondary labels, notes in the first person, an optional hint and an optional correct example. Immutable: with_context returns a new value.

    Diagnostic::is_error

    fn Diagnostic::is_error(self : Diagnostic) -> Bool

    Whether the severity is Error.

    Diagnostic::new

    fn Diagnostic::new(code~ : String, severity~ : Severity, title~ : String, message~ : String, span~ :
    Span
    , labels? : Array[Label], notes? : Array[String], hint? : String, example? : String) -> Diagnostic

    Build a diagnostic; the optional parts default to empty lists and None.

    Diagnostic::with_context

    fn Diagnostic::with_context(self : Diagnostic, label : Label, note : String) -> Diagnostic

    A copy with label as the first label and note as the first note.

    Label

    pub(all) struct Label {
    span :
    Span

    text : String
    } derive(Eq,
    Debug
    )

    A secondary span with the text shown under it ("the structure started here").

    Severity

    pub(all) enum Severity {
    Error
    Warning
    } derive(Eq, Hash,
    Debug
    )

    How serious a diagnostic is. A file with an Error is rejected; a Warning does not stop parsing.

    codes

    fn codes() -> ArrayView[String]

    Every diagnostic code, in table order.

    description

    fn description(code : String) -> String?

    The one-line description of a code, or None for an unknown code.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io