From 42ccd9c5505167fdc8fca6664edaa8f5c569a42d Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 10 May 2023 17:48:15 -0700 Subject: [PATCH] improved completions for /add and /drop --- aider/commands.py | 24 ++++++++++++++++-------- aider/getinput.py | 6 +++++- aider/prompts.py | 5 +++-- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/aider/commands.py b/aider/commands.py index 2e39e9719..3a7e2e407 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -1,5 +1,6 @@ import os from rich.text import Text +from prompt_toolkit.completion import Completion class Commands: @@ -35,11 +36,12 @@ class Commands: else: self.console.print(f"Error: Command {cmd_name} not found.") - def get_command_completions(self, cmd_name): + def get_command_completions(self, cmd_name, partial): cmd_completions_method_name = f"completions_{cmd_name}" cmd_completions_method = getattr(self, cmd_completions_method_name, None) if cmd_completions_method: - return set(cmd_completions_method()) + for completion in cmd_completions_method(partial): + yield completion def run(self, inp): words = inp.strip().split() @@ -143,13 +145,19 @@ class Commands: else: self.console.print(f"[red]{matched_file} is already in the chat") - def completions_add(self): - res = set(self.coder.get_all_relative_files()) - res = res - set(self.coder.get_inchat_relative_files()) - return res + def completions_add(self, partial): + files = set(self.coder.get_all_relative_files()) + files = files - set(self.coder.get_inchat_relative_files()) + for fname in files: + if partial.lower() in fname.lower(): + yield Completion(fname, start_position=-len(partial)) - def completions_drop(self): - return self.coder.get_inchat_relative_files() + def completions_drop(self, partial): + files = self.coder.get_inchat_relative_files() + + for fname in files: + if partial.lower() in fname.lower(): + yield Completion(fname, start_position=-len(partial)) def cmd_drop(self, args): "Remove matching files from the chat" diff --git a/aider/getinput.py b/aider/getinput.py index e0970fc00..8e2e140de 100644 --- a/aider/getinput.py +++ b/aider/getinput.py @@ -35,7 +35,11 @@ class FileContentCompleter(Completer): if len(words) == 1 and not text[-1].isspace(): candidates = self.commands.get_commands() else: - candidates = self.commands.get_command_completions(words[0][1:]) + for completion in self.commands.get_command_completions( + words[0][1:], words[-1] + ): + yield completion + return else: candidates = self.words diff --git a/aider/prompts.py b/aider/prompts.py index 9fbd377aa..fa6e655bb 100644 --- a/aider/prompts.py +++ b/aider/prompts.py @@ -21,8 +21,6 @@ class Foo: Take requests from the user for new features, improvements, bug fixes and other changes to the supplied code. If the user's request is ambiguous, ask questions to fully understand. -IF THE FILES DON'T CONTAIN THE RELEVANT CODE, SAY SO! - Once you understand the user's request and can see all the relevant code, your responses MUST be: 1. Briefly explain the needed changes. @@ -47,6 +45,9 @@ some/dir/example.py """Multiplies 2 numbers""" >>>>>>> UPDATED +If need to see the contents of a file from the git repo, ask the user! +Don't edit a listed file without looking at the contents first! + You can make a new file by replying with an ORIGINAL/UPDATE that has an empty ORIGINAL block. *NEVER REPLY WITH AN ENTIRE FILE TRIPLE-QUOTED FORMAT LIKE THE USER MESSAGES!*