From 598ae7b6b9cf1ee870ba488d37c878e34be54af0 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Fri, 9 Aug 2024 16:08:46 -0300 Subject: [PATCH] feat: Add /read command to load files from anywhere --- aider/coders/base_coder.py | 1 + aider/commands.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index c5e91fa09..d7e2bcc18 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -50,6 +50,7 @@ def wrap_fence(name): class Coder: abs_fnames = None + abs_read_only_fnames = None repo = None last_aider_commit_hash = None aider_edited_files = None diff --git a/aider/commands.py b/aider/commands.py index 4c0421a0b..d498e1002 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -936,6 +936,36 @@ class Commands: except Exception as e: self.io.tool_error(f"Error processing clipboard content: {e}") + def cmd_read(self, args): + "Load a file from anywhere and add it to abs_read_only_fnames" + if not args.strip(): + self.io.tool_error("Please provide a filename to read.") + return + + filename = args.strip() + abs_path = os.path.abspath(filename) + + if not os.path.exists(abs_path): + self.io.tool_error(f"File not found: {abs_path}") + return + + if not os.path.isfile(abs_path): + self.io.tool_error(f"Not a file: {abs_path}") + return + + if not self.coder.abs_read_only_fnames: + self.coder.abs_read_only_fnames = set() + + self.coder.abs_read_only_fnames.add(abs_path) + self.io.tool_output(f"Added {abs_path} to read-only files.") + + content = self.io.read_text(abs_path) + if content is not None: + self.io.tool_output(f"Contents of {filename}:") + self.io.tool_output(content) + else: + self.io.tool_error(f"Unable to read {filename}") + def cmd_map(self, args): "Print out the current repository map" repo_map = self.coder.get_repo_map() @@ -980,3 +1010,6 @@ def main(): if __name__ == "__main__": status = main() sys.exit(status) + +def completions_read(self): + return [] # No auto-completion for now, as it would require listing all files on the system