lsppos

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2022 License: BSD-3-Clause Imports: 7 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 added in v0.1.11

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 added in v0.1.11

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 added in v0.1.11

type TokenMapper struct {
	// contains filtered or unexported fields
}

TokenMapper maps token.Pos to LSP positions for a single file.

func NewTokenMapper added in v0.1.11

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 added in v0.1.11

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 added in v0.1.11

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