MCPcopy
hub / github.com/hashicorp/hcl / nameSuggestion

Function nameSuggestion

json/didyoumean.go:28–36  ·  view source on GitHub ↗

nameSuggestion tries to find a name from the given slice of suggested names that is close to the given name and returns it if found. If no suggestion is close enough, returns the empty string. The suggestions are tried in order, so earlier suggestions take precedence if the given string is similar

(given string, suggestions []string)

Source from the content-addressed store, hash-verified

26// This function is intended to be used with a relatively-small number of
27// suggestions. It's not optimized for hundreds or thousands of them.
28func nameSuggestion(given string, suggestions []string) string {
29 for _, suggestion := range suggestions {
30 dist := levenshtein.Distance(given, suggestion, nil)
31 if dist < 3 { // threshold determined experimentally
32 return suggestion
33 }
34 }
35 return ""
36}

Callers 2

keywordSuggestionFunction · 0.70
ContentMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected