feat: Update get_command_completions and get_completions methods

This commit is contained in:
Paul Gauthier (aider) 2024-09-27 15:59:56 -07:00
parent 01437fa58c
commit 37b512e4fc

View file

@ -94,16 +94,15 @@ class AutoCompleter(Completer):
) )
def get_command_completions(self, text, words): def get_command_completions(self, text, words):
candidates = []
if len(words) == 1 and not text[-1].isspace(): if len(words) == 1 and not text[-1].isspace():
partial = words[0].lower() partial = words[0].lower()
candidates = [cmd for cmd in self.command_names if cmd.startswith(partial)] candidates = [cmd for cmd in self.command_names if cmd.startswith(partial)]
return candidates for candidate in sorted(candidates):
yield Completion(candidate, start_position=-len(words[-1]))
return
if len(words) <= 1: if len(words) <= 1 or text[-1].isspace():
return [] return
if text[-1].isspace():
return []
cmd = words[0] cmd = words[0]
partial = words[-1].lower() partial = words[-1].lower()
@ -124,7 +123,8 @@ class AutoCompleter(Completer):
return return
candidates = [word for word in candidates if partial in word.lower()] candidates = [word for word in candidates if partial in word.lower()]
return candidates for candidate in sorted(candidates):
yield Completion(candidate, start_position=-len(words[-1]))
def get_completions(self, document, complete_event): def get_completions(self, document, complete_event):
self.tokenize() self.tokenize()
@ -139,11 +139,8 @@ class AutoCompleter(Completer):
return return
if text[0] == "/": if text[0] == "/":
candidates = self.get_command_completions(text, words) yield from self.get_command_completions(text, words)
if candidates is not None: return
for candidate in sorted(candidates):
yield Completion(candidate, start_position=-len(words[-1]))
return
candidates = self.words candidates = self.words
candidates.update(set(self.fname_to_rel_fnames)) candidates.update(set(self.fname_to_rel_fnames))