Documentation ¶
Overview ¶
Package span contains support for representing with positions and ranges in text files.
Index ¶
- Variables
- func SameExistingFile(a, b URI) bool
- func SortSpans(spans []Span)
- type Point
- 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 (span *Span) SetRange(file *token.File, start, end token.Pos)
- func (s Span) Start() Point
- func (s Span) URI() URI
- func (s *Span) UnmarshalJSON(b []byte) 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 SameExistingFile ¶ added in v0.11.0
SameExistingFile reports whether two spans denote the same existing file by querying the file system.
Types ¶
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 (Point) HasPosition ¶
func (*Point) MarshalJSON ¶
func (*Point) UnmarshalJSON ¶
type Span ¶
type Span struct {
// contains filtered or unexported fields
}
A Span represents a range of text within a source file. The start and end points of a valid span may be hold either its byte offset, or its (line, column) pair, or both. Columns are measured in bytes.
Spans are appropriate in user interfaces (e.g. command-line tools) and tests where a position is notated without access to the content of the file.
Use protocol.Mapper to convert between Span and other representations, such as go/token (also UTF-8) or the LSP protocol (UTF-16). The latter requires access to file contents.
See overview comments at ../lsp/protocol/mapper.go.
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 ParseInDir ¶
ParseInDir is like Parse, but interprets paths relative to wd.
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) SetRange ¶
SetRange implements packagestest.rangeSetter, allowing gopls' test suites to use Spans instead of Range in parameters.
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.
For empty paths, URIFromPath returns the empty URI "". For non-empty paths, URIFromPath returns a uri with the file:// scheme.
func URIFromURI ¶
TODO(adonovan): document this function, and any invariants of span.URI that it is supposed to establish.