Minga.Diagnostics.Diagnostic (Minga v0.1.0)

Copy Markdown View Source

A single diagnostic — an error, warning, info, or hint tied to a location.

Source-agnostic: LSP servers, external linters, compilers, and test runners all produce the same struct. The source field identifies the producer (e.g., "expert", "mix_compile").

Summary

Types

The LSP position encoding used by range columns.

A zero-indexed source location range. Columns are raw offsets in the diagnostic's encoding.

Severity level, ordered from most to least severe.

t()

A diagnostic entry.

Functions

Compares two severities. Returns :lt, :eq, or :gt.

Returns the diagnostic end position as a byte-column position for the given line text.

Returns the more severe of two severities.

Sorts diagnostics by line, then column, then severity (most severe first).

Returns the diagnostic start position as a byte-column position for the given line text.

Types

encoding()

@type encoding() :: :utf8 | :utf16 | :utf32

The LSP position encoding used by range columns.

position()

@type position() :: {line :: non_neg_integer(), col :: non_neg_integer()}

range()

@type range() :: %{
  start_line: non_neg_integer(),
  start_col: non_neg_integer(),
  end_line: non_neg_integer(),
  end_col: non_neg_integer()
}

A zero-indexed source location range. Columns are raw offsets in the diagnostic's encoding.

severity()

@type severity() :: :error | :warning | :info | :hint

Severity level, ordered from most to least severe.

t()

@type t() :: %Minga.Diagnostics.Diagnostic{
  code: String.t() | integer() | nil,
  encoding: encoding(),
  message: String.t(),
  range: range(),
  severity: severity(),
  source: String.t() | nil
}

A diagnostic entry.

Functions

compare_severity(a, b)

@spec compare_severity(severity(), severity()) :: :lt | :eq | :gt

Compares two severities. Returns :lt, :eq, or :gt.

:error is the most severe (lowest rank).

Examples

iex> Minga.Diagnostics.Diagnostic.compare_severity(:error, :warning)
:lt

iex> Minga.Diagnostics.Diagnostic.compare_severity(:hint, :error)
:gt

end_position(diagnostic, line_text)

@spec end_position(t(), String.t()) :: position()

Returns the diagnostic end position as a byte-column position for the given line text.

more_severe(a, b)

@spec more_severe(severity(), severity()) :: severity()

Returns the more severe of two severities.

Examples

iex> Minga.Diagnostics.Diagnostic.more_severe(:warning, :error)
:error

iex> Minga.Diagnostics.Diagnostic.more_severe(:info, :hint)
:info

sort(diagnostics)

@spec sort([t()]) :: [t()]

Sorts diagnostics by line, then column, then severity (most severe first).

start_position(diagnostic, line_text)

@spec start_position(t(), String.t()) :: position()

Returns the diagnostic start position as a byte-column position for the given line text.