Documentation
¶
Index ¶
- Constants
- func AssignMoveColors(actions []Action, srcOffsets, dstOffsets []int)
- func BuildLineIndex(data []byte) []int
- func ByteToLineCol(lineIndex []int, offset uint32) (line, col int)
- func EqualIgnoringStyle(s, d string, significantWhitespace bool) bool
- func ForEachLineSpan(lineIndex []int, fileBytes []byte, startByte, endByte uint32, ...)
- func FormatFallbackAnnotationLineLimit(lines int) string
- func FormatFallbackAnnotationSizeLimit(sizeBytes int) string
- func MarshalWithOptions(es *actions.EditScript, ms *engine.Mapping, ...) ([]byte, error)
- func ResolveMoveColor(act *Action, lineCount int) int
- type Action
- type DelimiterSpan
- type Envelope
- type EnvelopeOptions
- type FallbackReason
- type HighlightSpan
- type LineAlignmentPair
- type NodeRef
Constants ¶
const FallbackAnnotationConflict = "[merge conflict markers, falling back to line diff]"
FallbackAnnotationConflict is the terminal badge text for merge conflicts.
const FallbackAnnotationParseError = "[parse error, falling back to line diff]"
FallbackAnnotationParseError is the terminal badge text for parse errors.
const MaxUngroupedHighlightLines = 3
MaxUngroupedHighlightLines is how many lines a standalone move can span before dropping its contrasting color (slot 1 / Magenta) and falling back to Cyan (slot 0).
const SchemaVersion = "v1"
SchemaVersion defines the stable, versioned JSON output format version.
Variables ¶
This section is empty.
Functions ¶
func AssignMoveColors ¶ added in v0.10.0
AssignMoveColors assigns move colors (0: Cyan, 1: Magenta) to moved actions:
- Descendants moving with a parent inherit that parent's color.
- Adjacent moves shifting together in the same order share a color so lines don't alternate colors for no reason.
- Swaps, reordered moves, or moves nested inside another take different colors so they stand out.
- Moves diverging from the same parent or converging near the same destination take different colors, unless one moved into the other's body block.
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 EqualIgnoringStyle ¶ added in v0.15.0
EqualIgnoringStyle reports whether two lines match once whitespace is stripped away. For indentation-sensitive languages (Python), leading whitespace must match exactly. For delimiter-based languages (Go, Rust), leading indentation shifts are ignored.
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 FormatFallbackAnnotationLineLimit ¶ added in v0.16.0
FormatFallbackAnnotationLineLimit returns the terminal badge text when line count exceeds DIFFM_LINE_LIMIT.
func FormatFallbackAnnotationSizeLimit ¶ added in v0.16.0
FormatFallbackAnnotationSizeLimit returns the terminal badge text when file size exceeds DIFFM_SIZE_LIMIT.
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.
func ResolveMoveColor ¶ added in v0.14.0
ResolveMoveColor picks the color slot for a move. Standalone moves keep slot 1 (Magenta) up to 3 lines; larger ungrouped blocks collapse to slot 0 (Cyan). Grouped moves keep whatever color AssignMoveColors picked.
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"`
MoveColorIndex int `json:"-"`
OrigStartByte uint32 `json:"-"`
OrigEndByte uint32 `json:"-"`
DestOrigStartByte uint32 `json:"-"`
DestOrigEndByte uint32 `json:"-"`
ASTNode *treesitter.ASTNode `json:"-"`
DestASTNode *treesitter.ASTNode `json:"-"`
SrcLineCount int `json:"-"`
DstLineCount int `json:"-"`
}
Action is a single AST edit operation. Omitting "subtree" on the wire implicitly means 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"`
FallbackReason FallbackReason `json:"fallback_reason,omitempty"`
FallbackAnnotation string `json:"fallback_annotation,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 translates raw diff actions and line alignments into the finalized JSON payload.
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.
func (*Envelope) IsFallback ¶ added in v0.15.0
IsFallback reports whether the envelope represents a line-diff fallback rather than a clean AST diff.
type EnvelopeOptions ¶ added in v0.6.0
type EnvelopeOptions struct {
IncludeActions bool
IncludeAlignment bool
IncludeHighlights bool
CommentLineMappings map[int]int
ShowStyleChanges bool
SignificantWhitespace bool
}
EnvelopeOptions selects which sections to include in the JSON envelope.
type FallbackReason ¶ added in v0.14.0
type FallbackReason string
FallbackReason classifies why Diffmantic degraded to line-diff mode.
const ( FallbackReasonNone FallbackReason = "" FallbackReasonParseError FallbackReason = "parse_error" FallbackReasonFileSizeLimit FallbackReason = "file_size_limit" FallbackReasonLineLimit FallbackReason = "line_limit" FallbackReasonConflict FallbackReason = "merge_conflict" FallbackReasonMergeConflict = FallbackReasonConflict FallbackReasonUnsupportedLanguage FallbackReason = "unsupported_language" FallbackReasonMismatchedLanguages FallbackReason = "mismatched_languages" )
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"
ColorIndex int `json:"-"`
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, ms *engine.Mapping, es *actions.EditScript, commentLineMappings ...map[int]int) []LineAlignmentPair
AlignLines computes the side-by-side alignment grid using exact line diff matches and semantic AST node mappings as alignment anchors.
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