Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions aider/repomap.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pygments.lexers import guess_lexer_for_filename
from pygments.token import Token
from tqdm import tqdm
from tree_sitter import Query
from tree_sitter import Query, QueryError

from aider.dump import dump
from aider.special import filter_important_files
Expand Down Expand Up @@ -298,8 +298,12 @@ def get_tags_raw(self, fname, rel_fname):
return
tree = parser.parse(bytes(code, "utf-8"))

# Run the tags queries
captures = self._run_captures(Query(language, query_scm), tree.root_node)
# Skip files whose installed parser and scm query are out of sync.
try:
captures = self._run_captures(Query(language, query_scm), tree.root_node)
except QueryError as err:
print(f"Skipping file {fname}: {err}")
return

captures_by_tag = defaultdict(list)
matches = []
Expand Down
24 changes: 24 additions & 0 deletions tests/basic/test_repomap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import time
import unittest
from pathlib import Path
from unittest.mock import patch

import git
from tree_sitter import QueryError

from aider.dump import dump # noqa: F401
from aider.io import InputOutput
Expand Down Expand Up @@ -273,6 +275,28 @@ def test_get_repo_map_excludes_added_files(self):
# close the open cache files, so Windows won't error
del repo_map

def test_get_repo_map_skips_query_compile_failures(self):
with IgnorantTemporaryDirectory() as temp_dir:
broken_file = os.path.join(temp_dir, "broken.py")
healthy_file = os.path.join(temp_dir, "healthy.md")

with open(broken_file, "w", encoding="utf-8") as f:
f.write("def broken():\n return 1\n")

with open(healthy_file, "w", encoding="utf-8") as f:
f.write("# healthy\n")

io = InputOutput()
repo_map = RepoMap(main_model=self.GPT35, root=temp_dir, io=io)

with patch("aider.repomap.Query", side_effect=QueryError("boom")):
result = repo_map.get_repo_map([], [broken_file, healthy_file])

self.assertIn("broken.py", result)
self.assertIn("healthy.md", result)

del repo_map


class TestRepoMapTypescript(unittest.TestCase):
def setUp(self):
Expand Down
Loading