mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-07 13:15:00 +00:00
feat: add error handling for TreeContext with fallback to raw comments
This commit is contained in:
parent
a96d87814b
commit
fd301c519d
1 changed files with 21 additions and 4 deletions
|
@ -195,10 +195,27 @@ Be sure to remove all these "AI" comments from the code!
|
||||||
# Convert comment line numbers to line indices (0-based)
|
# Convert comment line numbers to line indices (0-based)
|
||||||
lois = [ln - 1 for ln, _ in zip(line_nums, comments) if ln > 0]
|
lois = [ln - 1 for ln, _ in zip(line_nums, comments) if ln > 0]
|
||||||
|
|
||||||
# Handle ValueError from TreeContext and just include the actual comments instead. ai!
|
try:
|
||||||
context = TreeContext(
|
context = TreeContext(
|
||||||
rel_fname,
|
rel_fname,
|
||||||
code,
|
code,
|
||||||
|
color=False,
|
||||||
|
line_number=False,
|
||||||
|
child_context=False,
|
||||||
|
last_line=False,
|
||||||
|
margin=0,
|
||||||
|
mark_lois=True,
|
||||||
|
loi_pad=3,
|
||||||
|
show_top_of_file_parent_scope=False,
|
||||||
|
)
|
||||||
|
context.lines_of_interest = set()
|
||||||
|
context.add_lines_of_interest(lois)
|
||||||
|
context.add_context()
|
||||||
|
res += context.format()
|
||||||
|
except ValueError:
|
||||||
|
# Fall back to just showing the comments if TreeContext fails
|
||||||
|
for ln, comment in zip(line_nums, comments):
|
||||||
|
res += f" Line {ln}: {comment}\n"
|
||||||
color=False,
|
color=False,
|
||||||
line_number=False,
|
line_number=False,
|
||||||
child_context=False,
|
child_context=False,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue