tools: golang.org/x/tools/internal/lsp/diff Index | Files | Directories

package diff

import "golang.org/x/tools/internal/lsp/diff"

Package diff supports a pluggable diff algorithm.

Index

Package Files

diff.go unified.go

func ApplyEdits Uses

func ApplyEdits(before string, edits []TextEdit) string

ApplyEdits applies the set of edits to the before and returns the resulting content. It may panic or produce garbage if the edits are not valid for the provided before content.

func SortTextEdits Uses

func SortTextEdits(d []TextEdit)

SortTextEdits attempts to order all edits by their starting points. The sort is stable so that edits with the same starting point will not be reordered.

type ComputeEdits Uses

type ComputeEdits func(uri span.URI, before, after string) []TextEdit

ComputeEdits is the type for a function that produces a set of edits that convert from the before content to the after content.

type Hunk Uses

type Hunk struct {
    // The line in the original source where the hunk starts.
    FromLine int
    // The line in the original source where the hunk finishes.
    ToLine int
    // The set of line based edits to apply.
    Lines []Line
}

Hunk represents a contiguous set of line edits to apply.

type Line Uses

type Line struct {
    // Kind is the type of line this represents, deletion, insertion or copy.
    Kind OpKind
    // Content is the content of this line.
    // For deletion it is the line being removed, for all others it is the line
    // to put in the output.
    Content string
}

Line represents a single line operation to apply as part of a Hunk.

type OpKind Uses

type OpKind int

OpKind is used to denote the type of operation a line represents.

const (
    // Delete is the operation kind for a line that is present in the input
    // but not in the output.
    Delete OpKind = iota
    // Insert is the operation kind for a line that is new in the output.
    Insert
    // Equal is the operation kind for a line that is the same in the input and
    // output, often used to provide context around edited lines.
    Equal
)

func (OpKind) String Uses

func (k OpKind) String() string

String returns a human readable representation of an OpKind. It is not intended for machine processing.

type TextEdit Uses

type TextEdit struct {
    Span    span.Span
    NewText string
}

TextEdit represents a change to a section of a document. The text within the specified span should be replaced by the supplied new text.

func LineEdits Uses

func LineEdits(before string, edits []TextEdit) []TextEdit

LineEdits takes a set of edits and expands and merges them as necessary to ensure that there are only full line edits left when it is done.

type Unified Uses

type Unified struct {
    // From is the name of the original file.
    From string
    // To is the name of the modified file.
    To  string
    // Hunks is the set of edit hunks needed to transform the file content.
    Hunks []*Hunk
}

Unified represents a set of edits as a unified diff.

func ToUnified Uses

func ToUnified(from, to string, content string, edits []TextEdit) Unified

ToUnified takes a file contents and a sequence of edits, and calculates a unified diff that represents those edits.

func (Unified) Format Uses

func (u Unified) Format(f fmt.State, r rune)

Format converts a unified diff to the standard textual form for that diff. The output of this function can be passed to tools like patch.

Directories

PathSynopsis
difftestPackage difftest supplies a set of tests that will operate on any implementation of a diff algorithm as exposed by "golang.org/x/tools/internal/lsp/diff"
myersPackage myers implements the Myers diff algorithm.

Package diff imports 4 packages (graph) and is imported by 11 packages. Updated 2019-11-14. Refresh now. Tools for package owners.