lsppos

package
v0.0.35 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2022 License: BSD-3-Clause, BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func UTF16len

func UTF16len(buf []byte) int

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

func NewMapper(content []byte) *Mapper

NewMapper creates a new Mapper for the given content.

func (*Mapper) LineColUTF16

func (m *Mapper) LineColUTF16(offset int) (line, char int)

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

func (m *Mapper) Position(offset int) (protocol.Position, bool)

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

func (m *Mapper) Range(start, end int) (protocol.Range, error)

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

NewTokenMapper creates a new TokenMapper for the given content, using the provided file to compute offsets.

func (*TokenMapper) NodeRange

func (m *TokenMapper) NodeRange(n ast.Node) (protocol.Range, error)

NodeRange returns the protocol range corresponding to the span of the given node.

func (*TokenMapper) Position

func (m *TokenMapper) Position(pos token.Pos) (protocol.Position, bool)

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

func (m *TokenMapper) Range(start, end token.Pos) (protocol.Range, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL