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.

Instances For
    Instances For
      @[instance_reducible]
      Instances For

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

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

        Instances For

          Structured result status of a trace node action, produced by withTraceNode and withTraceNodeBefore and included in the TraceData of trace messages. Either .success (✅️), .failure (❌️), or .error (💥️).

          This is used both to render emojis in trace messages and to allow more robust inspection of trace logs via metaprogramming.

          See also Except.toTraceResult for converting an Except ε α to a TraceResult.

          • success : TraceResult

            The traced action succeeded (✅️, checkEmoji).

          • failure : TraceResult

            The traced action failed (❌️, crossEmoji).

          • error : TraceResult

            An exception was thrown during the traced action (💥️, bombEmoji).

          Instances For
            @[instance_reducible]
            @[instance_reducible]

            Convert a TraceResult to its emoji representation.

            Instances For
              structure Lean.TraceData :
              • cls : Name

                Trace class, e.g. Elab.step.

              • Structured success/failure result set by withTraceNode/withTraceNodeBefore. none for trace nodes not created by these functions (e.g. addTrace, diagnostic nodes).

              • 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.

              Instances For

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

                Instances For

                  Eagerly formatted text.

                  Instances For
                    def Lean.MessageData.lazy (f : PPContextBaseIO MessageData) (hasSyntheticSorry : MetavarContextBool := fun (x : MetavarContext) => false) (onMissingContext : UnitBaseIO MessageData := fun (x : Unit) => pure (ofFormat (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).

                    Instances For
                      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.

                      Instances For

                        composePreservingKind msg msg' appends the contents of msg' to the end of msg but ensures that the resulting message preserves the kind (as given by MessageData.kind) of msg.

                        Instances For

                          An empty message.

                          Instances For

                            Simply formats the name. See MessageData.ofConstName for richer messages.

                            Instances For
                              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.

                              Instances For
                                def Lean.MessageData.withExprHover (fmt : Format) (expr : Expr) (lctx : LocalContext) (location? : Option DeclarationLocation := none) (docString? : Option String := none) (mkDocString? : Option (PPContextIO String) := none) (explicit : Bool := false) :

                                Creates message data wrapping fmt that gives information about expr when hovered over.

                                Options:

                                • location? overrides what "go to definition" does
                                • docString? allows overriding the docstring for the expression
                                • mkDocString? allows generating a dynamic docstring; if this is provided, docString? is ignored
                                • explicit makes the hover pretty print the head application in explicit mode; the default value is false (note: delaboration expression hovers normally set this to true, since their purpose is to get more information about a given expression)
                                Instances For
                                  def Lean.MessageData.withExprHoverM {m : TypeType} [Monad m] [MonadLCtx m] (fmt : Format) (expr : Expr) (lctx? : Option LocalContext := none) (location? : Option DeclarationLocation := none) (docString? : Option String := none) (mkDocString? : Option (PPContextIO String) := none) (explicit : Bool := false) :

                                  Calls withExprHover, but uses the current local context if one is not given. See withExprHover for a description of each parameter.

                                  Instances For
                                    def Lean.MessageData.ofUserName {m : TypeType} [Monad m] [MonadLCtx m] (userName : Name) :

                                    Render userName as MessageData, attaching hover information for the local declaration with that user-facing name if it is bound in the current LocalContext. The lookup uses userName verbatim (so macro scopes are preserved for matching) and the rendered name uses userName.simpMacroScopes. Falls back to plain text when the variable is not in scope.

                                    Instances For

                                      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.

                                      @[instance_reducible]
                                      @[instance_reducible]
                                      @[instance_reducible]

                                      Wrap the given message in l and r. See also Format.bracket.

                                      Instances For

                                        Wrap the given message in parentheses ().

                                        Instances For

                                          Wrap the given message in square brackets [].

                                          Instances For

                                            Append the given list of messages with the given separator.

                                            Instances For

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

                                              Instances For

                                                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.

                                                Instances For

                                                  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.

                                                  Instances For

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

                                                    Instances For

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

                                                      Instances For
                                                        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
                                                          @[instance_reducible]
                                                          @[instance_reducible]
                                                          instance Lean.instToJsonBaseMessage {α✝ : Type u_1} [ToJson α✝] :
                                                          def Lean.instToJsonBaseMessage.toJson {α✝ : Type u_1} [ToJson α✝] :
                                                          BaseMessage α✝Json
                                                          Instances For
                                                            @[instance_reducible]
                                                            instance Lean.instFromJsonBaseMessage {α✝ : Type} [FromJson α✝] :
                                                            @[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.

                                                            Instances For

                                                              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.

                                                                Instances For
                                                                  def Lean.kindOfErrorName (errorName : Name) :

                                                                  Creates a tag (i.e., message kind) for an error message with (user-facing) name errorName.

                                                                  Instances For

                                                                    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.

                                                                    Instances For

                                                                      Strip the `nested prefix components added to tags by throwNestedTacticEx.

                                                                      Instances For

                                                                        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.

                                                                        Instances For

                                                                          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.

                                                                          Instances For

                                                                            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.

                                                                            Instances For
                                                                              @[inline]
                                                                              Instances For
                                                                                def Lean.SerialMessage.toString (msg : SerialMessage) (includeEndPos : Bool := false) :
                                                                                Instances For
                                                                                  @[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.

                                                                                  Instances For
                                                                                    Instances For
                                                                                      @[inline]

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

                                                                                      Instances For
                                                                                        def Lean.Message.toString (msg : Message) (includeEndPos : Bool := false) :
                                                                                        Instances For
                                                                                          Instances For

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

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

                                                                                                    Instances For
                                                                                                      def Lean.MessageLog.forM {m : TypeType} [Monad m] (log : MessageLog) (f : Messagem Unit) :
                                                                                                      Instances For

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

                                                                                                        Instances For

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

                                                                                                          Instances For
                                                                                                            Instances For
                                                                                                              Instances For
                                                                                                                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.

                                                                                                                Instances For
                                                                                                                  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.

                                                                                                                  Instances For

                                                                                                                    Atom quotes

                                                                                                                    Instances For
                                                                                                                      • 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
                                                                                                                        Instances For
                                                                                                                          Instances For
                                                                                                                            Instances
                                                                                                                              @[instance_reducible]
                                                                                                                              @[instance_reducible]
                                                                                                                              @[instance_reducible]
                                                                                                                              @[instance_reducible]
                                                                                                                              @[instance_reducible, defaultInstance 1000]
                                                                                                                              @[instance_reducible]
                                                                                                                              @[instance_reducible]
                                                                                                                              @[instance_reducible]
                                                                                                                              @[instance_reducible]
                                                                                                                              @[instance_reducible]
                                                                                                                              def Lean.toTraceElem {α : Type} [ToMessageData α] (e : α) (cls : Name := Name.mkSimple "_") :

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

                                                                                                                              Instances For