Documentation ¶
Overview ¶
Package span contains support for representing with positions and ranges in text files.
Index ¶
- Variables
- func Compare(a, b Span) int
- func ComparePoint(a, b Point) int
- func CompareURI(a, b URI) int
- func ToUTF16Column(p Point, content []byte) (int, error)
- type Converter
- type Point
- type PosConverter
- type Range
- type Span
- func (s Span) End() Point
- func (s Span) Format(f fmt.State, c rune)
- func (s Span) HasOffset() bool
- func (s Span) HasPosition() bool
- func (s Span) IsPoint() bool
- func (s Span) IsValid() bool
- func (s *Span) MarshalJSON() ([]byte, error)
- func (s Span) Range(converter *PosConverter) (Range, error)
- func (s Span) Start() Point
- func (s Span) URI() URI
- func (s *Span) UnmarshalJSON(b []byte) error
- func (s Span) WithAll(c Converter) (Span, error)
- func (s Span) WithOffset(c Converter) (Span, error)
- func (s Span) WithPosition(c Converter) (Span, error)
- type URI
Constants ¶
This section is empty.
Variables ¶
var Invalid = Span{/* contains filtered or unexported fields */}
Invalid is a span that reports false from IsValid
Functions ¶
func ComparePoint ¶
func CompareURI ¶
Types ¶
type Converter ¶
type Converter interface { //ToPosition converts from an offset to a line:column pair. ToPosition(offset int) (int, int, error) //ToOffset converts from a line:column pair to an offset. ToOffset(line, col int) (int, error) }
Converter is the interface to an object that can convert between line:column and offset forms for a single file.
type Point ¶
type Point struct {
// contains filtered or unexported fields
}
Point represents a single point within a file. In general this should only be used as part of a Span, as on its own it does not carry enough information.
func FromUTF16Column ¶
FromUTF16Column advances the point by the utf16 character offset given the supplied line contents. This is used to convert from the utf16 counts used by some editors to the native (always in bytes) column representation.
func (Point) HasPosition ¶
func (*Point) MarshalJSON ¶
func (*Point) UnmarshalJSON ¶
type PosConverter ¶
type PosConverter struct {
// contains filtered or unexported fields
}
PosConverter is a Converter backed by a loc file set and file. It uses the file set methods to work out the conversions, which makes it fast and does not require the file contents.
func NewContentConverter ¶
func NewContentConverter(filename string, content []byte) *PosConverter
NewContentConverter returns an implementation of Converter for the given file content.
func NewPosConverter ¶
func NewPosConverter(fset *loc.FileSet, f *loc.File) *PosConverter
NewPosConverter returns an implementation of Converter backed by a loc.File.
func (*PosConverter) ToPosition ¶
func (l *PosConverter) ToPosition(offset int) (int, int, error)
type Range ¶
Range represents a source code range in loc.Pos form. It also carries the FileSet that produced the positions, so that it is self contained.
func NewRange ¶
NewRange creates a new Range from a FileSet and two positions. To represent a point pass a 0 as the end pos.
type Span ¶
type Span struct {
// contains filtered or unexported fields
}
Span represents a source code range in standardized form.
func Parse ¶
Parse returns the location represented by the input. Only file paths are accepted, not URIs. The returned span will be normalized, and thus if printed may produce a different string.
func (Span) Format ¶
Format implements fmt.Formatter to print the Location in a standard form. The format produced is one that can be read back in using Parse.
func (Span) HasPosition ¶
func (*Span) MarshalJSON ¶
func (Span) Range ¶
func (s Span) Range(converter *PosConverter) (Range, error)
Range converts a Span to a Range that represents the Span for the supplied File.
func (*Span) UnmarshalJSON ¶
type URI ¶
type URI string
URI represents the full URI for a file.
func URIFromPath ¶
URIFromPath returns a span URI for the supplied file path. It will always have the file scheme.
func URIFromURI ¶
func URINormalizeAuthority ¶
vscode URIs with 'untitled' scheme is using %2B instead of + inside the authority string, which does not conform to RFC3986. Remove as soon as this issue is fixed: https://github.com/microsoft/vscode/issues/133955