Get rid of WordPrefix

This commit is contained in:
Kovid Goyal 2022-09-16 20:41:18 +05:30
parent 0ff2446a1a
commit 3a8bab90dc
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 13 additions and 4 deletions

View File

@ -121,6 +121,9 @@ def completion(self: TestCompletion, tdir: str):
add('kitty -1 ', does_not_have_words('@ls', '@'))
add('kitty --directory ', all_words('bin/', 'sub/'))
add('kitty -1d ', all_words('bin/', 'sub/'))
add('kitty -1d', all_words('-1d'))
add('kitty --directory=', all_words('--directory=bin/', '--directory=sub/'))
add('kitty --start-as=m', all_words('--start-as=minimized', '--start-as=maximized'))
for cmd, tests, result in zip(all_cmds, all_tests, run_tool()):
self.current_cmd = cmd

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 {