mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-06 20:54:59 +00:00
wip
This commit is contained in:
parent
c24c9d33a5
commit
c7358c96b9
2 changed files with 20 additions and 1 deletions
|
@ -3,6 +3,7 @@ import re
|
||||||
from difflib import SequenceMatcher
|
from difflib import SequenceMatcher
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from ..dump import dump # noqa: F401
|
||||||
from .base_coder import Coder
|
from .base_coder import Coder
|
||||||
from .editblock_prompts import EditBlockPrompts
|
from .editblock_prompts import EditBlockPrompts
|
||||||
|
|
||||||
|
@ -102,10 +103,27 @@ def replace_part_with_missing_leading_whitespace(whole, part, replace):
|
||||||
part_lines = part.splitlines()
|
part_lines = part.splitlines()
|
||||||
replace_lines = replace.splitlines()
|
replace_lines = replace.splitlines()
|
||||||
|
|
||||||
|
dump(repr(part), repr(replace))
|
||||||
|
|
||||||
|
# GPT often messes up leading whitespace.
|
||||||
|
# It usually does it uniformly across the ORIG and UPD blocks.
|
||||||
|
# Either omitting all leading whitespace, or including only some of it.
|
||||||
|
|
||||||
|
leading = [len(p) - len(p.lstrip()) for p in part_lines if p.strip()] + [
|
||||||
|
len(p) - len(p.lstrip()) for p in replace_lines if p.strip()
|
||||||
|
]
|
||||||
|
|
||||||
|
# Outdent everything in part and replace by the max fixed amount possible
|
||||||
|
if leading and min(leading):
|
||||||
|
leading = min(leading)
|
||||||
|
part_lines = [p[leading:] if p.strip() else p for p in part_lines]
|
||||||
|
replace_lines = [p[leading:] if p.strip() else p for p in replace_lines]
|
||||||
|
|
||||||
# If all lines in the part start with whitespace, then honor it.
|
# If all lines in the part start with whitespace, then honor it.
|
||||||
# But GPT often outdents the part and replace blocks completely,
|
# But GPT often outdents the part and replace blocks completely,
|
||||||
# thereby discarding the actual leading whitespace in the file.
|
# thereby discarding the actual leading whitespace in the file.
|
||||||
if all((not pline or pline[0].isspace()) for pline in part_lines):
|
if all((not pline or pline[0].isspace()) for pline in part_lines):
|
||||||
|
print("bye")
|
||||||
return
|
return
|
||||||
|
|
||||||
for i in range(len(whole_lines) - len(part_lines) + 1):
|
for i in range(len(whole_lines) - len(part_lines) + 1):
|
||||||
|
|
|
@ -509,7 +509,8 @@ def main(argv=None, input=None, output=None, force_git_root=None):
|
||||||
content = io.read_text(args.apply)
|
content = io.read_text(args.apply)
|
||||||
if content is None:
|
if content is None:
|
||||||
return
|
return
|
||||||
coder.apply_updates(content)
|
coder.partial_response_content = content
|
||||||
|
coder.apply_updates()
|
||||||
return
|
return
|
||||||
|
|
||||||
io.tool_output("Use /help to see in-chat commands, run with --help to see cmd line args")
|
io.tool_output("Use /help to see in-chat commands, run with --help to see cmd line args")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue