From 487040203eafe3fdc405c1fe3c55dabb59d71678 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 27 May 2023 08:46:06 -0700 Subject: [PATCH] aider: Updated get_input to take a root param and receive rel_fnames not abs fnames, and updated FileContentCompleter to work with them. # Context: USER: change get_input to take a root param and receive rel_fnames not abs fnames. don't compute short_fnames, just use rel_fnames. also update FileContentCompleter to take root and rel_fnames and work with them. ASSISTANT: To make the requested changes, I need you to provide me with *read-write* access to the following files: 1. `aider/io.py` 2. `aider/prompts.py` Once you've granted me access to these files, I can provide you with the necessary code modifications. USER: I added these *read-write* files: aider/io.py ASSISTANT: Great! I will now make the changes to the `get_input` function and the `FileContentCompleter` class in the `aider/io.py` file. ```python aider/io.py <<<<<<< ORIGINAL class FileContentCompleter(Completer): def __init__(self, fnames, commands): self.commands = commands self.words = set() for fname in fnames: with open(fname, "r") as f: content = f.read() ======= class FileContentCompleter(Completer): def __init__(self, root, rel_fnames, commands): self.commands = commands self.words = set() for rel_fname in rel_fnames: fname = os.path.join(root, rel_fname) with open(fname, "r") as f: content = f.read() >>>>>>> UPDATED ```python aider/io.py <<<<<<< ORIGINAL def get_input(self, fnames, commands): if self.pretty: self.console.rule() else: print() fnames = list(fnames) if len(fnames) > 1: common_prefix = os.path.commonpath(fnames) if not common_prefix.endswith(os.path.sep): common_prefix += os.path.sep short_fnames = [fname.replace(common_prefix, "", 1) for fname in fnames] elif len(fnames): short_fnames = [os.path.basename(fnames[0])] else: short_fnames = [] show = " ".join(short_fnames) ======= def get_input(self, root, rel_fnames, commands): if self.pretty: self.console.rule() else: print() rel_fnames = list(rel_fnames) show = " ".join(rel_fnames) >>>>>>> UPDATED ```python aider/io.py <<<<<<< ORIGINAL completer_instance = FileContentCompleter(fnames, commands) ======= completer_instance = FileContentCompleter(root, rel_fnames, commands) >>>>>>> UPDATED ``` These changes will update the `get_input` function to take a `root` parameter and receive `rel_fnames` instead of absolute file names. The `FileContentCompleter` class is also updated to take the `root` and `rel_fnames` parameters and work with them. --- aider/io.py | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/aider/io.py b/aider/io.py index bfbef3bbc..1457e92be 100644 --- a/aider/io.py +++ b/aider/io.py @@ -14,11 +14,12 @@ from datetime import datetime class FileContentCompleter(Completer): - def __init__(self, fnames, commands): + def __init__(self, root, rel_fnames, commands): self.commands = commands self.words = set() - for fname in fnames: + for rel_fname in rel_fnames: + fname = os.path.join(root, rel_fname) with open(fname, "r") as f: content = f.read() try: @@ -70,24 +71,14 @@ 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, fnames, commands): + def get_input(self, root, rel_fnames, commands): if self.pretty: self.console.rule() else: print() - fnames = list(fnames) - if len(fnames) > 1: - common_prefix = os.path.commonpath(fnames) - if not common_prefix.endswith(os.path.sep): - common_prefix += os.path.sep - short_fnames = [fname.replace(common_prefix, "", 1) for fname in fnames] - elif len(fnames): - short_fnames = [os.path.basename(fnames[0])] - else: - short_fnames = [] - - show = " ".join(short_fnames) + rel_fnames = list(rel_fnames) + show = " ".join(rel_fnames) if len(show) > 10: show += "\n" show += "> " @@ -98,7 +89,7 @@ class InputOutput: style = Style.from_dict({"": "green"}) while True: - completer_instance = FileContentCompleter(fnames, commands) + completer_instance = FileContentCompleter(root, rel_fnames, commands) if multiline_input: show = ". "