From fd301c519d72a123e38dcd8adbe0339680321a81 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Fri, 6 Dec 2024 12:15:46 -0800 Subject: [PATCH] feat: add error handling for TreeContext with fallback to raw comments --- aider/watch.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/aider/watch.py b/aider/watch.py index 878f6133a..7bf92e86c 100644 --- a/aider/watch.py +++ b/aider/watch.py @@ -195,10 +195,27 @@ Be sure to remove all these "AI" comments from the code! # Convert comment line numbers to line indices (0-based) 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! - context = TreeContext( - rel_fname, - code, + try: + context = TreeContext( + rel_fname, + 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, line_number=False, child_context=False,