Get rid of WordPrefix

This commit is contained in:
Kovid Goyal
2022-09-16 20:41:18 +05:30
parent 0ff2446a1a
commit 3a8bab90dc
3 changed files with 13 additions and 4 deletions

View File

@@ -91,8 +91,8 @@ func complete_word(word string, completions *Completions, only_args_allowed bool
option := cmd.find_option(word[:idx])
if option != nil {
if option.Completion_for_arg != nil {
completions.WordPrefix = word[:idx+1]
option.Completion_for_arg(completions, word[idx+1:], arg_num)
completions.add_prefix_to_all_matches(word[:idx+1])
}
}
} else {

View File

@@ -14,7 +14,6 @@ type MatchGroup struct {
NoTrailingSpace bool `json:"no_trailing_space,omitempty"`
IsFiles bool `json:"is_files,omitempty"`
Matches []*Match `json:"matches,omitempty"`
WordPrefix string `json:"word_prefix,omitempty"`
}
func (self *MatchGroup) add_match(word string, description ...string) *Match {
@@ -24,14 +23,21 @@ func (self *MatchGroup) add_match(word string, description ...string) *Match {
}
type Completions struct {
Groups []*MatchGroup `json:"groups,omitempty"`
WordPrefix string `json:"word_prefix,omitempty"`
Groups []*MatchGroup `json:"groups,omitempty"`
current_cmd *Command
all_words []string // all words passed to parse_args()
current_word_idx int // index of current word in all_words
}
func (self *Completions) add_prefix_to_all_matches(prefix string) {
for _, mg := range self.Groups {
for _, m := range mg.Matches {
m.Word = prefix + m.Word
}
}
}
func (self *Completions) add_match_group(title string) *MatchGroup {
for _, q := range self.Groups {
if q.Title == title {