mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 22:34:59 +00:00
added lint reflection
This commit is contained in:
parent
fe65b7d11f
commit
4b0c38254e
2 changed files with 27 additions and 2 deletions
|
@ -20,6 +20,7 @@ from aider import __version__, models, prompts, utils
|
||||||
from aider.commands import Commands
|
from aider.commands import Commands
|
||||||
from aider.history import ChatSummary
|
from aider.history import ChatSummary
|
||||||
from aider.io import InputOutput
|
from aider.io import InputOutput
|
||||||
|
from aider.linter import Linter
|
||||||
from aider.litellm import litellm
|
from aider.litellm import litellm
|
||||||
from aider.mdstream import MarkdownStream
|
from aider.mdstream import MarkdownStream
|
||||||
from aider.repo import GitRepo
|
from aider.repo import GitRepo
|
||||||
|
@ -287,6 +288,8 @@ class Coder:
|
||||||
self.verbose,
|
self.verbose,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.linter = Linter(root=self.root, encoding=io.encoding)
|
||||||
|
|
||||||
if max_chat_history_tokens is None:
|
if max_chat_history_tokens is None:
|
||||||
max_chat_history_tokens = self.main_model.max_chat_history_tokens
|
max_chat_history_tokens = self.main_model.max_chat_history_tokens
|
||||||
self.summarizer = ChatSummary(
|
self.summarizer = ChatSummary(
|
||||||
|
@ -721,8 +724,16 @@ class Coder:
|
||||||
|
|
||||||
edited, edit_error = self.apply_updates()
|
edited, edit_error = self.apply_updates()
|
||||||
if edit_error:
|
if edit_error:
|
||||||
self.update_cur_messages(set())
|
|
||||||
self.reflected_message = edit_error
|
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)
|
self.update_cur_messages(edited)
|
||||||
|
|
||||||
|
@ -744,6 +755,20 @@ class Coder:
|
||||||
else:
|
else:
|
||||||
self.reflected_message = add_rel_files_message
|
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):
|
def update_cur_messages(self, edited):
|
||||||
if self.partial_response_content:
|
if self.partial_response_content:
|
||||||
self.cur_messages += [dict(role="assistant", content=self.partial_response_content)]
|
self.cur_messages += [dict(role="assistant", content=self.partial_response_content)]
|
||||||
|
|
|
@ -89,7 +89,7 @@ def basic_lint(fname, code):
|
||||||
)
|
)
|
||||||
context.add_lines_of_interest(errors)
|
context.add_lines_of_interest(errors)
|
||||||
context.add_context()
|
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 += fname + ":\n"
|
||||||
output += context.format()
|
output += context.format()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue