Documentation
¶
Index ¶
- func SetupDefaultServices(sc *service.Container)
- type DefaultStore
- func (s *DefaultStore) AddFile(file *File)
- func (s *DefaultStore) AddOverlay(overlay *Overlay)
- func (s *DefaultStore) AllFiles() []*File
- func (s *DefaultStore) AllOverlays() []*Overlay
- func (s *DefaultStore) Get(uri lsp.DocumentURI) Handle
- func (s *DefaultStore) GetFile(uri lsp.DocumentURI) *File
- func (s *DefaultStore) GetOverlay(uri lsp.DocumentURI) *Overlay
- func (s *DefaultStore) KeysFiles() []lsp.DocumentURI
- func (s *DefaultStore) KeysOverlays() []lsp.DocumentURI
- func (s *DefaultStore) RemoveFile(uri lsp.DocumentURI)
- func (s *DefaultStore) RemoveOverlay(uri lsp.DocumentURI)
- type File
- func (f *File) Content() []byte
- func (f *File) LanguageID() string
- func (f *File) LineCount() int
- func (f *File) OffsetAt(position lsp.Position) int
- func (f *File) PositionAt(offset int) lsp.Position
- func (f *File) Text(r *lsp.Range) string
- func (f *File) URI() lsp.DocumentURI
- func (f *File) Version() int32
- type Handle
- type Overlay
- func (o *Overlay) ApplyEdits(edits []lsp.TextEdit) (string, error)
- func (o *Overlay) Content() []byte
- func (o *Overlay) LineCount() int
- func (o *Overlay) OffsetAt(position lsp.Position) int
- func (o *Overlay) PositionAt(offset int) lsp.Position
- func (o *Overlay) Text(r *lsp.Range) string
- func (o *Overlay) Update(changes []lsp.TextDocumentContentChangeEvent, version int32) error
- func (o *Overlay) Version() int32
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetupDefaultServices ¶
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 ¶
NewFile creates a new text document file. The content parameter is accepted as a string and stored internally as bytes.
func (*File) LanguageID ¶
LanguageID returns the language identifier.
func (*File) PositionAt ¶
PositionAt converts a zero-based offset to a position.
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 ¶
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 ¶
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 ¶
LineCount returns the number of lines in the document. This method is thread-safe.
func (*Overlay) OffsetAt ¶
OffsetAt converts a position to a zero-based offset. This method is thread-safe.
func (*Overlay) PositionAt ¶
PositionAt converts a zero-based offset to a position. This method is thread-safe.
func (*Overlay) Text ¶
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.
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.