Documentation
¶
Overview ¶
Package locator addresses byte regions of files and applies splice edits to them. A Locator names a file and a byte range; applying an Edit reads the live file, replaces the range with new text, and writes the result back atomically. RawHash gates byte-offset validity by hashing the live raw bytes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyFileEdits ¶
ApplyFileEdits groups edits by Path and applies each file's edits in a single atomic write. Within a file, edits are applied reverse-sorted by StartByte (descending) so that splicing an earlier-offset edit never invalidates the byte ranges of later-offset edits not yet applied.
Types ¶
type Edit ¶
type Edit struct {
// NewText replaces the locator's [StartByte:EndByte] region.
NewText string
}
Edit is the replacement text for a single locator's byte range.
type FileEdit ¶
type FileEdit struct {
// Path is the absolute or relative path of the file to edit.
Path string
// StartByte is the inclusive start of the byte range to replace.
StartByte int
// EndByte is the exclusive end of the byte range to replace.
EndByte int
// NewText is the text spliced in for [StartByte:EndByte].
NewText string
}
FileEdit is one byte-range replacement within a named file. It is the unit the coordinator/LSP path produces; multiple FileEdits per file are applied reverse-sorted by StartByte so earlier offsets stay valid.
type Locator ¶
type Locator interface {
// Path returns the file the locator addresses.
Path() string
// Apply reads the file, splices e.NewText into the locator's byte range,
// and writes the result back atomically.
Apply(e Edit) error
// RawHash returns the FNV-1a-64 hex digest of the file's live raw bytes,
// which gates byte-offset validity.
RawHash() string
}
Locator addresses an editable byte region of a single file.
type TextLocator ¶
type TextLocator struct {
// Path_ is the file the locator addresses.
Path_ string
// StartByte is the inclusive start of the addressed byte range.
StartByte int
// EndByte is the exclusive end of the addressed byte range.
EndByte int
}
TextLocator is a byte-range Locator over a text file.
func (*TextLocator) Apply ¶
func (l *TextLocator) Apply(e Edit) error
Apply reads the file, replaces [StartByte:EndByte] with e.NewText, and writes the result back via atomicwrite. It returns an error if the byte range falls outside the current file contents.
func (*TextLocator) Path ¶
func (l *TextLocator) Path() string
Path returns the file the locator addresses.
func (*TextLocator) RawHash ¶
func (l *TextLocator) RawHash() string
RawHash returns the FNV-1a-64 hex digest of the file's live raw bytes. A read error yields the empty string so callers treat the offsets as invalid.