Documentation ¶
Index ¶
- func FromGoASTNode(fileset *token.FileSet, node ast.Node) option.Option[*SrcLocation]
- func FromGoASTNodeWithTypeAndText(fileset *token.FileSet, node ast.Node, typ LocationType, text string) option.Option[*SrcLocation]
- func FromGoTokenPos(fileset *token.FileSet, start, end token.Pos) option.Option[*SrcLocation]
- func FromGoTokenPositions(start token.Position, end token.Position) option.Option[*SrcLocation]
- type ErrParams
- type File
- type LocationType
- type Pos
- type SrcLocation
- type SrcLocations
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromGoASTNode ¶
FromGoASTNode returns a SrcLocation from a Go AST node storing the start and end locations of that node.
func FromGoASTNodeWithTypeAndText ¶ added in v1.9.3
func FromGoASTNodeWithTypeAndText(fileset *token.FileSet, node ast.Node, typ LocationType, text string) option.Option[*SrcLocation]
func FromGoTokenPos ¶ added in v1.14.5
func FromGoTokenPositions ¶
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.
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 (*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 separate 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 NewSrcLocations ¶ added in v1.29.5
func NewSrcLocations(opts ...option.Option[*SrcLocation]) SrcLocations
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)