mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 06:15:00 +00:00
WIP: Refactor do_replace method to utils module and update references in coder module.
This commit is contained in:
parent
11a5379d61
commit
fb12b73975
2 changed files with 30 additions and 31 deletions
34
coder.py
34
coder.py
|
@ -377,41 +377,13 @@ class Coder:
|
|||
self.fnames[path] = 0
|
||||
|
||||
edited.add(path)
|
||||
if self.do_replace(path, original, updated):
|
||||
self.console.print(f"[red]Applied edit to {fname}")
|
||||
if utils.do_replace(path, original, updated):
|
||||
self.console.print(f"[red]Applied edit to {path}")
|
||||
else:
|
||||
self.console.print(f"[red]Failed to apply edit to {fname}")
|
||||
self.console.print(f"[red]Failed to apply edit to {path}")
|
||||
|
||||
return edited
|
||||
|
||||
def do_replace(self, fname, before_text, after_text):
|
||||
before_text = utils.strip_quoted_wrapping(before_text, fname)
|
||||
after_text = utils.strip_quoted_wrapping(after_text, fname)
|
||||
fname = Path(fname)
|
||||
|
||||
# does it want to make a new file?
|
||||
if not fname.exists() and not before_text.strip():
|
||||
print("Creating empty file:", fname)
|
||||
fname.touch()
|
||||
|
||||
content = fname.read_text()
|
||||
|
||||
if not before_text.strip():
|
||||
if content:
|
||||
new_content = content + after_text
|
||||
else:
|
||||
# first populating an empty file
|
||||
new_content = after_text
|
||||
else:
|
||||
new_content = utils.replace_most_similar_chunk(
|
||||
content, before_text, after_text
|
||||
)
|
||||
if not new_content:
|
||||
return
|
||||
|
||||
fname.write_text(new_content)
|
||||
return True
|
||||
|
||||
def commit(self, history=None, prefix=None, ask=False):
|
||||
repo = self.repo
|
||||
if not repo:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue