suggest

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 5 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 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

View Source
const Limit = 3

Limit bounds how many candidates a "did you mean" offers.

View Source
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

func Budget(n int) int

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

func EditDistance(a, b string) int

EditDistance is the Levenshtein distance between a and b, counting a transposition as one edit.

func Hint

func Hint(msg, word string, candidates, unquoted []string) string

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

func Name(name string) string

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

func Nearest(word string, candidates []string) []string

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

func Notation(fqn string) string

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 OrList

func OrList(items []string) string

OrList joins candidates as "a, b or c", for a message that offers a choice.

func Qualified

func Qualified(idx *symbols.Index, name string) []string

Qualified returns the qualified names under which the index declares the simple name name, the most plausible first (see nearest): `Integer` is declared as `ScalarValues::Integer`.

func QuotingRule

func QuotingRule(names []string) string

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

func Rank(cands []Candidate) []string

Rank offers the candidates no other candidate rules out, closest and most reachable first, a name before a short name, at most Limit of them; the ordering is total.

func SimpleNames

func SimpleNames(idx *symbols.Index) []string

SimpleNames returns every simple name the index registers, sorted.

func Spelled

func Spelled(fqn, name string) string

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`.

func Unquoted

func Unquoted(word string, names []string) []string

Unquoted returns the names, in the order given, that the identifier word starts and that go on with a character no basic name holds: `SA` starts 'SA-506'.

func With

func With(msg, word string, candidates []string) string

With appends "— did you mean …?" to a message about word, ignoring a candidate equal to word.

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
	Short    bool   // the spelling reaches its declaration by the short name, not the name
}

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

type Neighbour struct {
	Name     string
	Distance int
}

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

func Neighbours(word string, candidates []string) []Neighbour

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

func NewTable(idx *symbols.Index) *Table

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

func (t *Table) Declared(name string) []string

Declared is Qualified over every spelling, including the names that must be written quoted.

func (*Table) Neighbours

func (t *Table) Neighbours(word string) []Neighbour

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

func (t *Table) Qualified(name string) []string

Qualified returns the qualified names under which the index declares the simple name name, the most plausible first (see nearest): `Integer` is declared as `ScalarValues::Integer`.

func (*Table) Refresh

func (t *Table) Refresh(names map[string]bool)

Refresh refiles the qualified names the index changed since the table last read it, one lookup each: the table then equals one built afresh.

func (*Table) Unquoted

func (t *Table) Unquoted(word string) []string

Unquoted returns the registered simple names word is the unquoted start of (see Unquoted), in name order.

Jump to

Keyboard shortcuts

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