textdoc

package
v0.0.0-...-cdf053b Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetupDefaultServices

func SetupDefaultServices(sc *service.Container)

SetupDefaultServices sets up the default services for the textdoc package. If any service is already set, it's not overwritten.

Types

type DefaultStore

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

DefaultStore is an in-memory implementation of Store that manages files and overlays.

func (*DefaultStore) AddFile

func (s *DefaultStore) AddFile(file *File)

AddFile adds or updates a file in the store.

func (*DefaultStore) AddOverlay

func (s *DefaultStore) AddOverlay(overlay *Overlay)

AddOverlay adds or updates an overlay in the store.

func (*DefaultStore) AllFiles

func (s *DefaultStore) AllFiles() []*File

AllFiles returns all stored files.

func (*DefaultStore) AllOverlays

func (s *DefaultStore) AllOverlays() []*Overlay

AllOverlays returns all stored overlays.

func (*DefaultStore) Get

func (s *DefaultStore) Get(uri lsp.DocumentURI) Handle

Get retrieves a handle by URI, checking overlays first, then files. Returns nil if neither an overlay nor a file is stored.

func (*DefaultStore) GetFile

func (s *DefaultStore) GetFile(uri lsp.DocumentURI) *File

GetFile retrieves a file by URI. Returns nil if the file is not stored.

func (*DefaultStore) GetOverlay

func (s *DefaultStore) GetOverlay(uri lsp.DocumentURI) *Overlay

GetOverlay retrieves an overlay by URI. Returns nil if the overlay is not stored.

func (*DefaultStore) KeysFiles

func (s *DefaultStore) KeysFiles() []lsp.DocumentURI

KeysFiles returns the URIs of all stored files.

func (*DefaultStore) KeysOverlays

func (s *DefaultStore) KeysOverlays() []lsp.DocumentURI

KeysOverlays returns the URIs of all stored overlays.

func (*DefaultStore) RemoveFile

func (s *DefaultStore) RemoveFile(uri lsp.DocumentURI)

RemoveFile removes a file from the store by URI.

func (*DefaultStore) RemoveOverlay

func (s *DefaultStore) RemoveOverlay(uri lsp.DocumentURI)

RemoveOverlay removes an overlay from the store by URI.

type File

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

File represents an immutable text document read from the file system. It implements Handle but does not support modifications.

func NewFile

func NewFile(uri lsp.DocumentURI, languageID string, version int32, content string) (*File, error)

NewFile creates a new text document file. The content parameter is accepted as a string and stored internally as bytes.

func (*File) Content

func (f *File) Content() []byte

Content returns a copy of the document content as a byte slice.

func (*File) LanguageID

func (f *File) LanguageID() string

LanguageID returns the language identifier.

func (*File) LineCount

func (f *File) LineCount() int

LineCount returns the number of lines in the document.

func (*File) OffsetAt

func (f *File) OffsetAt(position lsp.Position) int

OffsetAt converts a position to a zero-based offset.

func (*File) PositionAt

func (f *File) PositionAt(offset int) lsp.Position

PositionAt converts a zero-based offset to a position.

func (*File) Text

func (f *File) Text(r *lsp.Range) string

Text returns the text content or a substring if range is provided. This is a convenience method that returns a string instead of []byte.

func (*File) URI

func (f *File) URI() lsp.DocumentURI

URI returns the document URI.

func (*File) Version

func (f *File) Version() int32

Version returns the document version.

type Handle

type Handle interface {
	// URI returns the associated URI for this document.
	URI() lsp.DocumentURI
	// LanguageID returns the identifier of the language associated with this document.
	LanguageID() string
	// Version returns the version number of this document.
	Version() int32
	// Content returns the document content as a byte slice.
	Content() []byte
	// Text returns the text content or a substring if range is provided.
	Text(r *lsp.Range) string
	// PositionAt converts a zero-based offset to a position.
	PositionAt(offset int) lsp.Position
	// OffsetAt converts a position to a zero-based offset.
	OffsetAt(position lsp.Position) int
}

Handle represents a reference to a text document's content and metadata.

type Overlay

type Overlay struct {
	File
	// contains filtered or unexported fields
}

Overlay represents an open text document in the editor. It may have unsaved edits and implements both Handle and Mapper. Conceptually, an overlay models in-memory edits layered on top of any on-disk file content.

func NewOverlay

func NewOverlay(uri lsp.DocumentURI, languageID string, version int32, content string) (*Overlay, error)

NewOverlay creates a new text document overlay. The content parameter is accepted as a string and stored internally as bytes.

func (*Overlay) ApplyEdits

func (o *Overlay) ApplyEdits(edits []lsp.TextEdit) (string, error)

ApplyEdits applies a list of text edits and returns the resulting text. The edits are automatically sorted by position, and overlapping edits return an error. This method is thread-safe.

func (*Overlay) Content

func (o *Overlay) Content() []byte

Content returns a copy of the document content as a byte slice. Returning bytes enables efficient manipulation; a copy is returned to prevent external modification of internal state. This method is thread-safe.

func (*Overlay) LineCount

func (o *Overlay) LineCount() int

LineCount returns the number of lines in the document. This method is thread-safe.

func (*Overlay) OffsetAt

func (o *Overlay) OffsetAt(position lsp.Position) int

OffsetAt converts a position to a zero-based offset. This method is thread-safe.

func (*Overlay) PositionAt

func (o *Overlay) PositionAt(offset int) lsp.Position

PositionAt converts a zero-based offset to a position. This method is thread-safe.

func (*Overlay) Text

func (o *Overlay) Text(r *lsp.Range) string

Text returns the text content or a substring if range is provided. This is a convenience method that returns a string instead of []byte. This method is thread-safe.

func (*Overlay) Update

func (o *Overlay) Update(changes []lsp.TextDocumentContentChangeEvent, version int32) error

Update applies content changes to the overlay and updates its version. Both incremental and full-document change events are supported. This method is thread-safe.

func (*Overlay) Version

func (o *Overlay) Version() int32

Version returns the current document version. This method is thread-safe.

type Store

type Store interface {
	// Get retrieves a handle by URI, checking overlays first, then files.
	// Returns nil if neither an overlay nor a file is stored.
	Get(uri lsp.DocumentURI) Handle
	// GetOverlay retrieves an overlay by URI. Returns nil if the overlay is not stored.
	GetOverlay(uri lsp.DocumentURI) *Overlay
	// GetFile retrieves a file by URI. Returns nil if the file is not stored.
	GetFile(uri lsp.DocumentURI) *File
	// AddOverlay adds or updates an overlay in the store.
	AddOverlay(overlay *Overlay)
	// AddFile adds or updates a file in the store.
	AddFile(file *File)
	// RemoveOverlay removes an overlay from the store by URI.
	RemoveOverlay(uri lsp.DocumentURI)
	// RemoveFile removes a file from the store by URI.
	RemoveFile(uri lsp.DocumentURI)
	// AllOverlays returns all stored overlays.
	AllOverlays() []*Overlay
	// AllFiles returns all stored files.
	AllFiles() []*File
	// KeysOverlays returns the URIs of all stored overlays.
	KeysOverlays() []lsp.DocumentURI
	// KeysFiles returns the URIs of all stored files.
	KeysFiles() []lsp.DocumentURI
}

Store is responsible for storing cached file contents and overlays. It provides thread-safe access to document files and overlays.

func NewDefaultStore

func NewDefaultStore() Store

NewDefaultStore creates a new store for files and overlays.

Jump to

Keyboard shortcuts

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