Documentation

Lean.Message

def Lean.mkErrorStringWithPos (fileName : String) (pos : Position) (msg : String) (endPos : Option Position := none) (kind : Option String := none) (name : Option Name := none) :

Creates a string describing an error message msg produced at pos, optionally ending at endPos, in fileName.

Additional optional arguments can be used to prepend a label kind describing the severity of the error (e.g., "warning" or "error") and a bracketed name label displaying the name of the error if it has one.

Equations
  • One or more equations did not get rendered due to their size.

A naming context is the information needed to shorten names in pretty printing.

It gives the current namespace and the list of open declarations.

structure Lean.TraceData :
  • cls : Name

    Trace class, e.g. Elab.step.

  • startTime : Float

    Start time in seconds; 0 if unknown to avoid Option allocation.

  • stopTime : Float

    Stop time in seconds; 0 if unknown to avoid Option allocation.

  • collapsed : Bool

    Whether trace node defaults to collapsed in the infoview.

  • tag : String

    Optional tag shown in trace.profiler.output output after the trace class name.

Structured message data. We use it for reporting errors, trace messages, etc.

Instances For
def Lean.MessageData.lazy (f : PPContextBaseIO MessageData) (hasSyntheticSorry : MetavarContextBool := fun (x : MetavarContext) => false) (onMissingContext : UnitBaseIO MessageData := fun (x : Unit) => pure (ofFormat (Std.Format.text "(invalid MessageData.lazy, missing context)"))) :

Lazy message data production, with access to the context as given by a surrounding MessageData.withContext (which is expected to exist).

Equations
  • One or more equations did not get rendered due to their size.
partial def Lean.MessageData.hasTag (p : NameBool) :

Returns true when the message contains a MessageData.tagged tag .. constructor where p tag is true.

This does not descend into lazily generated subtrees (.ofLazy); message tags of interest (like those added by logLinter) are expected to be near the root of the MessageData, and not hidden inside .ofLazy.

Returns the top-level tag of the message. If none, returns Name.anonymous.

This does not descend into message subtrees (e.g., .compose, .ofLazy). The message kind is expected to describe the whole message.

Equations
Equations
Equations
  • One or more equations did not get rendered due to their size.
Equations
  • One or more equations did not get rendered due to their size.
Equations
  • One or more equations did not get rendered due to their size.
def Lean.MessageData.ofConstName (constName : Name) (fullNames : Bool := false) :

Represents a constant name such that hovering and "go to definition" works. If there is no such constant in the environment, the name is simply formatted, but sanitized if it is a hygienic name. Use MessageData.ofName if hovers are undesired.

If fullNames is true, then pretty prints as if pp.fullNames is true. Otherwise, pretty prints using the current user setting for pp.fullNames.

Equations
  • One or more equations did not get rendered due to their size.

Maximum number of trace node children to display by default to prevent slowdowns from rendering. In the info view, more children can be expanded interactively.

Equations
Equations
Equations
  • One or more equations did not get rendered due to their size.

Wrap the given message in parentheses ().

Equations

Wrap the given message in square brackets [].

Equations

Write the given list of messages as a list, separating each item with ,\n and surrounding with square brackets.

Equations

Puts MessageData into a comma-separated list with "or" at the back (with the serial comma).

Best used on non-empty lists; returns "– none –" for an empty list.

Equations

Puts MessageData into a comma-separated list with "and" at the back (with the serial comma).

Best used on non-empty lists; returns "– none –" for an empty list.

Equations

Produces a labeled note that can be appended to an error message.

Equations

Produces a labeled hint without an associated code action (non-monadic variant of MessageData.hint).

Equations
structure Lean.BaseMessage (α : Type u) :

A BaseMessage is a richly formatted piece of information emitted by Lean. They are rendered by client editors in the infoview and in diagnostic windows. There are two varieties in the Lean core:

  • fileName : String
  • pos : Position
  • endPos : Option Position
  • keepFullRange : Bool

    If true, report range as given; see msgToInteractiveDiagnostic.

  • severity : MessageSeverity
  • isSilent : Bool

    If true, filter this message from non-language server output. In the language server, silent messages are served as silent diagnostics. See also DiagnosticWith.isSilent?.

  • caption : String
  • data : α

    The content of the message.

Instances For
Equations
  • One or more equations did not get rendered due to their size.
@[reducible, inline]

A Message is a richly formatted piece of information emitted by Lean. They are rendered by client editors in the infoview and in diagnostic windows.

Equations

A SerialMessage is a Message whose MessageData has been eagerly serialized and is thus appropriate for use in pure contexts where the effectful MessageData.toString cannot be used.

Instances For

A suffix added to diagnostic name-containing tags to indicate that they should be used as an error code.

Equations

Produces a MessageData tagged with an identifier for error name.

Note: this function generally should not be called directly; instead, use the macros logNamedError and throwNamedError.

Equations

If the provided name is labeled as a diagnostic name, removes the label and returns the corresponding diagnostic name.

Note: we use this labeling mechanism so that we can have error kinds that are not intended to be shown to the user, without having to validate the presence of an error explanation at runtime.

Equations

Returns the error name with which msg is tagged, if one exists.

Note that this is distinct from msg.kind: the kind of a named-error message is not equal to its name, and there exist message kinds that are not error-name kinds.

Equations

Returns the error name with which msg is tagged, if one exists.

Note that this is distinct from msg.kind: the kind of a named-error message is not equal to its name, and there exist message kinds that are not error-name kinds.

Equations
@[inline]
Equations
  • One or more equations did not get rendered due to their size.
def Lean.SerialMessage.toString (msg : SerialMessage) (includeEndPos : Bool := false) :
Equations
  • One or more equations did not get rendered due to their size.
@[reducible, inline]

Returns the top-level tag of the message. If none, returns Name.anonymous.

This does not descend into message subtrees (e.g., .compose, .ofLazy). The message kind is expected to describe the whole message.

Equations
@[inline]

Serializes the message, converting its data into a string and saving its kind.

Equations
  • One or more equations did not get rendered due to their size.
def Lean.Message.toString (msg : Message) (includeEndPos : Bool := false) :
Equations
Equations

A persistent array of messages.

In the Lean elaborator, we use a fresh message log per command but may also report diagnostics at various points inside a command, which will empty unreported and move its messages to reported. Reported messages are preserved for some specific "lookback" operations such as hasError that should consider the entire message history of the current command; most other functions such as add and toList will only operate on unreported messages.

  • The list of messages already reported (i.e. saved in a Snapshot), in insertion order.

  • The list of messages not already reported, in insertion order.

  • loggedKinds : NameSet

    Set of message kinds that have been added to the log. For example, we have the kind unsafe.exponentiation.warning for warning messages associated with the configuration option exponentiation.threshold. We don't produce a warning if the kind is already in the following set.

Instances For
Equations
@[deprecated "renamed to `unreported`; direct access should in general be avoided in favor of using `MessageLog.toList/toArray`" (since := "2024-05-22")]
Equations
Equations
Equations
Equations

Checks if either of reported or unreported contains an error, i.e. whether the current command has errored yet.

Equations
  • One or more equations did not get rendered due to their size.

Moves unreported messages to reported.

Equations
Equations
  • One or more equations did not get rendered due to their size.
Equations
  • One or more equations did not get rendered due to their size.
Equations
  • One or more equations did not get rendered due to their size.
def Lean.MessageLog.forM {m : TypeType} [Monad m] (log : MessageLog) (f : Messagem Unit) :
Equations

Converts the unreported messages to a list, oldest message first.

Equations

Converts the unreported messages to an array, oldest message first.

Equations
def Lean.inlineExpr (e : Expr) (maxInlineLength : Nat := 30) :

Renders an expression e inline in a message unless it will exceed maxInlineLength characters, in which case the expression is indented on a new line.

Note that the output of this function is formatted with preceding and trailing space included. Thus, in m₁ ++ inlineExpr e ++ m₂, m₁ should not end with a space or new line, nor should m₂ begin with one.

Equations
  • One or more equations did not get rendered due to their size.
def Lean.inlineExprTrailing (e : Expr) (maxInlineLength : Nat := 30) :

See Lean.inlineExpr. This variation is to be used when the expression is the trailing element of a message; it does not append a newline or space after the expression.

Equations
  • One or more equations did not get rendered due to their size.
  • addMessageContext : MessageDatam MessageData

    Without context, a MessageData object may be missing information (e.g. hover info) for pretty printing, or may print an error. Hence, addMessageContext should be called on all constructed MessageData (e.g. via m!) before taking it out of context (e.g. leaving MetaM or CoreM).

Instances
Equations
Equations
  • One or more equations did not get rendered due to their size.
Instances
Equations
  • One or more equations did not get rendered due to their size.
Equations
  • One or more equations did not get rendered due to their size.
Equations
  • One or more equations did not get rendered due to their size.
Equations
  • One or more equations did not get rendered due to their size.
def Lean.toTraceElem {α : Type} [ToMessageData α] (e : α) (cls : Name := Name.mkSimple "_") :

Helper functions for creating a MessageData with the given header and elements.

Equations