package lazycode ¶
import "golazy.dev/lazycode"
Constants ¶
const AbsentHash ¶
AbsentHash marks a planned creation whose baseline path did not exist.
const AbsentHash = "absent"
Functions ¶
func Hash ¶
Hash returns the SHA-256 baseline identifier for data.
func Hash(data []byte) string
Types ¶
type Diagnostic ¶
Diagnostic records information discovered while planning source changes.
type Diagnostic struct {
Path string
Line int
Column int
Message string
Severity Severity
}
type EditKind ¶
EditKind describes how a planned edit changes one file.
type EditKind string
type FileEdit ¶
FileEdit is one baseline-bound file change produced by a plan. Before and After are copies of the baseline and planned contents respectively.
type FileEdit struct {
Path string
Kind EditKind
BaselineHash string
Before []byte
After []byte
}
func (e FileEdit) VerifyBaseline ¶
VerifyBaseline reports whether data still matches the input used to plan e.
func (e FileEdit) VerifyBaseline(data []byte, exists bool) bool
type Operation ¶
Operation applies one in-memory change to a Workspace.
type Operation interface {
Apply(*Workspace) error
}
type OperationFunc ¶
OperationFunc adapts a function to the Operation interface.
type OperationFunc func(*Workspace) error
func (f OperationFunc) Apply ¶
Apply calls f with workspace.
func (f OperationFunc) Apply(workspace *Workspace) error
type Result ¶
Result contains the file edits and diagnostics produced by a plan.
type Result struct {
Files []FileEdit
Diagnostics []Diagnostic
}
func (r Result) Changed ¶
Changed reports whether the plan contains at least one file edit.
func (r Result) Changed() bool
type Severity ¶
Severity classifies a planning diagnostic.
type Severity string
type Workspace ¶
Workspace holds an immutable baseline and an in-memory working copy. Its mutation methods never touch the filesystem and are intended for Operations.
type Workspace struct {
// contains filtered or unexported fields
}
func FromFiles ¶
FromFiles returns a Workspace whose baseline is populated from files. Input paths must be relative and file contents are copied.
func FromFiles(root string, files map[string][]byte) (*Workspace, error)
func Load ¶
Load reads relative paths into a Workspace. It never writes to root.
func Load(root string, paths ...string) (*Workspace, error)
func New ¶
New returns an empty Workspace rooted at root. Root is metadata for callers; New does not read or create the directory.
func New(root string) *Workspace
func (w *Workspace) Add ¶
Add adds an existing file to the immutable baseline.
func (w *Workspace) Add(name string, data []byte) error
func (w *Workspace) Diagnose ¶
Diagnose appends a diagnostic to the current in-memory plan. An empty severity defaults to SeverityInfo.
func (w *Workspace) Diagnose(diagnostic Diagnostic) error
func (w *Workspace) Exists ¶
Exists reports whether name exists in the current in-memory working copy.
func (w *Workspace) Exists(name string) bool
func (w *Workspace) Paths ¶
Paths returns the existing paths in the current working copy in lexical order.
func (w *Workspace) Paths() []string
func (w *Workspace) Plan ¶
Plan applies operations to a fresh clone, leaving w reusable and unchanged.
func (w *Workspace) Plan(operations ...Operation) (Result, error)
func (w *Workspace) Read ¶
Read returns a copy of the current in-memory contents of name.
func (w *Workspace) Read(name string) ([]byte, error)
func (w *Workspace) Remove ¶
Remove marks a file absent in memory.
func (w *Workspace) Remove(name string) error
func (w *Workspace) Replace ¶
Replace creates or replaces a file in memory.
func (w *Workspace) Replace(name string, data []byte) error
func (w *Workspace) Root ¶
Root returns the caller-supplied workspace root.
func (w *Workspace) Root() string
Directories ¶
| Path | Synopsis |
|---|---|
| lazycode/gocode | Package gocode provides syntax-aware Go edits as lazycode operations. |
| lazycode/jscode | Package jscode provides deliberately bounded JavaScript text edits as lazycode operations. |
| lazycode/jsoncode | Package jsoncode provides structured JSON object edits as lazycode operations. |
| lazycode/tomlcode | Package tomlcode provides conservative, comment-preserving TOML edits as lazycode operations. |
Package lazycode plans source-file changes without writing them.
Format-specific packages create Operations that edit an in-memory Workspace. Plan returns baseline-bound edits for a caller to review and apply transactionally:
workspace, err := lazycode.Load(".", "js.toml") if err != nil { return err } result, err := workspace.Plan( tomlcode.SetString( "js.toml", "libraries", "turbo", "@hotwired/[email protected]", ), ) if err != nil { return err } for _, edit := range result.Files { fmt.Printf("%s %s\n", edit.Kind, edit.Path) }Planning never writes to disk. Before applying an edit, the caller should re-read its path and call FileEdit.VerifyBaseline. The caller owns confirmation, atomic writes, rollback, and command execution.