Pentiment.Formatter.Renderer (pentiment v0.2.0)
View SourceRich 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
Types
@type format_options() :: [ colors: boolean(), context_lines: non_neg_integer(), syntax: :auto | boolean(), highlighter: module() ]
Functions
@spec format(Pentiment.Diagnostic.t(), Pentiment.Source.t() | map(), format_options()) :: String.t()
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).:autohighlights when colors are active, a highlighter is available, and the source's language is known;falsedisables. Highlighting is strictly subordinate to:colors—colors: falsealways yields plain text.:highlighter- Module implementingPentiment.Highlighter(default:Pentiment.Highlighter.Makeup)
Sources
Sources can be provided as:
- A
Pentiment.Sourcestruct - A map of source names to content strings:
%{"file.ex" => "content..."} - A map of source names to
Pentiment.Sourcestructs
@spec format_all( [Pentiment.Diagnostic.t()], Pentiment.Source.t() | map(), format_options() ) :: String.t()
Formats multiple diagnostics for display.