package lsppos
import "golang.org/x/tools/internal/lsp/lsppos"
Package lsppos provides utilities for working with LSP positions. Much of this functionality is duplicated from the internal/span package, but this package is simpler and more accurate with respect to newline terminated content.
See https://microsoft.github.io/language-server-protocol/specification#textDocuments for a description of LSP positions. Notably:
- Positions are specified by a 0-based line count and 0-based utf-16 character offset.
- Positions are line-ending agnostic: there is no way to specify \r|\n or \n|. Instead the former maps to the end of the current line, and the latter to the start of the next line.
Index ¶
- func UTF16len(buf []byte) int
- type Mapper
- func NewMapper(content []byte) *Mapper
- func (m *Mapper) LineColUTF16(offset int) (line, char int)
- func (m *Mapper) Position(offset int) (protocol.Position, bool)
- func (m *Mapper) Range(start, end int) (protocol.Range, error)
- type TokenMapper
Functions ¶
func UTF16len ¶
UTF16Len returns the UTF-16 length of the UTF-8 encoded content, were it to be re-encoded as UTF-16.
Types ¶
type Mapper ¶
type Mapper struct {
// contains filtered or unexported fields
}
Mapper maps utf-8 byte offsets to LSP positions for a single file.
func NewMapper ¶
NewMapper creates a new Mapper for the given content.
func (*Mapper) LineColUTF16 ¶
LineColUTF16 returns the 0-based UTF-16 line and character index for the given offset. It returns -1, -1 if offset is out of bounds for the file being mapped.
func (*Mapper) Position ¶
Position returns the protocol position corresponding to the given offset. It returns false if offset is out of bounds for the file being mapped.
func (*Mapper) Range ¶
Range returns the protocol range corresponding to the given start and end offsets.
type TokenMapper ¶
type TokenMapper struct {
// contains filtered or unexported fields
}
TokenMapper maps token.Pos to LSP positions for a single file.
func NewTokenMapper ¶
func NewTokenMapper(content []byte, file *token.File) *TokenMapper
NewMapper creates a new TokenMapper for the given content, using the provided file to compute offsets.
func (*TokenMapper) Position ¶
Position returns the protocol position corresponding to the given pos. It returns false if pos is out of bounds for the file being mapped.
func (*TokenMapper) Range ¶
Range returns the protocol range corresponding to the given start and end positions. It returns an error if start or end is out of bounds for the file being mapped.
Source Files ¶
lsppos.go token.go
- Version
- v0.1.12
- Published
- Jul 27, 2022
- Platform
- linux/amd64
- Imports
- 7 packages
- Last checked
- 6 minutes ago –
Tools for package owners.