From 5ba084edec6f73e394c1e6a13d8b5c60ed6f22c7 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 27 May 2023 08:54:10 -0700 Subject: [PATCH] auto-complete filenames --- aider/coder.py | 15 ++++++++++----- aider/io.py | 25 +++++++++++++++++++++---- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/aider/coder.py b/aider/coder.py index 7a04abff4..a5730d160 100755 --- a/aider/coder.py +++ b/aider/coder.py @@ -237,8 +237,12 @@ class Coder: return True def run_loop(self): - rel_fnames = self.get_inchat_relative_files() - inp = self.io.get_input(self.root, rel_fnames, self.commands) + inp = self.io.get_input( + self.root, + self.get_inchat_relative_files(), + self.get_addable_relative_files(), + self.commands, + ) self.num_control_c = 0 @@ -340,9 +344,7 @@ class Coder: quotes = "".join(['"', "'", "`"]) words = set(word.strip(quotes) for word in words) - addable_rel_fnames = set(self.get_all_relative_files()) - set( - self.get_inchat_relative_files() - ) + addable_rel_fnames = self.get_addable_relative_files() mentioned_rel_fnames = set() fname_to_rel_fnames = {} @@ -639,6 +641,9 @@ class Coder: return 0 return max(Path(path).stat().st_mtime for path in files) + def get_addable_relative_files(self): + return set(self.get_all_relative_files()) - set(self.get_inchat_relative_files()) + def apply_updates(self, content, inp): try: edited = self.update_files(content, inp) diff --git a/aider/io.py b/aider/io.py index 1457e92be..42bad149c 100644 --- a/aider/io.py +++ b/aider/io.py @@ -14,11 +14,18 @@ from datetime import datetime class FileContentCompleter(Completer): - def __init__(self, root, rel_fnames, commands): + def __init__(self, root, rel_fnames, addable_rel_fnames, commands): self.commands = commands + self.addable_rel_fnames = addable_rel_fnames + self.rel_fnames = rel_fnames self.words = set() + for rel_fname in addable_rel_fnames: + self.words.add(rel_fname) + for rel_fname in rel_fnames: + self.words.add(rel_fname) + fname = os.path.join(root, rel_fname) with open(fname, "r") as f: content = f.read() @@ -52,7 +59,15 @@ class FileContentCompleter(Completer): class InputOutput: - def __init__(self, pretty=True, yes=False, input_history_file=None, chat_history_file=None, input=None, output=None): + def __init__( + self, + pretty=True, + yes=False, + input_history_file=None, + chat_history_file=None, + input=None, + output=None, + ): self.input = input self.output = output self.pretty = pretty @@ -71,7 +86,7 @@ class InputOutput: current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S") self.append_chat_history(f"\n# aider chat started at {current_time}\n\n") - def get_input(self, root, rel_fnames, commands): + def get_input(self, root, rel_fnames, addable_rel_fnames, commands): if self.pretty: self.console.rule() else: @@ -89,7 +104,9 @@ class InputOutput: style = Style.from_dict({"": "green"}) while True: - completer_instance = FileContentCompleter(root, rel_fnames, commands) + completer_instance = FileContentCompleter( + root, rel_fnames, addable_rel_fnames, commands + ) if multiline_input: show = ". "