mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-28 00:05:01 +00:00
Move strip_quoted_wrapping
function from coder.py
to utils.py
and update its usage in coder.py
.
# Context: USER: move strip_quoted_wrapping into utils ASSISTANT: To move the `strip_quoted_wrapping` function from `coder.py` to `utils.py`, you need to make the following changes: In `coder.py`, remove the `strip_quoted_wrapping` function: ```python coder.py <<<<<<< ORIGINAL def strip_quoted_wrapping(self, res, fname=None): if not res: return res res = res.splitlines() if fname and res[0].strip().endswith(Path(fname).name): res = res[1:] if res[0].startswith("```") and res[-1].startswith("```"): res = res[1:-1] res = "\n".join(res) if res and res[-1] != "\n": res += "\n" return res ======= >>>>>>> UPDATED ``` In `utils.py`, add the `strip_quoted_wrapping` function: ```python utils.py <<<<<<< ORIGINAL ======= def strip_quoted_wrapping(res, fname=None): if not res: return res res = res.splitlines() if fname and res[0].strip().endswith(Path(fname).name): res = res[1:] if res[0].startswith("```") and res[-1].startswith("```"): res = res[1:-1] res = "\n".join(res) if res and res[-1] != "\n": res += "\n" return res >>>>>>> UPDATED ``` Finally, update the usage of `strip_quoted_wrapping` in `coder.py` to use the function from `utils.py`: ```python coder.py <<<<<<< ORIGINAL before_text = self.strip_quoted_wrapping(before_text, fname) after_text = self.strip_quoted_wrapping(after_text, fname) ======= before_text = utils.strip_quoted_wrapping(before_text, fname) after_text = utils.strip_quoted_wrapping(after_text, fname) >>>>>>> UPDATED ```
This commit is contained in:
parent
a232adb43e
commit
05c39b7329
1 changed files with 3 additions and 22 deletions
25
coder.py
25
coder.py
|
@ -407,9 +407,8 @@ class Coder:
|
||||||
return edited
|
return edited
|
||||||
|
|
||||||
def do_replace(self, fname, before_text, after_text):
|
def do_replace(self, fname, before_text, after_text):
|
||||||
before_text = self.strip_quoted_wrapping(before_text, fname)
|
before_text = utils.strip_quoted_wrapping(before_text, fname)
|
||||||
after_text = self.strip_quoted_wrapping(after_text, fname)
|
after_text = utils.strip_quoted_wrapping(after_text, fname)
|
||||||
|
|
||||||
fname = Path(fname)
|
fname = Path(fname)
|
||||||
|
|
||||||
# does it want to make a new file?
|
# does it want to make a new file?
|
||||||
|
@ -432,24 +431,6 @@ class Coder:
|
||||||
self.console.print(f"[red]Applied edit to {fname}")
|
self.console.print(f"[red]Applied edit to {fname}")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def strip_quoted_wrapping(self, res, fname=None):
|
|
||||||
if not res:
|
|
||||||
return res
|
|
||||||
|
|
||||||
res = res.splitlines()
|
|
||||||
|
|
||||||
if fname and res[0].strip().endswith(Path(fname).name):
|
|
||||||
res = res[1:]
|
|
||||||
|
|
||||||
if res[0].startswith("```") and res[-1].startswith("```"):
|
|
||||||
res = res[1:-1]
|
|
||||||
|
|
||||||
res = "\n".join(res)
|
|
||||||
if res and res[-1] != "\n":
|
|
||||||
res += "\n"
|
|
||||||
|
|
||||||
return res
|
|
||||||
|
|
||||||
def commit(self, history=None, prefix=None, ask=False):
|
def commit(self, history=None, prefix=None, ask=False):
|
||||||
repo = self.repo
|
repo = self.repo
|
||||||
if not repo:
|
if not repo:
|
||||||
|
@ -611,4 +592,4 @@ def main():
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
status = main()
|
status = main()
|
||||||
sys.exit(status)
|
sys.exit(status)
|
Loading…
Add table
Add a link
Reference in a new issue