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 ¶
- Variables
- type Document
- func (d *Document) ApplyChange(change lsp.TextDocumentContentChangeEvent, version int) error
- func (d *Document) LanguageID() string
- func (d *Document) Line(n int) (string, bool)
- func (d *Document) Lines() []string
- func (d *Document) OffsetAt(pos lsp.Position) (int, error)
- func (d *Document) PositionAt(offset int) (lsp.Position, error)
- func (d *Document) Text() string
- func (d *Document) URI() lsp.DocumentURI
- func (d *Document) Version() int
- type Store
- func (s *Store) Change(params *lsp.DidChangeTextDocumentParams) (*Document, error)
- func (s *Store) Close(params *lsp.DidCloseTextDocumentParams)
- func (s *Store) Get(uri lsp.DocumentURI) (*Document, bool)
- func (s *Store) Open(params *lsp.DidOpenTextDocumentParams) (*Document, error)
- func (s *Store) Text(uri lsp.DocumentURI) (string, bool)
- func (s *Store) URIs() []lsp.DocumentURI
- func (s *Store) Version(uri lsp.DocumentURI) (int, bool)
Constants ¶
This section is empty.
Variables ¶
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 ¶
LanguageID returns the document's language identifier.
func (*Document) Lines ¶
Lines returns the document split on "\n". Line endings are preserved except for the delimiter removed by strings.Split.
func (*Document) PositionAt ¶
PositionAt converts a byte offset in Text() to an LSP UTF-16 position.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store tracks open text documents and applies LSP document sync messages.
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.