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 Hint(msg, word string, candidates, unquoted []string) string
- func Name(name string) string
- func Nearest(word string, candidates []string) []string
- func Notation(fqn string) string
- func OrList(items []string) string
- func Qualified(idx *symbols.Index, name string) []string
- func QuotingRule(names []string) string
- func Rank(cands []Candidate) []string
- func SimpleNames(idx *symbols.Index) []string
- func Spelled(fqn, name string) string
- func Unquoted(word string, names []string) []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 Hint ¶
Hint is With, offering first the registered names word is the unquoted start of, each in Notation, and stating the QuotingRule after the question.
func Name ¶
Name writes a registered name as it is typed back: quoted unless a basic name spells it, so a name holding `::` is one segment however it reads.
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 Notation ¶
Notation writes a registered qualified name as it is typed back: a segment no basic name spells is quoted, one the library writes bare (`when`) is left so.
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 QuotingRule ¶
QuotingRule states why the names must be quoted, naming the characters (in the order met) no basic name holds; a leading digit is one such character.
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.
func Spelled ¶
Spelled writes the registered fqn whose last segment is name as it is typed back, that segment quoted whole: `T::'a::b-1'` for `T::a::b-1` named `a::b-1`.
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 Refresh it with the names that change afterwards, or build a new one.
func (*Table) Declared ¶
Declared is Qualified over every spelling, including the names that must be written quoted.
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.
func (*Table) Qualified ¶
Qualified returns the qualified names, shortest first, under which the index declares the simple name name: `Integer` is declared as `ScalarValues::Integer`.