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.
This commit is contained in:
Paul Gauthier 2023-06-25 20:38:46 -07:00
parent ef88cc6d55
commit e5ad9d501f

View file

@ -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