refactor: add dry run mode to apply_edits method

This commit is contained in:
Paul Gauthier 2024-10-29 14:28:38 -07:00 committed by Paul Gauthier (aider)
parent 3ccae4eff7
commit 28d9f6f8da

View file

@ -35,9 +35,13 @@ class EditBlockCoder(Coder):
return edits
def apply_edits(self, edits):
def apply_edits_dry_run(self, edits):
return self.apply_edits(edits, dry_run=True)
def apply_edits(self, edits, dry_run=False):
failed = []
passed = []
updated = []
for edit in edits:
path, original, updated = edit
@ -52,14 +56,21 @@ class EditBlockCoder(Coder):
if new_content:
break
# ai: update full_path->path!
updated.append((path, original, updated))
if new_content:
if not dry_run:
self.io.write_text(full_path, new_content)
passed.append(edit)
else:
failed.append(edit)
if dry_run:
return updated
if not failed:
return passed
return
blocks = "block" if len(failed) == 1 else "blocks"