From 37b512e4fc9d449d52505fc09562e9d396bafbe5 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Fri, 27 Sep 2024 15:59:56 -0700 Subject: [PATCH] feat: Update get_command_completions and get_completions methods --- aider/io.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/aider/io.py b/aider/io.py index a71c91469..624e68885 100644 --- a/aider/io.py +++ b/aider/io.py @@ -94,16 +94,15 @@ class AutoCompleter(Completer): ) def get_command_completions(self, text, words): - candidates = [] if len(words) == 1 and not text[-1].isspace(): partial = words[0].lower() 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: - return [] - if text[-1].isspace(): - return [] + if len(words) <= 1 or text[-1].isspace(): + return cmd = words[0] partial = words[-1].lower() @@ -124,7 +123,8 @@ class AutoCompleter(Completer): return 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): self.tokenize() @@ -139,11 +139,8 @@ class AutoCompleter(Completer): return if text[0] == "/": - candidates = self.get_command_completions(text, words) - if candidates is not None: - for candidate in sorted(candidates): - yield Completion(candidate, start_position=-len(words[-1])) - return + yield from self.get_command_completions(text, words) + return candidates = self.words candidates.update(set(self.fname_to_rel_fnames))