A stable, LSP-shaped diagnostic returned by Letterpress operations.
Ranges use zero-based UTF-16 line and character coordinates so the same
positions work in Elixir responses and browser editors. source_hash and
document_version let a host discard stale asynchronous results.
Diagnostic codes and the JSON shape are public contract. English messages
are written for people and may improve between releases; application logic
should match on code and, when needed, structured data.
Example
iex> diagnostic =
...> Letterpress.Diagnostic.simple("LP_SCHEMA_UNUSED_VARIABLE", "Check this value", :warning)
iex> {diagnostic.code, diagnostic.severity, diagnostic.range.start}
{"LP_SCHEMA_UNUSED_VARIABLE", :warning, %{line: 0, character: 0}}
Summary
Types
A zero-based UTF-16 document position.
A half-open source range from :start to :end.
Severity understood by ExDoc consumers and LSP-compatible editors.
A version-1 Letterpress diagnostic.
Functions
Returns whether a list contains an error diagnostic.
Converts compiler diagnostic maps into t/0 structs.
Creates a document-level diagnostic for local validation.
Creates a redacted diagnostic for a compiler or runtime boundary failure.
Returns the string-keyed JSON projection of a diagnostic.
Types
@type point() :: %{line: non_neg_integer(), character: non_neg_integer()}
A zero-based UTF-16 document position.
A half-open source range from :start to :end.
@type severity() :: :error | :warning | :information | :hint
Severity understood by ExDoc consumers and LSP-compatible editors.
@type t() :: %Letterpress.Diagnostic{ code: String.t(), data: map(), document_version: non_neg_integer(), message: String.t(), range: range(), related: [map()], severity: severity(), source: String.t(), source_hash: String.t(), version: 1 }
A version-1 Letterpress diagnostic.
Functions
Returns whether a list contains an error diagnostic.
Example
iex> warning =
...> Letterpress.Diagnostic.simple("LP_SCHEMA_UNUSED_VARIABLE", "Heads up", :warning)
iex> error = Letterpress.Diagnostic.simple("LP_SCHEMA_INVALID", "Stop")
iex> Letterpress.Diagnostic.errors?([warning, error])
true
Converts compiler diagnostic maps into t/0 structs.
Only the four known severity strings become atoms. Unknown severities fall
back to :error, and missing optional fields receive contract defaults.
Creates a document-level diagnostic for local validation.
The range points to the start of the document, and the severity defaults to
:error.
Creates a redacted diagnostic for a compiler or runtime boundary failure.
The returned diagnostic preserves the profile, source hash, and document version but never copies template source or resolved values into its message or data.
Returns the string-keyed JSON projection of a diagnostic.
Severity becomes a string; range point keys also become strings. The result contains only JSON-native values when the struct came from Letterpress.