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)
| 125 | // transformations of each possible completion contain a lowercase |
| 126 | // version of the seed. It returns nil if there are no matches. |
| 127 | func 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 |