From 4b0c38254e9e7a8c29d6e58b52a7f9c122f89015 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 17 May 2024 16:58:04 -0700 Subject: [PATCH] added lint reflection --- aider/coders/base_coder.py | 27 ++++++++++++++++++++++++++- aider/linter.py | 2 +- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 565da3c2e..e7c4f9860 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -20,6 +20,7 @@ from aider import __version__, models, prompts, utils from aider.commands import Commands from aider.history import ChatSummary from aider.io import InputOutput +from aider.linter import Linter from aider.litellm import litellm from aider.mdstream import MarkdownStream from aider.repo import GitRepo @@ -287,6 +288,8 @@ class Coder: self.verbose, ) + self.linter = Linter(root=self.root, encoding=io.encoding) + if max_chat_history_tokens is None: max_chat_history_tokens = self.main_model.max_chat_history_tokens self.summarizer = ChatSummary( @@ -721,8 +724,16 @@ class Coder: edited, edit_error = self.apply_updates() if edit_error: - self.update_cur_messages(set()) self.reflected_message = edit_error + self.update_cur_messages(set()) + return + + if edited: + lint_errors = self.lint_edited(edited) + if lint_errors: + self.reflected_message = lint_errors + self.update_cur_messages(set()) + return self.update_cur_messages(edited) @@ -744,6 +755,20 @@ class Coder: else: self.reflected_message = add_rel_files_message + def lint_edited(self, fnames): + res = "" + for fname in fnames: + errors = self.linter.lint(fname) + if errors: + res += "\n" + res += errors + res += "\n" + + if res: + self.io.tool_error(res) + + return res + def update_cur_messages(self, edited): if self.partial_response_content: self.cur_messages += [dict(role="assistant", content=self.partial_response_content)] diff --git a/aider/linter.py b/aider/linter.py index 8523e5563..75cb1d17c 100644 --- a/aider/linter.py +++ b/aider/linter.py @@ -89,7 +89,7 @@ def basic_lint(fname, code): ) context.add_lines_of_interest(errors) context.add_context() - output = "# Syntax Errors found on the lines marked with █\n" + output = "# Syntax Errors found on the lines marked with █\n\n" output += fname + ":\n" output += context.format()