diagnostic

package
v1.16.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package diagnostic provides Rust-style annotated error rendering for ELPS CLI output. It is intentionally independent of the lisp/ package so that it can be used by any CLI command without creating import cycles.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColorMode

type ColorMode int

ColorMode controls when ANSI color codes are used.

const (
	ColorAuto   ColorMode = iota // detect based on terminal and NO_COLOR
	ColorAlways                  // always use colors
	ColorNever                   // never use colors
)

type Diagnostic

type Diagnostic struct {
	Severity Severity
	Message  string
	Spans    []Span
	Notes    []string // "= note:" lines (stack trace frames, etc.)
}

Diagnostic represents a single error, warning, or note with optional source annotations and trailing notes.

type Renderer

type Renderer struct {
	// Color controls ANSI color output. Default is ColorAuto.
	Color ColorMode

	// SourceReader reads source file contents. If nil, os.ReadFile is used.
	SourceReader func(string) ([]byte, error)
}

Renderer formats diagnostics as Rust-style annotated source snippets.

func (*Renderer) Render

func (r *Renderer) Render(w io.Writer, d Diagnostic) error

Render writes a single diagnostic to w.

func (*Renderer) RenderAll

func (r *Renderer) RenderAll(w io.Writer, diags []Diagnostic) error

RenderAll writes all diagnostics to w separated by blank lines.

type Severity

type Severity int

Severity indicates the severity level of a diagnostic.

const (
	SeverityError Severity = iota
	SeverityWarning
	SeverityNote
)

func (Severity) String

func (s Severity) String() string

type Span

type Span struct {
	File   string // path for reading source; display name if unreadable
	Line   int    // 1-based line number
	Col    int    // 1-based start column
	EndCol int    // 1-based end column (0 = auto-detect from source)
	Label  string // text shown under the underline
}

Span identifies a region of source code to highlight in the diagnostic.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL