Documentation
¶
Overview ¶
Package srcop provides file mutation operations for the src tool: replace, insert, delete, comment, and edit.
Plane: shared
Index ¶
- func Delete(filename string, source []byte, symbolID string, depth int) ([]byte, error)
- func InsertAfter(filename string, source []byte, symbolID string, newContent []byte, depth int) ([]byte, error)
- func InsertBefore(filename string, source []byte, symbolID string, newContent []byte, depth int) ([]byte, error)
- func ReadComment(filename string, source []byte, symbolID string, depth int) (string, error)
- func Replace(filename string, source []byte, symbolID string, newContent []byte, depth int) ([]byte, error)
- func WriteComment(filename string, source []byte, symbolID string, comment []byte, depth int) ([]byte, error)
- type EditResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Delete ¶
Delete removes a symbol and its doc comment from the file. Returns the modified file content.
func InsertAfter ¶
func InsertAfter(filename string, source []byte, symbolID string, newContent []byte, depth int) ([]byte, error)
InsertAfter inserts new content after the symbol identified by symbolID. Returns the modified file content.
func InsertBefore ¶
func InsertBefore(filename string, source []byte, symbolID string, newContent []byte, depth int) ([]byte, error)
InsertBefore inserts new content before the symbol identified by symbolID. Returns the modified file content.
func ReadComment ¶
ReadComment extracts the doc comment attached to a symbol. Returns empty string if no doc comment exists.
func Replace ¶
func Replace(filename string, source []byte, symbolID string, newContent []byte, depth int) ([]byte, error)
Replace replaces a symbol's byte range with new content. Returns the modified file content. Note: Replace does not remove the existing doc comment (DocStart..StartByte). The caller is responsible for including or omitting comment text in newContent. Use WriteComment to update the doc comment independently.
Types ¶
type EditResult ¶ added in v1.0.0
type EditResult struct {
Content []byte // the new file bytes
Pass string // "exact"|"trim-trailing"|"trim-both"|"unicode-fold"
IndentFrom indent.Style // zero value if reindent not attempted
IndentTo indent.Style
Reindented bool
Warnings []string // file-level + reindent line-level warnings
}
EditResult holds the result of an edit operation including match metadata.
func Edit ¶ added in v1.0.0
func Edit(filename string, source []byte, input []byte) (*EditResult, error)
Edit applies a text replacement to source using a BEFORE/AFTER block from input. input must contain ===BEFORE=== and ===AFTER=== delimiters. It does NOT call writeAndShow — that is the caller's responsibility.
func EditDirect ¶ added in v1.0.0
func EditDirect(filename string, source, oldText, newText []byte) (*EditResult, error)
EditDirect applies a text replacement to source using raw oldText/newText bytes, bypassing the ===BEFORE===/===AFTER=== delimiter parser. It does NOT call writeAndShow — that is the caller's responsibility.