From 552bdc4f71031b8c18ac62c6a5fbccd852652884 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 7 Jul 2023 11:58:27 -0700 Subject: [PATCH] handle diff output for new file --- aider/coders/wholefile_coder.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/aider/coders/wholefile_coder.py b/aider/coders/wholefile_coder.py index 3439797bb..61c064037 100644 --- a/aider/coders/wholefile_coder.py +++ b/aider/coders/wholefile_coder.py @@ -55,15 +55,18 @@ class WholeFileCoder(Coder): full_path = (Path(self.root) / fname).absolute() - if mode == "diff" and full_path.exists(): - orig_lines = self.io.read_text(full_path).splitlines(keepends=True) + if mode == "diff": + if full_path.exists(): + orig_lines = self.io.read_text(full_path).splitlines(keepends=True) - show_diff = diffs.diff_partial_update( - orig_lines, - new_lines, - final=True, - ).splitlines() - output += show_diff + show_diff = diffs.diff_partial_update( + orig_lines, + new_lines, + final=True, + ).splitlines() + output += show_diff + else: + output += ["```"] + new_lines + ["```"] else: if self.allowed_to_edit(fname): edited.add(fname) @@ -110,7 +113,7 @@ class WholeFileCoder(Coder): # ending an existing block full_path = (Path(self.root) / fname).absolute() - if mode == "diff" and full_path.exists(): + if full_path.exists(): orig_lines = self.io.read_text(full_path).splitlines(keepends=True) show_diff = diffs.diff_partial_update( @@ -118,6 +121,8 @@ class WholeFileCoder(Coder): new_lines, ).splitlines() output += show_diff + else: + output += ["```"] + new_lines + ["```"] return "\n".join(output)