mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-04 03:35:00 +00:00
noop
This commit is contained in:
parent
8456caae1d
commit
a6c2841342
1 changed files with 29 additions and 27 deletions
|
@ -45,6 +45,35 @@ The ORIGINAL block needs to be EXACTLY the same as the lines in {path} with noth
|
||||||
return edited
|
return edited
|
||||||
|
|
||||||
|
|
||||||
|
def replace_most_similar_chunk(whole, part, replace):
|
||||||
|
"""Best efforts to find the `part` lines in `whole` and replace them with `replace`"""
|
||||||
|
|
||||||
|
whole_lines = whole.splitlines(keepends=True)
|
||||||
|
part_lines = part.splitlines(keepends=True)
|
||||||
|
replace_lines = replace.splitlines(keepends=True)
|
||||||
|
|
||||||
|
# Try for a perfect match
|
||||||
|
if part_lines in whole_lines:
|
||||||
|
updated_lines = whole_lines.replace(part_lines, replace_lines)
|
||||||
|
return updated_lines
|
||||||
|
|
||||||
|
# Try being flexible about leading whitespace
|
||||||
|
res = replace_part_with_missing_leading_whitespace(whole_lines, part_lines, replace_lines)
|
||||||
|
if res:
|
||||||
|
return res
|
||||||
|
|
||||||
|
# Try to handle when it elides code with ...
|
||||||
|
try:
|
||||||
|
res = try_dotdotdots(whole, part, replace)
|
||||||
|
if res:
|
||||||
|
return res
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Try fuzzy matching
|
||||||
|
return replace_closest_edit_distance(whole_lines, part, part_lines, replace_lines)
|
||||||
|
|
||||||
|
|
||||||
def try_dotdotdots(whole, part, replace):
|
def try_dotdotdots(whole, part, replace):
|
||||||
"""
|
"""
|
||||||
See if the edit block has ... lines.
|
See if the edit block has ... lines.
|
||||||
|
@ -146,33 +175,6 @@ def replace_part_with_missing_leading_whitespace(whole_lines, part_lines, replac
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def replace_most_similar_chunk(whole, part, replace):
|
|
||||||
whole_lines = whole.splitlines(keepends=True)
|
|
||||||
part_lines = part.splitlines(keepends=True)
|
|
||||||
replace_lines = replace.splitlines(keepends=True)
|
|
||||||
|
|
||||||
# Try for a perfect match
|
|
||||||
if part_lines in whole_lines:
|
|
||||||
updated_lines = whole_lines.replace(part_lines, replace_lines)
|
|
||||||
return updated_lines
|
|
||||||
|
|
||||||
# Try being flexible about leading whitespace
|
|
||||||
res = replace_part_with_missing_leading_whitespace(whole_lines, part_lines, replace_lines)
|
|
||||||
if res:
|
|
||||||
return res
|
|
||||||
|
|
||||||
# Try to handle when it elides code with ...
|
|
||||||
try:
|
|
||||||
res = try_dotdotdots(whole, part, replace)
|
|
||||||
if res:
|
|
||||||
return res
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Try fuzzy matching
|
|
||||||
return replace_closest_edit_distance(whole_lines, part, part_lines, replace_lines)
|
|
||||||
|
|
||||||
|
|
||||||
def replace_closest_edit_distance(whole_lines, part, part_lines, replace_lines):
|
def replace_closest_edit_distance(whole_lines, part, part_lines, replace_lines):
|
||||||
similarity_thresh = 0.8
|
similarity_thresh = 0.8
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue