Documentation
¶
Overview ¶
Package edit provides the in-memory round-trip edit primitives Båge applies before any file write: drift classification (two hashes), a pure byte-range splice over a single file's bytes, a byte-offset → row/col point helper, and a reparse that prefers incremental parsing for the single-region path.
Nothing here performs file I/O. Reading the live file, deciding to apply, and writing the result are the session/locator layers' responsibility (SPEC §5, §6). This package is the pure core those layers compose.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PointAt ¶
PointAt returns the zero-based row/column for byteOffset within src: Row is the count of '\n' bytes before the offset, and Col is the number of bytes since the last '\n' (or since the start of src on the first line). Offsets at or past len(src) clamp to EOF. A negative offset clamps to the origin.
func Reparse ¶
func Reparse(ctx context.Context, p parser.ParserPort, lang parser.Lang, old []byte, oldTree *parser.Tree, edits []locator.FileEdit) (newBytes []byte, tree *parser.Tree, err error)
Reparse splices edits into old and reparses the result. For a single edit and a non-nil oldTree it builds a parser.InputEdit from PointAt over the old and new bytes and calls ParseIncremental, reusing oldTree. Otherwise (oldTree nil, or a multi-edit batch where a single InputEdit cannot describe the change) it calls Parse for a full reparse. It returns the spliced bytes and the new tree; the caller owns the returned tree and must Close it.
func SpliceEdits ¶
SpliceEdits applies every edit to one file's bytes purely, returning a fresh slice. Edits are reverse-sorted by StartByte (descending) so splicing an earlier-offset edit never invalidates a later-offset edit's range. Overlapping ranges are rejected (mirroring locator.ApplyFileEdits) because reverse-sorted application is correct only for disjoint ranges. Out-of-range or inverted offsets are rejected. SpliceEdits performs no I/O.
Types ¶
type DriftStatus ¶
type DriftStatus int
DriftStatus classifies how a live file's bytes have drifted from the bytes a byte range was grounded against (SPEC §5).
const ( // DriftValid means the live raw bytes hash-match the expected raw hash, so // the byte range is trustworthy and the edit may apply directly. DriftValid DriftStatus = iota // DriftWhitespaceOnly means the raw hash differs but the normalized hash // matches: the change is whitespace-only and the range must be re-grounded // (re-resolved) before applying, never slid blindly. DriftWhitespaceOnly // DriftReal means the normalized hash differs: the content itself changed, // so the range must be re-grounded from Hylla or the edit rejected. DriftReal )
func CheckDrift ¶
func CheckDrift(h hashing.Hasher, live []byte, expectedRaw, expectedNorm string) DriftStatus
CheckDrift classifies live against the hashes the caller's byte range was grounded on. A raw match yields DriftValid; a raw mismatch with a normalized match yields DriftWhitespaceOnly; a normalized mismatch yields DriftReal. The same Hasher must have produced expectedRaw and expectedNorm.
func (DriftStatus) String ¶
func (s DriftStatus) String() string
String returns a stable lowercase label for the drift status.