diff --git a/aider/linter.py b/aider/linter.py index 5506f30df..8fc19a79b 100644 --- a/aider/linter.py +++ b/aider/linter.py @@ -20,11 +20,24 @@ def parse_file_for_errors(file_path): tree = parser.parse(bytes(content, "utf8")) - # Traverse the tree to find errors + # Traverse the tree to find errors and print context def traverse_tree(node): if node.type == 'ERROR' or node.is_missing: error_type = 'Syntax error' if node.type == 'ERROR' else 'Missing element' - print(f"{error_type} at line: {node.start_point[0] + 1}") + start_line = max(0, node.start_point[0] - 3) + end_line = node.end_point[0] + 3 + error_line = node.start_point[0] + 1 + + with open(file_path, 'r') as file: + lines = file.readlines() + + print(f"{error_type} at line: {error_line}") + print("Context:") + for i in range(start_line, min(end_line, len(lines))): + line_number = i + 1 + prefix = ">> " if line_number == error_line else " " + print(f"{prefix}{line_number}: {lines[i].rstrip()}") + print("\n") for child in node.children: traverse_tree(child)