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., "lexical", "mix_compile").

Summary

Types

A source location range (zero-indexed lines and byte columns).

Severity level, ordered from most to least severe.

t()

A diagnostic entry.

Functions

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

Returns the more severe of two severities.

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

Types

range()

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

A source location range (zero-indexed lines and byte columns).

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,
  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

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