Documentation
¶
Index ¶
- Constants
- func BuildLineIndex(data []byte) []int
- func ByteToLineCol(lineIndex []int, offset uint32) (line, col int)
- func ForEachLineSpan(lineIndex []int, fileBytes []byte, startByte, endByte uint32, ...)
- func MarshalWithOptions(es *actions.EditScript, ms *engine.Mapping, ...) ([]byte, error)
- type Action
- type DelimiterSpan
- type Envelope
- type EnvelopeOptions
- type HighlightSpan
- type LineAlignmentPair
- type NodeRef
Constants ¶
const SchemaVersion = "v1"
SchemaVersion defines the stable, versioned JSON output format version.
Variables ¶
This section is empty.
Functions ¶
func BuildLineIndex ¶ added in v0.4.0
BuildLineIndex returns byte offsets for the start of each line.
func ByteToLineCol ¶ added in v0.4.0
ByteToLineCol maps a byte offset to a zero-indexed line and column.
func ForEachLineSpan ¶ added in v0.4.0
func ForEachLineSpan(lineIndex []int, fileBytes []byte, startByte, endByte uint32, yield func(line, startCol, endCol int))
ForEachLineSpan runs yield for every line that intersects [startByte, endByte].
func MarshalWithOptions ¶ added in v0.6.0
func MarshalWithOptions(es *actions.EditScript, ms *engine.Mapping, srcRoot, dstRoot *treesitter.ASTNode, srcBytes, dstBytes []byte, opts EnvelopeOptions) ([]byte, error)
MarshalWithOptions formats the diff envelope as indented JSON using the given options.
Types ¶
type Action ¶
type Action struct {
Action string `json:"action"` // "insert", "delete", "update", "move"
Node *NodeRef `json:"node"`
Parent *NodeRef `json:"parent,omitempty"`
Position *int `json:"position,omitempty"`
OldParent *NodeRef `json:"old_parent,omitempty"`
OldPosition *int `json:"old_position,omitempty"`
OldValue string `json:"old_value,omitempty"`
NewValue string `json:"new_value,omitempty"`
Subtree *bool `json:"subtree,omitempty"`
DestNode *NodeRef `json:"dest_node,omitempty"`
DestStartByte *uint32 `json:"dest_start_byte,omitempty"`
DestEndByte *uint32 `json:"dest_end_byte,omitempty"`
GroupID string `json:"group_id,omitempty"`
}
Action represents a serialized edit-script action. The absence of the "subtree" field always indicates false.
type DelimiterSpan ¶ added in v0.8.0
type DelimiterSpan struct {
StartByte uint32
EndByte uint32
Action string // "insert", "delete", "move"
ActionRef *Action
}
DelimiterSpan tracks a closing delimiter (like a brace or bracket) for UI highlights.
type Envelope ¶
type Envelope struct {
Version string `json:"version"`
IsBinary bool `json:"is_binary,omitempty"`
Actions []Action `json:"actions,omitempty"`
LineAlignment []LineAlignmentPair `json:"line_alignment,omitempty"`
LeftHighlights []HighlightSpan `json:"left_highlights,omitempty"`
RightHighlights []HighlightSpan `json:"right_highlights,omitempty"`
}
Envelope wraps the serialized actions list with a schema version.
func BuildEnvelopeWithOptions ¶ added in v0.6.0
func BuildEnvelopeWithOptions(es *actions.EditScript, ms *engine.Mapping, srcRoot, dstRoot *treesitter.ASTNode, srcBytes, dstBytes []byte, opts EnvelopeOptions) (*Envelope, error)
BuildEnvelopeWithOptions packages the edit script, AST mappings, and UI metadata into an Envelope based on opts.
func BuildLineDiffEnvelopeWithOptions ¶ added in v0.6.0
func BuildLineDiffEnvelopeWithOptions(srcBytes, dstBytes []byte, opts EnvelopeOptions) *Envelope
BuildLineDiffEnvelopeWithOptions builds a fallback line-diff envelope when tree-sitter parsing fails or is skipped.
type EnvelopeOptions ¶ added in v0.6.0
EnvelopeOptions selects which sections to include in the JSON envelope.
type HighlightSpan ¶ added in v0.6.0
type HighlightSpan struct {
Line int `json:"line"`
StartCol int `json:"start_col"`
EndCol int `json:"end_col"`
Action string `json:"action"` // "insert", "delete", "update", "move"
ActionRef *Action `json:"-"`
}
HighlightSpan is a visual column range to color on a specific line.
func BuildHighlightSpans ¶ added in v0.6.0
func BuildHighlightSpans(fileBytes []byte, actions []Action, side string, extraSpans ...DelimiterSpan) []HighlightSpan
BuildHighlightSpans returns pre-merged highlight spans for one side of a diff. It splits byte ranges across newlines and merges adjacent spans of the same action when separated only by small punctuation or whitespace gaps. Pass extraSpans to include closing delimiter highlights without adding extra actions.
func (HighlightSpan) MarshalJSON ¶ added in v0.6.0
func (s HighlightSpan) MarshalJSON() ([]byte, error)
func (*HighlightSpan) UnmarshalJSON ¶ added in v0.6.0
func (s *HighlightSpan) UnmarshalJSON(b []byte) error
type LineAlignmentPair ¶ added in v0.2.0
LineAlignmentPair matches a source file line to a destination file line. A line index of -1 indicates a filler line.
func AlignLines ¶ added in v0.2.0
func AlignLines(srcBytes, dstBytes []byte) []LineAlignmentPair
AlignLines builds a side-by-side line alignment grid using line-level LCS diffing.
func (LineAlignmentPair) MarshalJSON ¶ added in v0.6.0
func (p LineAlignmentPair) MarshalJSON() ([]byte, error)
func (*LineAlignmentPair) UnmarshalJSON ¶ added in v0.6.0
func (p *LineAlignmentPair) UnmarshalJSON(b []byte) error