fix: resolve C# parser availability for tree-sitter-language-pack >=0.13.0#2
Merged
ductiletoaster merged 2 commits intomainfrom Mar 25, 2026
Merged
Conversation
Two bugs combined to raise `ValueError: Language 'c_sharp' is not available
in tree-sitter-language-pack` on GraphBuilder init, breaking indexing even
for non-C# projects:
1. Version pin too broad (>=0.6.0): versions before 0.13.0 don't ship
tree-sitter-c-sharp as a transitive dependency, so `import tree_sitter_c_sharp`
raises ModuleNotFoundError at startup. Bumped floor to >=0.13.0.
2. C# special-case used a hard-coded direct import and the wrong fallback key
('c_sharp') instead of delegating to get_language(). The pack's C# key
also changed between major versions (0.x uses "csharp", 1.x uses "c_sharp"),
so the fallback path was also broken. Replaced the manual import block with
a version-agnostic loop that tries both keys in order, and tightened the
except clause to re-raise ValueError unchanged (so LanguageNotFoundError
from the 1.x pack propagates cleanly).
Also adds a TODO comment in GraphBuilder.__init__ tracking the planned
Fix 3 (graceful per-parser degradation) for future work.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…rammars Implement Fix 3 from PR #2: extract _make_parser_safe() helper that wraps each TreeSitterParser construction in a try/except. Parsers that fail to load (e.g. C# when tree-sitter-language-pack cannot find the grammar) are skipped with a warning instead of crashing the entire GraphBuilder init. This unblocks the e2e CI tests which were failing because the C# grammar is not available under either key in all tree-sitter-language-pack versions. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix 1 (pyproject.toml): Tightened the
tree-sitter-language-packversion pin from>=0.6.0to>=0.13.0in both the main dependencies and the[parsing]extras group. Versions before 0.13.0 lack a usable C# grammar and caused silent failures.Fix 2 (tree_sitter_manager.py): Replaced the broken C# special-case import block with a version-agnostic lookup loop. The loop tries the key
"c_sharp"first (tree-sitter-language-pack v1.x naming) and falls back to"csharp"(v0.13.x naming). This makes C# load correctly regardless of which naming convention is in use, without any hard-codedimport tree_sitter_c_sharpcall that fails on older pack versions.Tests
All 82 existing unit tests pass with no changes required.
Future Work / TODO — Fix 3: Graceful degradation in
GraphBuilderThis is tracked as a TODO comment in
graph_builder.pybut was intentionally left out of this PR to keep the scope focused.Problem:
GraphBuilder.__init__currently initialises all language parsers eagerly. If any parser fails to load (wrong package version, missing grammar, etc.), the entireGraphBuilderconstruction raises an exception and the whole graph-building pipeline is unavailable — even for languages that loaded fine.Recommended fix: Extract a
_make_parser_safe(language_name)private helper that wraps the existing per-language parser construction in atry/except. The helper should:tree_sitter.Parserfor the given language the same way the current code does.logger.warning("Skipping parser for %s: %s", language_name, e)) so the failure is visible without being fatal.Noneon failure.Then, in
__init__, call_make_parser_safefor each language and filterNoneentries out of the resulting dict before storing it asself.parsers(or equivalent). The graph builder will then degrade gracefully — languages with working parsers continue to function, broken ones are skipped with a warning.This change would also make the class more robust against future grammar renames or package splits without needing another targeted fix like Fix 2.