Skip to content

fix: resolve C# parser availability for tree-sitter-language-pack >=0.13.0#2

Merged
ductiletoaster merged 2 commits intomainfrom
fix/csharp-parser-availability
Mar 25, 2026
Merged

fix: resolve C# parser availability for tree-sitter-language-pack >=0.13.0#2
ductiletoaster merged 2 commits intomainfrom
fix/csharp-parser-availability

Conversation

@ductiletoaster
Copy link
Copy Markdown
Member

Summary

  • Fix 1 (pyproject.toml): Tightened the tree-sitter-language-pack version pin from >=0.6.0 to >=0.13.0 in 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-coded import tree_sitter_c_sharp call 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 GraphBuilder

This is tracked as a TODO comment in graph_builder.py but 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 entire GraphBuilder construction 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 a try/except. The helper should:

  1. Attempt to build the tree_sitter.Parser for the given language the same way the current code does.
  2. On any exception, log a structured warning (e.g. logger.warning("Skipping parser for %s: %s", language_name, e)) so the failure is visible without being fatal.
  3. Return None on failure.

Then, in __init__, call _make_parser_safe for each language and filter None entries out of the resulting dict before storing it as self.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.

ductiletoaster and others added 2 commits March 24, 2026 06:48
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>
@ductiletoaster ductiletoaster merged commit 5e8a816 into main Mar 25, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant