Skip to content

feat: add C# language support - #46

Open
reinhardtb wants to merge 1 commit into
NanoNets:mainfrom
Mensura-Metrica:main
Open

feat: add C# language support#46
reinhardtb wants to merge 1 commit into
NanoNets:mainfrom
Mensura-Metrica:main

Conversation

@reinhardtb

Copy link
Copy Markdown

Summary

Adds C# language support to Graft, enabling the Tier-1 code graph to index .NET codebases.

What's implemented

Language detection: .cs files mapped to "csharp" language type.

Construct extraction:

  • class_declaration, struct_declaration, interface_declaration, record_declaration, enum_declaration → class/struct/interface/class/enum
  • method_declaration, constructor_declaration, property_declaration → method
  • base_list heritage edges (first = extends, rest = implements)
  • using_directive import edges
  • invocation_expression call edges with member_access_expression receiver resolution
  • Visibility via public modifier detection

Bindings: Field declarations, variable declarations, and parameter type annotations for receiver-type resolution on member calls.

Dependencies: tree-sitter-c-sharp@0.21.3 (compatible with tree-sitter@0.21.x).

Verification

Tested on mm-signum, a .NET 10 multi-tenant IoT platform:

  • 274 files parsed (131 C# + 27 TSX + 116 TS)
  • 2256 nodes (1528 methods, 313 classes, 73 interfaces, 46 functions, 22 enums)
  • 3010 edges (contains, calls, imports, extends, implements)
  • 526 tests pass (6 new C# tests, 520 existing)

Test coverage

6 test cases in test/graph-csharp.test.ts:

  1. Classes, interfaces, enums, records, structs extraction
  2. Methods, constructors, visibility (public/private)
  3. Heritage edges (extends + implements via base_list)
  4. Call edges (member calls with receiver resolution)
  5. Import edges (using directives)
  6. Contains edges (structural hierarchy)

Adds tree-sitter-c-sharp (v0.21.3) as a dependency and implements
full C# extraction in the Tier-1 code graph.

Supported constructs:
- class, struct, interface, record, enum declarations
- method, constructor, property declarations
- base_list heritage (extends + implements)
- using_directive imports
- invocation_expression calls with member_access_expression resolution
- visibility detection (public modifier = exported)
- Field, variable, and parameter type bindings

Files changed:
- src/graph/extract.ts: Language type, languageOf, CS_KINDS, GRAMMARS,
  describeCSharp, heritageEdges, calleeName, isImport, importSpecifier,
  csExported, csTypeName
- src/graph/bindings.ts: defName, isClassNode, handleCSharp, csTypeName
- src/graph/types.ts: Kind type comments updated for C# coverage
- test/graph-csharp.test.ts: 6 test cases covering classes/interfaces/
  enums/records/structs, methods/constructors/visibility, heritage edges,
  call edges, import edges, contains edges

Verified: 274 files (131 C# + 27 TSX + 116 TS) parsed on mm-signum
codebase, producing 2256 nodes and 3010 edges. All 526 tests pass.
@anirudhkumar-nanonets

Copy link
Copy Markdown
Collaborator

Thanks, this is valuable and we’d like to move it forward. Recent changes to main introduced conflicts. Could you rebase onto the latest main, resolve them, and rerun the test suite? We’ll review it promptly afterward.

@grahas

grahas commented Aug 7, 2026

Copy link
Copy Markdown

+1 on this, C# support would be awesome

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