MCPcopy Create free account
hub / github.com/cogentcore/core / MatchSeedCompletion

Function MatchSeedCompletion

parse/complete/complete.go:127–145  ·  view source on GitHub ↗

MatchSeedCompletion returns a list of matches given a list of [Completion] possibilities and a seed. It checks whether different transformations of each possible completion contain a lowercase version of the seed. It returns nil if there are no matches.

(completions []Completion, seed string)

Source from the content-addressed store, hash-verified

125// transformations of each possible completion contain a lowercase
126// version of the seed. It returns nil if there are no matches.
127func MatchSeedCompletion(completions []Completion, seed string) []Completion {
128 if len(seed) == 0 {
129 // everything matches
130 return completions
131 }
132
133 var matches []Completion
134 lseed := strings.ToLower(seed)
135
136 for _, c := range completions {
137 if IsSeedMatching(lseed, c.Text) {
138 matches = append(matches, c)
139 }
140 }
141 slices.SortStableFunc(matches, func(a, b Completion) int {
142 return cmp.Compare(MatchPrecedence(lseed, a.Text), MatchPrecedence(lseed, b.Text))
143 })
144 return matches
145}
146
147// IsSeedMatching returns whether the given lowercase seed matches
148// the given completion string. It checks whether different

Callers 4

CompleteMatchMethod · 0.92
childByLabelCanFocusFunction · 0.92
completeMatchMethod · 0.92
TestMatchSeedCompletionFunction · 0.85

Calls 3

IsSeedMatchingFunction · 0.85
MatchPrecedenceFunction · 0.85
CompareMethod · 0.45

Tested by 1

TestMatchSeedCompletionFunction · 0.68