diff --git a/aider/linter.py b/aider/linter.py index c02beb030..986a2a9a8 100644 --- a/aider/linter.py +++ b/aider/linter.py @@ -1,22 +1,24 @@ import os import tree_sitter +import sys +import warnings + +# tree_sitter is throwing a FutureWarning +warnings.simplefilter("ignore", category=FutureWarning) +from tree_sitter_languages import get_language, get_parser # noqa: E402 def parse_file_for_errors(file_path): - """ - Parses the given file using tree-sitter and prints out the line number of every syntax/parse error. - """ - # Load the language - Language = tree_sitter.Language - PARSER = tree_sitter.Parser() - LANGUAGE = Language(os.path.join('build', 'my-languages.so'), 'python') - PARSER.set_language(LANGUAGE) + + lang = "python" + + language = get_language(lang) + parser = get_parser(lang) # Read the file content with open(file_path, 'r') as file: content = file.read() - # Parse the content - tree = PARSER.parse(bytes(content, "utf8")) + tree = parser.parse(bytes(content, "utf8")) # Traverse the tree to find errors def traverse_tree(node): @@ -26,3 +28,18 @@ def parse_file_for_errors(file_path): traverse_tree(child) traverse_tree(tree.root_node) + +def main(): + """ + Main function to parse files provided as command line arguments. + """ + if len(sys.argv) < 2: + print("Usage: python linter.py ...") + sys.exit(1) + + for file_path in sys.argv[1:]: + print(f"Checking file: {file_path}") + parse_file_for_errors(file_path) + +if __name__ == "__main__": + main()