Help us shape the future of Go! Take the 2026 Go Developer Survey

suggest

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

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 LastSegment

func LastSegment(fqn string) string

LastSegment returns the simple name a qualified name ends in.

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 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, shortest first, under which the index declares the simple name name: `Integer` is declared as `ScalarValues::Integer`.

func Rank

func Rank(cands []Candidate) []string

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

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

SimpleNames returns every simple name the index registers, sorted.

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
}

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 build a new one after the index changes.

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, shortest first, under which the index declares the simple name name: `Integer` is declared as `ScalarValues::Integer`.

Jump to

Keyboard shortcuts

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