mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 02:05:00 +00:00
feat: use TreeContext to show AI comments in file context
This commit is contained in:
parent
c4764fa4d8
commit
d1dd40590f
1 changed files with 33 additions and 5 deletions
|
@ -172,17 +172,45 @@ class FileWatcher:
|
||||||
if line_nums:
|
if line_nums:
|
||||||
ai_comments[fname] = comments
|
ai_comments[fname] = comments
|
||||||
|
|
||||||
# instead of just joining the comments, use TreeContext to render them in context of their files ai!
|
from grep_ast import TreeContext
|
||||||
res = "\n".join(
|
|
||||||
comment for comments in ai_comments.values() if comments for comment in comments
|
|
||||||
)
|
|
||||||
|
|
||||||
res = """The "ai" comments below can be found in the code files I've shared with you.
|
res = """The "ai" comments below can be found in the code files I've shared with you.
|
||||||
They contain your instructions.
|
They contain your instructions.
|
||||||
Make the requested changes.
|
Make the requested changes.
|
||||||
Be sure to remove all these "ai" comments from the code!
|
Be sure to remove all these "ai" comments from the code!
|
||||||
|
|
||||||
""" + res
|
"""
|
||||||
|
|
||||||
|
for fname, comments in ai_comments.items():
|
||||||
|
if not comments:
|
||||||
|
continue
|
||||||
|
|
||||||
|
code = self.io.read_text(fname)
|
||||||
|
if not code:
|
||||||
|
continue
|
||||||
|
|
||||||
|
rel_fname = self.coder.get_rel_fname(fname)
|
||||||
|
res += f"\n{rel_fname}:\n"
|
||||||
|
|
||||||
|
# Convert comment line numbers to line indices (0-based)
|
||||||
|
lois = [ln - 1 for ln, _ in zip(line_nums, comments) if ln > 0]
|
||||||
|
|
||||||
|
context = TreeContext(
|
||||||
|
rel_fname,
|
||||||
|
code,
|
||||||
|
color=False,
|
||||||
|
line_number=False,
|
||||||
|
child_context=False,
|
||||||
|
last_line=False,
|
||||||
|
margin=0,
|
||||||
|
mark_lois=False,
|
||||||
|
loi_pad=0,
|
||||||
|
show_top_of_file_parent_scope=False,
|
||||||
|
)
|
||||||
|
context.lines_of_interest = set()
|
||||||
|
context.add_lines_of_interest(lois)
|
||||||
|
context.add_context()
|
||||||
|
res += context.format()
|
||||||
|
|
||||||
dump(res)
|
dump(res)
|
||||||
return res
|
return res
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue