Pentiment.Formatter.Renderer (pentiment v0.2.0)

View Source

Rich diagnostic formatter with source context and highlighting.

This formatter produces compiler-style error output with:

  • Severity and error code header
  • Source location with unicode box-drawing frame
  • Highlighted source context with underlines and branching labels
  • Notes and help suggestions

Example Output

error[E0001]: Type mismatch
   ╭─[lib/my_app.ex:15:10]
   │
14 │   add = fn x :: integer, y :: integer ->
15 │     x + y + 1.5
   •             ─┬─
   •              ╰── expected `integer`, found `float`
   │
   ╰─────
      note: `+` with integer arguments returns integer
      help: consider using `trunc(1.5)`

Multi-file Diagnostics

Labels carrying their own :source render as continuation frames inside the same diagnostic: the report's own file opens the frame with ╭─[...], each additional file is introduced with ├─[file:line:col] and rendered against its own source, and a single ╰───── closes the frame. Groups whose source is missing from the provided sources render header-only.

Summary

Functions

Formats a single diagnostic for display.

Formats multiple diagnostics for display.

Types

format_options()

@type format_options() :: [
  colors: boolean(),
  context_lines: non_neg_integer(),
  syntax: :auto | boolean(),
  highlighter: module()
]

Functions

format(diagnostic, sources, opts \\ [])

Formats a single diagnostic for display.

Options

  • :colors - Whether to use ANSI colors (default: true, respects IO.ANSI.enabled?())
  • :context_lines - Number of lines of context around labels (default: 2)
  • :syntax - Whether to syntax-highlight source context lines (default: :auto). :auto highlights when colors are active, a highlighter is available, and the source's language is known; false disables. Highlighting is strictly subordinate to :colors — colors: false always yields plain text.
  • :highlighter - Module implementing Pentiment.Highlighter (default: Pentiment.Highlighter.Makeup)

Sources

Sources can be provided as:

format_all(diagnostics, sources, opts \\ [])

@spec format_all(
  [Pentiment.Diagnostic.t()],
  Pentiment.Source.t() | map(),
  format_options()
) ::
  String.t()

Formats multiple diagnostics for display.