Documentation
¶
Overview ¶
Package documents maintains the language server's in-memory view of editor buffers: their versions, contents, and the overlay it derives for on-disk analysis. It owns the one canonical mapping between LSP UTF-16 positions and byte offsets so every feature agrees on coordinates.
Index ¶
- func EncodeUTF16(s string) int
- func PathToURI(path string) string
- func URIToPath(uri string) (string, error)
- type Document
- type Mapper
- func (m *Mapper) ByteRangeToRange(start, end int) protocol.Range
- func (m *Mapper) Content() []byte
- func (m *Mapper) LineByteColToOffset(line1, col1 int) int
- func (m *Mapper) LineCount() int
- func (m *Mapper) OffsetToPosition(offset int) protocol.Position
- func (m *Mapper) PositionToOffset(pos protocol.Position) int
- func (m *Mapper) RangeToByteRange(r protocol.Range) (int, int)
- type Store
- func (s *Store) Change(id protocol.VersionedTextDocumentIdentifier, ...) (*Document, error)
- func (s *Store) Close(uri protocol.DocumentURI) bool
- func (s *Store) Get(uri protocol.DocumentURI) (*Document, bool)
- func (s *Store) Open(item protocol.TextDocumentItem) (*Document, error)
- func (s *Store) OpenURIs() []protocol.DocumentURI
- func (s *Store) Overlay() map[string][]byte
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodeUTF16 ¶
EncodeUTF16 is exported for tests: it returns the UTF-16 encoding length of s.
Types ¶
type Document ¶
type Document struct {
URI protocol.DocumentURI
Path string
LanguageID string
Version int32
Content []byte
}
Document is one open editor buffer. It is authoritative over the on-disk file while open.
type Mapper ¶
type Mapper struct {
// contains filtered or unexported fields
}
Mapper converts between LSP positions (zero-based line, UTF-16 code-unit character offset) and byte offsets for one document content. It is the single canonical coordinate mapper used across the server, so every feature agrees. A Mapper is immutable and safe for concurrent reads.
func (*Mapper) ByteRangeToRange ¶
ByteRangeToRange converts a start/end byte offset pair to an LSP range.
func (*Mapper) LineByteColToOffset ¶
LineByteColToOffset converts a 1-based line and 1-based byte column (the form go/token reports) to a byte offset, clamping to line and content bounds.
func (*Mapper) OffsetToPosition ¶
OffsetToPosition converts a byte offset to an LSP position, clamping to the document bounds so an out-of-range offset never panics.
func (*Mapper) PositionToOffset ¶
PositionToOffset converts an LSP position to a byte offset, clamping to line and content bounds.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store holds all open documents. It is safe for concurrent use. It rejects out-of-order versions so a late change never regresses newer content.
func (*Store) Change ¶
func (s *Store) Change(id protocol.VersionedTextDocumentIdentifier, changes []protocol.TextDocumentContentChangeEvent) (*Document, error)
Change applies content changes, returning the updated document. Full and incremental changes are both supported. An out-of-order version is rejected.
func (*Store) Close ¶
func (s *Store) Close(uri protocol.DocumentURI) bool
Close removes a document. It reports whether the document was open.
func (*Store) Get ¶
func (s *Store) Get(uri protocol.DocumentURI) (*Document, bool)
Get returns a snapshot copy of a document, or (nil, false) if not open.
func (*Store) Open ¶
func (s *Store) Open(item protocol.TextDocumentItem) (*Document, error)
Open records a newly opened document.
func (*Store) OpenURIs ¶
func (s *Store) OpenURIs() []protocol.DocumentURI
OpenURIs returns the URIs of all open documents.