linediff

package
v0.75.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 3 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

Overview

Package linediff computes line-based diffs that stay minimal for scattered edits and place ambiguous insertions/deletions at readable boundaries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Inline

func Inline(oldLines, newLines []string) (oldRanges, newRanges [][]Range)

Inline finds the changed words between a block of removed lines and the added lines that replaced it. It returns byte ranges per line, or nil when the blocks share too little for a word-level comparison to help.

Types

type Hunk

type Hunk struct {
	OldStart, OldCount int
	NewStart, NewCount int
	Lines              []Line
}

func Compute

func Compute(oldContent, newContent string, context int) []Hunk

Compute returns unified-diff hunks with the given number of context lines.

type Kind

type Kind uint8
const (
	Equal Kind = iota
	Delete
	Insert
)

type Line

type Line struct {
	Kind Kind
	Old  int
	New  int
	Text string
}

Line is a single diff line. Old and New are 1-based line numbers; zero means the line does not exist on that side. Text excludes the trailing "\n".

type Range

type Range struct {
	Start, End int
}

Range is a half-open byte range [Start, End) within one line.

Jump to

Keyboard shortcuts

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