diff

package module
v0.0.0-...-75e60ef Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: BSD-3-Clause Imports: 5 Imported by: 0

README

diff

This is a copy of the Go text diffing package that gopls uses to generate unified diffs.

The code is entirely written by the Go Authors.

No PRs will be accepted here - please contribute to the upstream source!

License

See https://github.com/golang/tools/blob/master/LICENSE

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(src string, edits []Edit) (string, error)

Apply applies a sequence of edits to the src buffer and returns the result. Edits are applied in order of start offset; edits with the same start offset are applied in they order they were provided.

Apply returns an error if any edit is out of bounds, or if any pair of edits is overlapping.

func SortEdits

func SortEdits(edits []Edit)

SortEdits orders a slice of Edits by (start, end) offset. This ordering puts insertions (end = start) before deletions (end > start) at the same point, but uses a stable sort to preserve the order of multiple insertions at the same point. (Apply detects multiple deletions at the same point as an error.)

func Unified

func Unified(
	content string, edits []Edit,
	split func(string) []string,
	format func(string, bool) string,
) (string, error)

Types

type Edit

type Edit struct {
	Start, End int    // byte offsets of the region to replace
	New        string // the replacement
}

An Edit describes the replacement of a portion of a text file.

func Strings

func Strings(before, after string) []Edit

Strings computes the differences between two strings. The resulting edits respect rune boundaries.

func (Edit) String

func (e Edit) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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