mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 14:55:00 +00:00
add a trailing newline when replacing
This commit is contained in:
parent
2de786a651
commit
1c9bef484d
1 changed files with 6 additions and 6 deletions
12
utils.py
12
utils.py
|
@ -3,10 +3,10 @@ import math
|
||||||
from difflib import SequenceMatcher
|
from difflib import SequenceMatcher
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
#from dump import dump
|
# from dump import dump
|
||||||
|
|
||||||
|
|
||||||
def replace_most_similar_chunk(whole, part, replace):
|
def replace_most_similar_chunk(whole, part, replace):
|
||||||
|
|
||||||
similarity_thresh = 0.8
|
similarity_thresh = 0.8
|
||||||
|
|
||||||
max_similarity = 0
|
max_similarity = 0
|
||||||
|
@ -41,7 +41,7 @@ def replace_most_similar_chunk(whole, part, replace):
|
||||||
+ replace_lines
|
+ replace_lines
|
||||||
+ whole_lines[most_similar_chunk_end:]
|
+ whole_lines[most_similar_chunk_end:]
|
||||||
)
|
)
|
||||||
modified_whole = "\n".join(modified_whole)
|
modified_whole = "\n".join(modified_whole) + "\n"
|
||||||
return modified_whole
|
return modified_whole
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,6 +81,8 @@ def strip_quoted_wrapping(res, fname=None):
|
||||||
res += "\n"
|
res += "\n"
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
def do_replace(fname, before_text, after_text):
|
def do_replace(fname, before_text, after_text):
|
||||||
before_text = strip_quoted_wrapping(before_text, fname)
|
before_text = strip_quoted_wrapping(before_text, fname)
|
||||||
after_text = strip_quoted_wrapping(after_text, fname)
|
after_text = strip_quoted_wrapping(after_text, fname)
|
||||||
|
@ -99,9 +101,7 @@ def do_replace(fname, before_text, after_text):
|
||||||
# first populating an empty file
|
# first populating an empty file
|
||||||
new_content = after_text
|
new_content = after_text
|
||||||
else:
|
else:
|
||||||
new_content = replace_most_similar_chunk(
|
new_content = replace_most_similar_chunk(content, before_text, after_text)
|
||||||
content, before_text, after_text
|
|
||||||
)
|
|
||||||
if not new_content:
|
if not new_content:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue