mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 06:44:59 +00:00
refactor to use io.read_text
This commit is contained in:
parent
5f9947a727
commit
9cab570f87
2 changed files with 19 additions and 22 deletions
|
@ -287,10 +287,20 @@ class Coder:
|
||||||
]
|
]
|
||||||
fence = fences[0]
|
fence = fences[0]
|
||||||
|
|
||||||
|
def get_abs_fnames_content(self):
|
||||||
|
for fname in list(self.abs_fnames):
|
||||||
|
content = self.io.read_text(fname)
|
||||||
|
if content is None:
|
||||||
|
relative_fname = self.get_rel_fname(fname)
|
||||||
|
self.tool_error(f"Dropping {relative_fname} from the chat.")
|
||||||
|
self.abs_fnames.remove(fname)
|
||||||
|
else:
|
||||||
|
yield fname, content
|
||||||
|
|
||||||
def choose_fence(self):
|
def choose_fence(self):
|
||||||
all_content = ""
|
all_content = ""
|
||||||
for fname in self.abs_fnames:
|
for _fname, content in self.get_abs_fnames_content():
|
||||||
all_content += Path(fname).read_text() + "\n"
|
all_content += content + "\n"
|
||||||
|
|
||||||
all_content = all_content.splitlines()
|
all_content = all_content.splitlines()
|
||||||
|
|
||||||
|
@ -317,9 +327,14 @@ class Coder:
|
||||||
fnames = self.abs_fnames
|
fnames = self.abs_fnames
|
||||||
|
|
||||||
prompt = ""
|
prompt = ""
|
||||||
for fname in fnames:
|
for fname, content in self.get_abs_fnames_content():
|
||||||
relative_fname = self.get_rel_fname(fname)
|
relative_fname = self.get_rel_fname(fname)
|
||||||
prompt += utils.quoted_file(fname, relative_fname, fence=self.fence)
|
prompt = "\n"
|
||||||
|
prompt += relative_fname
|
||||||
|
prompt += f"\n{self.fence[0]}\n"
|
||||||
|
prompt += content
|
||||||
|
prompt += f"{self.fence[1]}\n"
|
||||||
|
|
||||||
return prompt
|
return prompt
|
||||||
|
|
||||||
def recheck_abs_fnames(self):
|
def recheck_abs_fnames(self):
|
||||||
|
|
|
@ -1,24 +1,6 @@
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from .dump import dump # noqa: F401
|
from .dump import dump # noqa: F401
|
||||||
|
|
||||||
|
|
||||||
def quoted_file(fname, display_fname, fence=("```", "```"), number=False):
|
|
||||||
prompt = "\n"
|
|
||||||
prompt += display_fname
|
|
||||||
prompt += f"\n{fence[0]}\n"
|
|
||||||
|
|
||||||
file_content = Path(fname).read_text()
|
|
||||||
lines = file_content.splitlines()
|
|
||||||
for i, line in enumerate(lines, start=1):
|
|
||||||
if number:
|
|
||||||
prompt += f"{i:4d} "
|
|
||||||
prompt += line + "\n"
|
|
||||||
|
|
||||||
prompt += f"{fence[1]}\n"
|
|
||||||
return prompt
|
|
||||||
|
|
||||||
|
|
||||||
def show_messages(messages, title=None, functions=None):
|
def show_messages(messages, title=None, functions=None):
|
||||||
if title:
|
if title:
|
||||||
print(title.upper(), "*" * 50)
|
print(title.upper(), "*" * 50)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue