documents

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeUTF16

func EncodeUTF16(s string) int

EncodeUTF16 is exported for tests: it returns the UTF-16 encoding length of s.

func PathToURI

func PathToURI(path string) string

PathToURI converts an absolute filesystem path to a file:// URI.

func URIToPath

func URIToPath(uri string) (string, error)

URIToPath converts a file:// URI to an absolute filesystem path, handling percent-encoding, Windows drive letters, and UNC paths. Non-file URIs are rejected so virtual documents never masquerade as files.

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.

func (*Document) Digest

func (d *Document) Digest() string

Digest returns the SHA-256 hex digest of the current content, used in edit preconditions.

func (*Document) Mapper

func (d *Document) Mapper() *Mapper

Mapper returns a position mapper for the current content.

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 NewMapper

func NewMapper(content []byte) *Mapper

NewMapper builds a Mapper over content.

func (*Mapper) ByteRangeToRange

func (m *Mapper) ByteRangeToRange(start, end int) protocol.Range

ByteRangeToRange converts a start/end byte offset pair to an LSP range.

func (*Mapper) Content

func (m *Mapper) Content() []byte

Content returns the mapped bytes.

func (*Mapper) LineByteColToOffset

func (m *Mapper) LineByteColToOffset(line1, col1 int) int

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) LineCount

func (m *Mapper) LineCount() int

LineCount returns the number of lines.

func (*Mapper) OffsetToPosition

func (m *Mapper) OffsetToPosition(offset int) protocol.Position

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

func (m *Mapper) PositionToOffset(pos protocol.Position) int

PositionToOffset converts an LSP position to a byte offset, clamping to line and content bounds.

func (*Mapper) RangeToByteRange

func (m *Mapper) RangeToByteRange(r protocol.Range) (int, int)

RangeToByteRange converts an LSP range to a start/end byte offset pair.

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 NewStore

func NewStore() *Store

NewStore returns an empty document store.

func (*Store) Change

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.

func (*Store) Overlay

func (s *Store) Overlay() map[string][]byte

Overlay returns the go/packages overlay map for all open documents: absolute path to current in-memory bytes. This is what feeds unsaved buffers to analysis without writing to disk.

Jump to

Keyboard shortcuts

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