document

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package document manages open LSP text documents.

Store tracks open documents and applies full or incremental textDocument/didChange updates. Positions are interpreted using LSP's UTF-16 character offsets, not Go byte offsets or rune indexes.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDocumentNotFound means a change or lookup referenced an unopened document.
	ErrDocumentNotFound = errors.New("document not found")

	// ErrInvalidPosition means an LSP position does not point into the document.
	ErrInvalidPosition = errors.New("invalid document position")

	// ErrInvalidRange means an LSP range is outside the document or has start after end.
	ErrInvalidRange = errors.New("invalid document range")

	// ErrVersionRegression means an update tried to move a document version backwards.
	ErrVersionRegression = errors.New("document version regression")
)

Functions

This section is empty.

Types

type Document

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

Document is an open text document.

func (*Document) ApplyChange

func (d *Document) ApplyChange(change lsp.TextDocumentContentChangeEvent, version int) error

ApplyChange applies a single LSP content change to the document.

func (*Document) LanguageID

func (d *Document) LanguageID() string

LanguageID returns the document's language identifier.

func (*Document) Line

func (d *Document) Line(n int) (string, bool)

Line returns a single zero-based line.

func (*Document) Lines

func (d *Document) Lines() []string

Lines returns the document split on "\n". Line endings are preserved except for the delimiter removed by strings.Split.

func (*Document) OffsetAt

func (d *Document) OffsetAt(pos lsp.Position) (int, error)

OffsetAt converts an LSP UTF-16 position to a byte offset in Text().

func (*Document) PositionAt

func (d *Document) PositionAt(offset int) (lsp.Position, error)

PositionAt converts a byte offset in Text() to an LSP UTF-16 position.

func (*Document) Text

func (d *Document) Text() string

Text returns the full document text.

func (*Document) URI

func (d *Document) URI() lsp.DocumentURI

URI returns the document URI.

func (*Document) Version

func (d *Document) Version() int

Version returns the latest document version seen by the store.

type Store

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

Store tracks open text documents and applies LSP document sync messages.

func NewStore

func NewStore() *Store

NewStore creates an empty document store.

func (*Store) Change

func (s *Store) Change(params *lsp.DidChangeTextDocumentParams) (*Document, error)

Change applies all content changes from a didChange notification.

func (*Store) Close

func (s *Store) Close(params *lsp.DidCloseTextDocumentParams)

Close removes a document from the store.

func (*Store) Get

func (s *Store) Get(uri lsp.DocumentURI) (*Document, bool)

Get returns a snapshot of an open document.

func (*Store) Open

func (s *Store) Open(params *lsp.DidOpenTextDocumentParams) (*Document, error)

Open records a newly opened document.

func (*Store) Text

func (s *Store) Text(uri lsp.DocumentURI) (string, bool)

Text returns the full text for an open document.

func (*Store) URIs

func (s *Store) URIs() []lsp.DocumentURI

URIs returns all open document URIs in lexical order.

func (*Store) Version

func (s *Store) Version(uri lsp.DocumentURI) (int, bool)

Version returns the current version for an open document.

Jump to

Keyboard shortcuts

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