refactor: Improve edit handling with dry run and path resolution

This commit is contained in:
Paul Gauthier 2024-10-29 14:31:12 -07:00 committed by Paul Gauthier (aider)
parent 5b6be29c1c
commit e1d55c82b1
2 changed files with 10 additions and 7 deletions

View file

@ -1811,12 +1811,11 @@ class Coder:
edited = set() edited = set()
try: try:
edits = self.get_edits() edits = self.get_edits()
edits = self.apply_edits_dry_run(edits)
edits = self.prepare_to_edit(edits) edits = self.prepare_to_edit(edits)
updated_edits = self.apply_edits(edits)
if updated_edits is not None:
edits = updated_edits
edited = set(edit[0] for edit in edits) edited = set(edit[0] for edit in edits)
self.apply_edits(edits)
except ValueError as err: except ValueError as err:
self.num_malformed_responses += 1 self.num_malformed_responses += 1
@ -1943,6 +1942,9 @@ class Coder:
def apply_edits(self, edits): def apply_edits(self, edits):
return return
def apply_edits_dry_run(self, edits):
return edits
def run_shell_commands(self): def run_shell_commands(self):
if not self.suggest_shell_commands: if not self.suggest_shell_commands:
return "" return ""

View file

@ -41,7 +41,7 @@ class EditBlockCoder(Coder):
def apply_edits(self, edits, dry_run=False): def apply_edits(self, edits, dry_run=False):
failed = [] failed = []
passed = [] passed = []
updated = [] updated_edits = []
for edit in edits: for edit in edits:
path, original, updated = edit path, original, updated = edit
@ -54,9 +54,10 @@ class EditBlockCoder(Coder):
content = self.io.read_text(full_path) content = self.io.read_text(full_path)
new_content = do_replace(full_path, content, original, updated, self.fence) new_content = do_replace(full_path, content, original, updated, self.fence)
if new_content: if new_content:
path = self.get_rel_fname(full_path)
break break
updated.append((path, original, updated)) updated_edits.append((path, original, updated))
if new_content: if new_content:
if not dry_run: if not dry_run:
@ -66,7 +67,7 @@ class EditBlockCoder(Coder):
failed.append(edit) failed.append(edit)
if dry_run: if dry_run:
return updated return updated_edits
if not failed: if not failed:
return return