edit

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 4 Imported by: 0

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

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 NewBuilder

func NewBuilder() *Builder

NewBuilder creates a new edit builder.

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

func (b *Builder) Clear()

Clear resets the builder for reuse.

func (*Builder) Delete

func (b *Builder) Delete(file string, span diag.Span) *Builder

Delete removes text at the given span.

func (*Builder) DeleteLine

func (b *Builder) DeleteLine(file string, line int) *Builder

DeleteLine removes an entire line.

func (*Builder) FileCount

func (b *Builder) FileCount() int

FileCount returns the number of files with edits.

func (*Builder) HasEdits

func (b *Builder) HasEdits() bool

HasEdits returns true if any edits have been added.

func (*Builder) Insert

func (b *Builder) Insert(file string, line, col int, text string) *Builder

Insert inserts text at the given position.

func (*Builder) InsertLine

func (b *Builder) InsertLine(file string, beforeLine int, text string) *Builder

InsertLine inserts a complete line before the given line number.

func (*Builder) Replace

func (b *Builder) Replace(file string, span diag.Span, newText string) *Builder

Replace replaces text at the given span.

func (*Builder) ReplaceAll

func (b *Builder) ReplaceAll(file string, edits []TextEdit) *Builder

ReplaceAll replaces all occurrences in a file.

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 FileEdit

type FileEdit struct {
	File  string
	Edits []TextEdit
}

FileEdit represents all edits to a single file.

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

type TextEdit struct {
	Span    diag.Span
	NewText string
}

TextEdit represents a single text modification.

func (TextEdit) IsDelete

func (e TextEdit) IsDelete() bool

IsDelete returns true if this edit is a pure deletion (empty new text).

func (TextEdit) IsInsert

func (e TextEdit) IsInsert() bool

IsInsert returns true if this edit is a pure insertion (empty span).

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.

Jump to

Keyboard shortcuts

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