diag

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: Apache-2.0 Imports: 7 Imported by: 1

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.

func (Diagnostic) As

func (d Diagnostic) As(v interface{}) bool

As allows d to be interpreted as a list of Diagnostics.

func (Diagnostic) Error

func (d Diagnostic) Error() string

Error implements error.

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

func (ds Diagnostics) Error() string

Error implements error.

func (Diagnostics) ErrorOrNil

func (ds Diagnostics) ErrorOrNil() error

ErrorOrNil returns an error interface if the list diagnostics is non-empty, nil otherwise.

func (Diagnostics) HasErrors

func (ds Diagnostics) HasErrors() bool

HasErrors reports whether the list of Diagnostics contain any error-level diagnostic.

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.

func (*Printer) Fprint

func (p *Printer) Fprint(w io.Writer, files map[string][]byte, diags Diagnostics) error

Fprint pretty-prints errors to a writer. files is used to look up file contents by name when printing context. files may be nil to avoid printing context.

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.

type Severity

type Severity int

Severity denotes the severity level of a diagnostic. The zero value of severity is invalid.

const (
	SeverityLevelWarn Severity = iota + 1
	SeverityLevelError
)

Supported severity levels.

Jump to

Keyboard shortcuts

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