mapper

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mapper

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

func NewMapper

func NewMapper(content []byte) *Mapper

NewMapper returns a Mapper for the given document content.

func (*Mapper) ApplyEdits

func (m *Mapper) ApplyEdits(edits []protocol.TextEdit) ([]byte, error)

ApplyEdits returns the mapped content with the edits applied. Edits must not overlap; they may arrive in any order. Positions are resolved from LSP (UTF-16) coordinates via the mapper, and later edits apply first so earlier offsets stay valid.

func (*Mapper) GetLSPEndPosition

func (m *Mapper) GetLSPEndPosition() protocol.Position

GetLSPEndPosition returns the position immediately after the last character of the document: the last line (0-based) at the UTF-16 length of its content. A document ending with a newline has an empty last line.

func (*Mapper) LSPPosToParserPosition

func (m *Mapper) LSPPosToParserPosition(pos protocol.Position) (syntax.Position, error)

LSPPosToParserPosition converts an LSP position (0-based line, UTF-16 code-unit column) to a parser position (1-based line, rune-based column).

Client positions are hints, not facts: they race with edits, so a column past the line end clamps to the line end instead of failing. Only a line past the document is an error — there is nothing to clamp to.

func (*Mapper) OffsetToLSPPosition

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

OffsetToLSPPosition converts a byte offset in the mapped content to an LSP position (0-based line, UTF-16 code-unit column).

Jump to

Keyboard shortcuts

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