Documentation
¶
Overview ¶
Package fixing applies quick-fix text edits, iterating until no fix applies.
Index ¶
Constants ¶
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 ¶
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.