From e5ad9d501faa8437f6e6bd8acd18d0a5f098852c Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 25 Jun 2023 20:38:46 -0700 Subject: [PATCH] aider: Added extra backticks to the start and end of the `show` variable to ensure proper formatting. # Context: USER: do the todo ASSISTANT: To complete the TODO task in the `diff_partial_update` function, I will find the longest string of backticks (`) that start a line in the `diff` variable. I will then add one more backtick to the start and end of the `show` variable to ensure proper formatting. Here are the changes: ```python aider/diffs.py <<<<<<< ORIGINAL for line in diff: pass diff = "".join(diff) if not diff.endswith("\n"): diff += "\n" show = "```diff\n" ======= max_backticks = max(len(line) - len(line.lstrip("`")) for line in diff.splitlines()) extra_backticks = "`" * (max_backticks + 1) diff = "".join(diff) if not diff.endswith("\n"): diff += "\n" show = f"{extra_backticks}diff\n" >>>>>>> UPDATED ``` ```python aider/diffs.py <<<<<<< ORIGINAL show += diff + "```\n\n" ======= show += diff + f"{extra_backticks}\n\n" >>>>>>> UPDATED ``` These changes will find the longest string of backticks at the start of a line in the `diff` variable and add one more backtick to the start and end of the `show` variable. --- aider/diffs.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/aider/diffs.py b/aider/diffs.py index 4608e8e18..0c4763c64 100644 --- a/aider/diffs.py +++ b/aider/diffs.py @@ -47,8 +47,8 @@ def diff_partial_update(lines_orig, lines_updated, final=False, fname=None): partially complete update. """ - # dump(lines_orig) - # dump(lines_updated) + dump(lines_orig) + dump(lines_updated) assert_newlines(lines_orig) assert_newlines(lines_orig) @@ -80,21 +80,26 @@ def diff_partial_update(lines_orig, lines_updated, final=False, fname=None): diff = list(diff)[2:] + # TODO find the longest string of ` that start a line + max_backticks = max(len(line) - len(line.lstrip("`")) for line in diff.splitlines()) + extra_backticks = "`" * (max_backticks + 1) + diff = "".join(diff) if not diff.endswith("\n"): diff += "\n" - show = "```diff\n" + show = f"{extra_backticks}diff\n" if fname: show += f"--- {fname} original\n" show += f"+++ {fname} updated\n" if not final: show += bar - show += diff + "```\n\n" + show += diff + f"{extra_backticks}\n\n" # print(diff) + dump(repr(show)) return show