feat(indexer): add C# language support to AST chunker#121
Conversation
Register tree-sitter-c-sharp so .cs files get semantic chunks instead of the whole-file fallback: - chunk methods and local functions as FUNCTION chunks - chunk classes, interfaces, structs, records and enums as CLASS chunks - extract root namespaces from using directives for IMPORTS edges record_declaration and enum_declaration also improve Java chunking, which shares those node types. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds C# support to the AST chunker so .cs files are semantically chunked (functions/types) and participate in import-edge extraction, rather than falling back to whole-file chunks.
Changes:
- Register
tree-sitter-c-sharpand add acsharpTree-sitter language to the chunker. - Extend AST node-type matching so C# methods/local functions become
FUNCTIONchunks and C# types (class/interface/struct/record/enum) becomeCLASSchunks. - Extract root namespaces from C#
usingdirectives for imports edges, with new tests validating chunking and import deduplication.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/context_engine/indexer/chunker.py |
Registers C# parser and adds C# node types for chunking and using-based import extraction. |
tests/indexer/test_chunker.py |
Adds coverage for C# function/type chunking and C# import extraction/deduplication behavior. |
pyproject.toml |
Adds tree-sitter-c-sharp as a runtime dependency. |
uv.lock |
Locks tree-sitter-c-sharp and bumps the project lock entry to the new version. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
rajkumarsakthivel
left a comment
There was a problem hiding this comment.
Approve — clean implementation, two things worth noting.
Java behaviour change (not a bug, but unannounced)
record_declaration and enum_declaration are new to _CLASS_TYPES. The PR comment says "Java, C#" but Java was not chunking records or enums before this PR — they will now be chunked as CLASS chunks for the first time. This is an improvement, not a regression, but it is an unannounced behaviour change. Worth calling out in the PR description. A Java test covering records/enums would also be nice.
>= 3 assertion for function chunks is fragile
If local_function_statement is the wrong node type for C# local functions and ApplyFee is missed, the test still passes with 2 chunks (Charge + the interface method). Consider checking == 3 or explicitly asserting ApplyFee content appears in the function chunks to make the assertion catch regressions.
Import granularity is intentional
using_directive → root namespace only (System.Collections.Generic → System) is consistent with the Python convention already in _parse_import_module. Flagging it as a deliberate trade-off in a comment would be helpful for future maintainers.
Everything else looks correct — method_declaration already covers C# class methods, the grammar version 0.23.5 is locked cleanly, uv.lock is consistent with pyproject.toml 0.4.25.
Register tree-sitter-c-sharp so .cs files get semantic chunks instead of the whole-file fallback:
record_declaration and enum_declaration also improve Java chunking, which shares those node types.