mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-06 12:45:00 +00:00
works
This commit is contained in:
parent
b600e17910
commit
86facafd09
1 changed files with 26 additions and 19 deletions
|
@ -1,19 +1,21 @@
|
||||||
import os
|
import os
|
||||||
import traceback
|
import py_compile # noqa: F401
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import traceback
|
||||||
import warnings
|
import warnings
|
||||||
import py_compile
|
import traceback
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from aider.dump import dump
|
from pathlib import Path
|
||||||
|
|
||||||
from grep_ast import TreeContext, filename_to_lang
|
from grep_ast import TreeContext, filename_to_lang
|
||||||
|
|
||||||
|
from aider.dump import dump # noqa: F401
|
||||||
|
|
||||||
# tree_sitter is throwing a FutureWarning
|
# tree_sitter is throwing a FutureWarning
|
||||||
warnings.simplefilter("ignore", category=FutureWarning)
|
warnings.simplefilter("ignore", category=FutureWarning)
|
||||||
|
|
||||||
from tree_sitter_languages import get_parser # noqa: E402
|
from tree_sitter_languages import get_parser # noqa: E402
|
||||||
import traceback
|
|
||||||
|
|
||||||
|
|
||||||
class Linter:
|
class Linter:
|
||||||
|
@ -69,30 +71,34 @@ class Linter:
|
||||||
if res:
|
if res:
|
||||||
return res
|
return res
|
||||||
|
|
||||||
return lint_pycompile(fname, code)
|
return lint_python_compile(fname, code)
|
||||||
|
|
||||||
def lint_pycompile(fname, code):
|
|
||||||
|
def lint_python_compile(fname, code):
|
||||||
try:
|
try:
|
||||||
# py_compile.compile(fname, doraise=True)
|
compile(code, fname, "exec") # USE TRACEBACK BELOW HERE
|
||||||
compile(code, fname, 'exec')
|
|
||||||
return
|
return
|
||||||
except ValueError as err:
|
except Exception as err:
|
||||||
dump(dir(err))
|
|
||||||
dump(err.text)
|
|
||||||
res = f"{type(err).__name__}: {err}\n"
|
|
||||||
line_numbers = list(range(err.lineno - 1, err.end_lineno))
|
line_numbers = list(range(err.lineno - 1, err.end_lineno))
|
||||||
|
|
||||||
dump(line_numbers)
|
tb_lines = traceback.format_exception(type(err), err, err.__traceback__)
|
||||||
|
last_file_i = 0
|
||||||
|
|
||||||
# Print out the Traceback, but only the last call stack
|
target = "# USE TRACEBACK"
|
||||||
tb_lines = traceback.format_exception(type(err), err, err.__traceback__)
|
target += " BELOW HERE"
|
||||||
last_call_stack = ''.join(tb_lines[-2:])
|
for i in range(len(tb_lines)):
|
||||||
res += last_call_stack
|
if target in tb_lines[i]:
|
||||||
|
last_file_i = i
|
||||||
|
break
|
||||||
|
|
||||||
res += '\n'
|
tb_lines = tb_lines[:1] + tb_lines[last_file_i + 1 :]
|
||||||
|
|
||||||
|
res = "".join(tb_lines)
|
||||||
|
res += "\n"
|
||||||
res += tree_context(fname, code, line_numbers)
|
res += tree_context(fname, code, line_numbers)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
def basic_lint(fname, code):
|
def basic_lint(fname, code):
|
||||||
"""
|
"""
|
||||||
Use tree-sitter to look for syntax errors, display them with tree context.
|
Use tree-sitter to look for syntax errors, display them with tree context.
|
||||||
|
@ -111,6 +117,7 @@ def basic_lint(fname, code):
|
||||||
|
|
||||||
return tree_context(fname, code, errors)
|
return tree_context(fname, code, errors)
|
||||||
|
|
||||||
|
|
||||||
def tree_context(fname, code, line_nums):
|
def tree_context(fname, code, line_nums):
|
||||||
context = TreeContext(
|
context = TreeContext(
|
||||||
fname,
|
fname,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue