diff

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package diff computes unified-style diffs for proposed file writes. The FileDiff type is consumed by both the TUI and the future web server.

Index

Constants

View Source
const MaxDiffLines = 500

Variables

This section is empty.

Functions

This section is empty.

Types

type DiffLine

type DiffLine struct {
	Kind    LineKind   `json:"kind"`
	Content string     `json:"content"`
	Spans   []WordSpan `json:"spans,omitempty"` // populated for matched Remove+Add pairs
}

DiffLine is one line of a diff output.

type FileDiff

type FileDiff struct {
	Path      string
	IsNew     bool
	IsDeleted bool
	Adds      int
	Removes   int
	Lines     []DiffLine // capped at MaxDiffLines body lines
	Truncated int        // number of body lines omitted due to cap
}

FileDiff is the result of diffing one proposed write against the on-disk file.

func Compute

func Compute(path, newContent string) FileDiff

Compute diffs newContent against the file at path. If the file does not exist it is treated as empty (new file).

func ComputeDeleted

func ComputeDeleted(path string) FileDiff

ComputeDeleted produces a diff for a file being deleted. It reads the file from disk and produces a diff where all lines are removals. If the file does not exist or cannot be read, it returns a minimal FileDiff.

type LineKind

type LineKind string

LineKind classifies a single diff line.

const (
	Add     LineKind = "add"
	Remove  LineKind = "remove"
	Context LineKind = "context"
	Hunk    LineKind = "hunk"
)

type WordSpan

type WordSpan struct {
	Text    string `json:"text"`
	Changed bool   `json:"changed"`
}

WordSpan is a segment of a diff line with a flag indicating whether it was changed. Spans cover the text after the leading +/-/ prefix character in Content.

Jump to

Keyboard shortcuts

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