Documentation
¶
Overview ¶
Package diag exposes error types used throughout River and a method to pretty-print them to the screen.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fprint ¶
func Fprint(w io.Writer, files map[string][]byte, diags Diagnostics) error
Fprint creates a Printer with default settings and prints diagnostics to the provided writer. files is used to look up file contents by name for printing diagnostics context. files may be set to nil to avoid printing context.
Types ¶
type Diagnostic ¶
type Diagnostic struct {
// Severity holds the severity level of this Diagnostic.
Severity Severity
// StartPos refers to a position in a file where this Diagnostic starts.
StartPos token.Position
// EndPos refers to an optional position in a file where this Diagnostic
// ends. If EndPos is the zero value, the Diagnostic should be treated as
// only covering a single character (i.e., StartPos == EndPos).
//
// When defined, EndPos must have the same Filename value as the StartPos.
EndPos token.Position
Message string
Value string
}
Diagnostic is an individual diagnostic message. Diagnostic messages can have different levels of severities.
type Diagnostics ¶
type Diagnostics []Diagnostic
Diagnostics is a collection of diagnostic messages.
func (*Diagnostics) Add ¶
func (ds *Diagnostics) Add(d Diagnostic)
Add adds an individual Diagnostic to the diagnostics list.
func (Diagnostics) ErrorOrNil ¶
func (ds Diagnostics) ErrorOrNil() error
ErrorOrNil returns an error interface if the list diagnostics is non-empty, nil otherwise.
type Printer ¶
type Printer struct {
// contains filtered or unexported fields
}
A Printer pretty-prints Diagnostics.
func NewPrinter ¶
func NewPrinter(cfg PrinterConfig) *Printer
NewPrinter creates a new diagnostics Printer with the provided config.
type PrinterConfig ¶
type PrinterConfig struct {
// When Color is true, the printer will output with color and special
// formatting characters (such as underlines).
//
// This should be disabled when not printing to a terminal.
Color bool
// ContextLinesBefore and ContextLinesAfter controls how many context lines
// before and after the range of the diagnostic are printed.
ContextLinesBefore, ContextLinesAfter int
}
PrinterConfig controls different settings for the Printer.