Documentation
¶
Overview ¶
Package edit provides text editing utilities for the language server.
It implements document management with support for incremental updates, position translation between byte offsets and line/column, and text modification operations.
Package edit provides text editing abstractions for LSP refactoring operations.
Index ¶
- type Builder
- func (b *Builder) Build() *WorkspaceEdit
- func (b *Builder) BuildSorted() *WorkspaceEdit
- func (b *Builder) Clear()
- func (b *Builder) Delete(file string, span diag.Span) *Builder
- func (b *Builder) DeleteLine(file string, line int) *Builder
- func (b *Builder) FileCount() int
- func (b *Builder) HasEdits() bool
- func (b *Builder) Insert(file string, line, col int, text string) *Builder
- func (b *Builder) InsertLine(file string, beforeLine int, text string) *Builder
- func (b *Builder) Replace(file string, span diag.Span, newText string) *Builder
- func (b *Builder) ReplaceAll(file string, edits []TextEdit) *Builder
- type EditApplier
- type FileEdit
- type LSPApplier
- type MemoryApplier
- type TextEdit
- type WorkspaceEdit
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder constructs workspace edits incrementally.
func (*Builder) Build ¶
func (b *Builder) Build() *WorkspaceEdit
Build creates the final WorkspaceEdit.
func (*Builder) BuildSorted ¶
func (b *Builder) BuildSorted() *WorkspaceEdit
BuildSorted creates a sorted WorkspaceEdit ready for application.
func (*Builder) DeleteLine ¶
DeleteLine removes an entire line.
func (*Builder) InsertLine ¶
InsertLine inserts a complete line before the given line number.
type EditApplier ¶
type EditApplier interface {
// Apply applies the workspace edit.
Apply(edit *WorkspaceEdit) error
// Preview returns the result without applying.
Preview(edit *WorkspaceEdit) (map[string]string, error)
}
EditApplier applies workspace edits to actual content.
type LSPApplier ¶
type LSPApplier struct {
ApplyFunc func(*WorkspaceEdit) error
}
LSPApplier wraps a callback to send workspace/applyEdit requests.
func (*LSPApplier) Apply ¶
func (a *LSPApplier) Apply(edit *WorkspaceEdit) error
Apply sends the edit via the callback.
func (*LSPApplier) Preview ¶
func (a *LSPApplier) Preview(edit *WorkspaceEdit) (map[string]string, error)
Preview is not supported for LSP applier.
type MemoryApplier ¶
type MemoryApplier struct {
// contains filtered or unexported fields
}
MemoryApplier applies edits to in-memory content. Used for testing and preview.
func NewMemoryApplier ¶
func NewMemoryApplier(files map[string]string) *MemoryApplier
NewMemoryApplier creates an applier with the given file contents.
func (*MemoryApplier) Apply ¶
func (a *MemoryApplier) Apply(edit *WorkspaceEdit) error
Apply applies the workspace edit to the in-memory files.
func (*MemoryApplier) Content ¶
func (a *MemoryApplier) Content(file string) string
Content returns the current content of a file.
func (*MemoryApplier) Files ¶
func (a *MemoryApplier) Files() []string
Files returns all file names.
func (*MemoryApplier) Preview ¶
func (a *MemoryApplier) Preview(edit *WorkspaceEdit) (map[string]string, error)
Preview returns what files would look like after applying edits. Does not modify the actual stored content or the input edit.
func (*MemoryApplier) SetContent ¶
func (a *MemoryApplier) SetContent(file, content string)
SetContent sets the content of a file.
type TextEdit ¶
TextEdit represents a single text modification.
type WorkspaceEdit ¶
type WorkspaceEdit struct {
Files []FileEdit
}
WorkspaceEdit represents edits across multiple files.
func (*WorkspaceEdit) EditCount ¶
func (w *WorkspaceEdit) EditCount() int
EditCount returns the total number of edits.
func (*WorkspaceEdit) FileCount ¶
func (w *WorkspaceEdit) FileCount() int
FileCount returns the number of files affected.
func (*WorkspaceEdit) IsEmpty ¶
func (w *WorkspaceEdit) IsEmpty() bool
IsEmpty returns true if no edits are present.
func (*WorkspaceEdit) Merge ¶
func (w *WorkspaceEdit) Merge(other *WorkspaceEdit)
Merge combines another workspace edit into this one.
func (*WorkspaceEdit) Sort ¶
func (w *WorkspaceEdit) Sort()
Sort orders edits for safe application (bottom-up, right-to-left). This ensures earlier edits don't affect positions of later ones.
func (*WorkspaceEdit) Validate ¶
func (w *WorkspaceEdit) Validate() error
Validate checks edit consistency. Returns error if edits overlap or are invalid.