serialize

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
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

func BuildLineIndex(data []byte) []int

BuildLineIndex returns byte offsets for the start of each line.

func ByteToLineCol added in v0.4.0

func ByteToLineCol(lineIndex []int, offset uint32) (line, col int)

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 Envelope

type Envelope struct {
	Version         string              `json:"version"`
	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

type EnvelopeOptions struct {
	IncludeActions      bool
	IncludeAlignment    bool
	IncludeHighlights   bool
	CommentLineMappings map[int]int // Maps source to destination line numbers for matched comments.
}

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) []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.

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

type LineAlignmentPair struct {
	LeftLine  int `json:"left_line"`
	RightLine int `json:"right_line"`
}

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,
	es *actions.EditScript,
	ms *engine.Mapping,
	srcRoot, dstRoot *treesitter.ASTNode,
	commentLineMappings map[int]int,
) []LineAlignmentPair

AlignLines computes a visual side-by-side alignment grid for the source and destination lines, using line-level similarity and AST mappings.

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

type NodeRef

type NodeRef struct {
	Tree      string `json:"tree"` // "before" or "after"
	Type      string `json:"type"`
	Label     string `json:"label,omitempty"`
	StartByte uint32 `json:"start_byte"`
	EndByte   uint32 `json:"end_byte"`
}

NodeRef is a stable and self-describing reference to an AST node.

Jump to

Keyboard shortcuts

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