Documentation
¶
Overview ¶
Package suggest offers the spellings a name that did not resolve may have meant: the qualified names the index declares it under, or the nearest spellings by edit distance. Shared by every surface reporting an unresolved name.
Index ¶
- Constants
- func Budget(n int) int
- func EditDistance(a, b string) int
- func LastSegment(fqn string) string
- func Nearest(word string, candidates []string) []string
- func OrList(items []string) string
- func Qualified(idx *symbols.Index, name string) []string
- func Rank(cands []Candidate) []string
- func SimpleNames(idx *symbols.Index) []string
- func With(msg, word string, candidates []string) string
- type Candidate
- type Neighbour
- type Table
Constants ¶
const Limit = 3
Limit bounds how many candidates a "did you mean" offers.
const NeighbourLimit = 25
NeighbourLimit bounds how many near spellings are considered for one name, so a common short name does not cost a scope search per registered name.
Variables ¶
This section is empty.
Functions ¶
func Budget ¶
Budget is how many edits a name of n runes justifies as a typo. It scales with the name, since one edit of a short name reaches most short names: a name of two runes or fewer is too short for a typo to be identifiable.
func EditDistance ¶
EditDistance is the Levenshtein distance between a and b, counting a transposition as one edit.
func LastSegment ¶
LastSegment returns the simple name a qualified name ends in.
func Nearest ¶
Nearest returns the spellings closest to word by edit distance, within the budget a typo of that length justifies. It is what a surface with one flat set of equally reachable names asks — the REPL's meta commands.
func Qualified ¶
Qualified returns the qualified names, shortest first, under which the index declares the simple name name: `Integer` is declared as `ScalarValues::Integer`.
func Rank ¶
Rank offers the candidates no other candidate rules out, closest and most reachable first, at most Limit of them. Ordering is total, so the same candidate set always reads the same way.
func SimpleNames ¶
SimpleNames returns every simple name the index registers, sorted.
Types ¶
type Candidate ¶
type Candidate struct {
Spelling string // what to offer: a name usable as written, else a qualified path
Distance int // edit distance from the typed name
InScope bool // the spelling resolves from the reference's scope as written
Library bool // declared by bundled library content, not by the workspace
}
Candidate is a spelling a name that did not resolve may have meant, beside what makes it plausible: how far it is from the typed name, and how the user would reach it.
type Neighbour ¶
Neighbour is a registered name beside its distance from the one that did not resolve. The budget is spent case-insensitively — a wrong case is a typo — but Distance counts case, so a name spelled as typed is the closer guess.
func Neighbours ¶
Neighbours returns the candidates within word's edit-distance budget, closest first, at most NeighbourLimit of them.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table indexes what an index registers, once, so a suggestion costs a lookup and a search of the plausible spellings rather than a scan of every name.
func NewTable ¶
NewTable sweeps the index once. It reads the index, so build a new one after the index changes.
func (*Table) Neighbours ¶
Neighbours returns the registered simple names within word's edit-distance budget, closest first, at most NeighbourLimit of them: what a caller scores against the scope the name was written in.