serialize

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 7 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 Marshal

func Marshal(es *actions.EditScript, ms *engine.Mapping, srcRoot, dstRoot *treesitter.ASTNode, srcBytes, dstBytes []byte) ([]byte, error)

Marshal serializes the diff result into an indented JSON byte slice.

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"`
	LineAlignment []LineAlignmentPair `json:"line_alignment,omitempty"`
}

Envelope wraps the serialized actions list with a schema version.

func BuildEnvelope added in v0.2.0

func BuildEnvelope(es *actions.EditScript, ms *engine.Mapping, srcRoot, dstRoot *treesitter.ASTNode, srcBytes, dstBytes []byte) (*Envelope, error)

BuildEnvelope bundles the edit script, AST mappings, and metadata into a unified envelope.

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

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

type NodeRef

type NodeRef struct {
	Tree      string `json:"tree"` // "before" or "after"
	Path      []int  `json:"path"`
	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