Skip to content

feat(indexer): add C# language support to AST chunker#121

Merged
rajkumarsakthivel merged 1 commit into
elara-labs:mainfrom
felixarjuna:feat/csharp-support
Jul 3, 2026
Merged

feat(indexer): add C# language support to AST chunker#121
rajkumarsakthivel merged 1 commit into
elara-labs:mainfrom
felixarjuna:feat/csharp-support

Conversation

@felixarjuna

Copy link
Copy Markdown
Contributor

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.

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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-sharp and add a csharp Tree-sitter language to the chunker.
  • Extend AST node-type matching so C# methods/local functions become FUNCTION chunks and C# types (class/interface/struct/record/enum) become CLASS chunks.
  • Extract root namespaces from C# using directives 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 rajkumarsakthivel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.GenericSystem) 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.

@rajkumarsakthivel rajkumarsakthivel merged commit b77f95c into elara-labs:main Jul 3, 2026
19 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.

3 participants