fixing

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 4 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 fixing applies quick-fix text edits, iterating until no fix applies.

Index

Constants

View Source
const MaxIterations = 10

MaxIterations bounds the re-analyse/re-fix loop.

Variables

This section is empty.

Functions

func Apply

func Apply(src []byte, edits []diagnostic.TextEdit) ([]byte, int)

Apply applies edits to src. Edits overlapping an earlier (by position, then by input order) edit are dropped; the number applied is returned.

func Edits

func Edits(f diagnostic.Fix) (edits []diagnostic.TextEdit, ok bool)

Edits computes the edits of a fix. Fixes compute them lazily, outside the engine's crash isolation: ok is false when the computation panics, and the fix is then left out instead of failing the whole request or run.

Types

type Analyzer

type Analyzer interface {
	Analyze(*syntax.File) []diagnostic.Finding
}

Analyzer supplies findings for a parsed source file.

type Options

type Options struct {
	Parse syntax.Options
	// Filter selects which findings to fix (nil = all fixable findings).
	Filter func(diagnostic.Finding) bool
	// SinglePass applies the fixes of the first analysis only (IDE
	// "apply all quick-fixes" semantics, used by conformance tests).
	SinglePass bool
}

Options control FixSource.

type Result

type Result struct {
	Source     []byte
	Applied    int // total edits applied over all iterations
	Iterations int
}

Result of fixing one source.

func FixSource

func FixSource(e Analyzer, path string, src []byte, opt Options) Result

FixSource repeatedly analyses src and applies the first fix of every fixable finding (one fix per finding, non-overlapping) until nothing changes or MaxIterations is reached. A fix applies whole or not at all: one whose edits leave the source or overlap each other is skipped, and an iteration whose result has more syntax errors than its input is undone and ends the loop.

func FixSourceContext

func FixSourceContext(ctx context.Context, e Analyzer, path string, src []byte, opt Options) Result

FixSourceContext is FixSource stopping between iterations once ctx is done.

Jump to

Keyboard shortcuts

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