Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrParams ¶
type ErrParams struct { Code int `json:"code"` Title string `json:"title"` Summary string `json:"summary"` Detail string `json:"detail,omitempty"` Cause error `json:"-"` Locations SrcLocations `json:"locations,omitempty"` }
ErrParams are used to create *errinsrc.ErrInSrc objects.
It exists within an `internal` package so that it can only be used by other packages within the `errinsrc` folder. This is enforce through the Go compiler that all errors are created inside the `srcerrors` subpackage.
type LocationType ¶
type LocationType uint8
const ( LocError LocationType = iota // Renders in red LocWarning // Renders in yellow LocHelp // Renders in blue )
type SrcLocation ¶
type SrcLocation struct { Type LocationType `json:"type"` // The type of this location Text string `json:"text,omitempty"` // Optional text to render at this location File *File `json:"file,omitempty"` // The file containing the error Start Pos `json:"start"` // The position this location starts at End Pos `json:"end"` // The position this location ends at }
func FromCueTokenPos ¶
func FromCueTokenPos(cueLoc interface { Filename() string Line() int Column() int }, pathPrefix string) *SrcLocation
FromCueTokenPos converts a cueerror.Pos to a SrcLocation
We use an interface for `cue/token.Pos` so we can test it
func FromGoASTNode ¶
func FromGoASTNode(fileset *token.FileSet, node ast.Node) *SrcLocation
FromGoASTNode returns a SrcLocation from a Go AST node storing the start and end locations of that node.
func FromGoTokenPositions ¶
func FromGoTokenPositions(start token.Position, end token.Position) *SrcLocation
FromGoTokenPositions returns a SrcLocation from two Go token positions. They can be the same position or different positions. However, they must be locations within the same file.
This function will panic if the locations are in different files.
func (*SrcLocation) Less ¶
func (s *SrcLocation) Less(other *SrcLocation) bool
type SrcLocations ¶
type SrcLocations []*SrcLocation
SrcLocations represents a list of locations within the source code. It can be sorted and split up into seperate lists using GroupByFile
func LocationsFromCueError ¶
func LocationsFromCueError(err cueerrors.Error, pathPrefix string) SrcLocations
LocationsFromCueError returns a list of SrcLocations based on what was given in the cueerror.Error.
func (SrcLocations) GroupByFile ¶
func (s SrcLocations) GroupByFile() []SrcLocations
GroupByFile groups all locations by file and returns a new SrcLocations for each file.
If a file has overlapping locations or two locations on the same line then more than one SrcLocations will be returned for that file. This is due to a limitation in the srcrender, and may be relaxed in the future.
func (SrcLocations) Len ¶
func (s SrcLocations) Len() int
func (SrcLocations) Less ¶
func (s SrcLocations) Less(i, j int) bool
func (SrcLocations) Swap ¶
func (s SrcLocations) Swap(i, j int)