indentheuristic

package
v0.0.0-...-b13b7c6 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package indentheuristic is an implementation of the indentation heuristic by Michael Haggerty (https://github.com/mhagger/diff-slider-tools).

The idea behind the heuristic is that, since there's usually not a single solution, we can locally vary the solution we found to improve the aesthetics. We can vary the solution around the following degrees of freedom:

a. A deletion of a line X, followed by an insertion of line Y is the same as an insertion of
   line Y followed by a deletion of line X.
b. A deletion of a line X, followed by zero or more deletions, followed by a match Y with
   X == Y allows us to swap the deletion and the match. The same is true for insertions. The
   same is true the other way around (match of line X, followed by zero or more deletions,
   followed by a deletion of line Y with X == Y).

The heuristics use these degrees of freedom to achieve the following goals:

  1. Group deletions and insertions using (we do this implicitly by how we construct the diff from the result slices).
  2. Make deletion and insertion groups as large as possible by merging adjacent groups if using.
  3. If possible align deletions and insertions such that deletions are followed by insertions without a matching line in between using.
  4. If it's not possible to align deletions and insertions, shift beginnings and ends of deletions / insertion groups to a line that has significance to humans based on indention at the line and around the line.

The most intricate piece of these heuristics are in (4) which is based on human rated diffs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(x, y []byteview.ByteView, rx, ry []bool)

Apply applies the indent heuristics to rx and ry.

Types

This section is empty.

Jump to

Keyboard shortcuts

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