Documentation

Lean.Message

def Lean.mkErrorStringWithPos (fileName : String) (pos : Position) (msg : String) (endPos : Option Position := none) :
Equations
    Instances For
      Instances For
        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
            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.

            Instances For

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

              Instances For

                Eagerly formatted text.

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

                        Equations
                          Instances For
                            Equations
                              Instances For

                                An empty message.

                                Equations
                                  Instances For
                                    Equations
                                      Instances For
                                        Equations
                                          Instances For
                                            Equations
                                              Instances For

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

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

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

                                                            Equations
                                                              Instances For
                                                                Equations
                                                                  Instances For

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

                                                                    Equations
                                                                      Instances For

                                                                        Wrap the given message in parentheses ().

                                                                        Equations
                                                                          Instances For

                                                                            Wrap the given message in square brackets [].

                                                                            Equations
                                                                              Instances For

                                                                                Append the given list of messages with the given separator.

                                                                                Equations
                                                                                  Instances For

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

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

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

                                                                                            Equations
                                                                                              Instances For

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

                                                                                                Equations
                                                                                                  Instances For

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

                                                                                                    Equations
                                                                                                      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
                                                                                                          Equations
                                                                                                            instance Lean.instToJsonBaseMessage {α✝ : Type u_1} [ToJson α✝] :
                                                                                                            Equations
                                                                                                              instance Lean.instFromJsonBaseMessage {α✝ : Type} [FromJson α✝] :
                                                                                                              Equations
                                                                                                                @[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
                                                                                                                  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
                                                                                                                      @[inline]
                                                                                                                      Equations
                                                                                                                        Instances For
                                                                                                                          def Lean.SerialMessage.toString (msg : SerialMessage) (includeEndPos : Bool := false) :
                                                                                                                          Equations
                                                                                                                            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.

                                                                                                                              Equations
                                                                                                                                Instances For
                                                                                                                                  Equations
                                                                                                                                    Instances For
                                                                                                                                      @[inline]

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

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

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

                                                                                                                                                                        Equations
                                                                                                                                                                          Instances For

                                                                                                                                                                            Moves unreported messages to reported.

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

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

                                                                                                                                                                                        Equations
                                                                                                                                                                                          Instances For

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

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

                                                                                                                                                                                                            Equations
                                                                                                                                                                                                              Instances For

                                                                                                                                                                                                                Atom quotes

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

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

                                                                                                                                                                                                                                                Equations
                                                                                                                                                                                                                                                  Instances For