writeback

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const MaxSpliceFileSize = 100 * 1024 * 1024 // 100MB

MaxSpliceFileSize is the maximum source file size Splice will read. Prevents OOM on accidentally large files (e.g., generated code, vendored blobs).

Variables

View Source
var ErrSourceChanged = fmt.Errorf("source file changed during splice")

ErrSourceChanged is returned when the source file was modified between when Splice read it and when Splice was about to commit. Indicates the byte ranges in SourceOrigin are stale and the splice would write corrupt content. Callers should re-ingest and retry.

Functions

func FormatBuffer added in v0.2.0

func FormatBuffer(content []byte, filePath string) []byte

FormatBuffer formats source code in-memory based on file extension. Go files use gofumpt; HCL/Terraform files use hclwrite.Format. Python files use ruff (preferred) or black. TypeScript/JavaScript files use prettier. Returns the formatted buffer, or the original buffer unchanged if the file type has no formatter or formatting fails.

func LanguageForPath added in v0.2.0

func LanguageForPath(filePath string) *sitter.Language

LanguageForPath maps file extensions to tree-sitter languages. Delegates to the lang registry — supports all 18 languages automatically.

func Splice

func Splice(origin graph.SourceOrigin, newContent []byte) error

Splice replaces the byte range identified by origin with newContent in the source file. The write is atomic: content is written to a temp file first, then renamed.

To defend against TOCTOU between read and rename, Splice captures the file's size and modification time before reading and re-checks them immediately before the rename. If they don't match, Splice returns ErrSourceChanged without touching the source.

Side effect: each successful Splice replaces the destination inode (the rename swaps in a fresh file). External consumers — file watchers, IDE language servers, NFS/SMB clients with cached fds — that key on inode rather than path will see the file as "new" and may need to re-arm or re-resolve. Pre-splice readers continue seeing the original content until they close the fd (POSIX keeps the unlinked inode alive). See TestSplice_InodeChangesAfterRename and TestSplice_OpenReaderSeesOldContentAfterSplice for the pinned contract.

func Validate added in v0.2.0

func Validate(content []byte, filePath string) error

Validate parses content with tree-sitter and returns an error if the AST contains syntax errors. Files with no known tree-sitter language pass through without validation (returns nil).

Types

type ValidationError added in v0.2.0

type ValidationError struct {
	FilePath string
	Line     uint32 // 0-indexed
	Column   uint32 // 0-indexed
	Message  string
}

ValidationError contains structured information about a syntax error.

func ASTErrors added in v0.2.0

func ASTErrors(content []byte, filePath string) []ValidationError

ASTErrors returns all ERROR node locations in the content for diagnostic reporting. Returns nil if no errors or unknown language.

func (*ValidationError) Error added in v0.2.0

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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