Skip to content

feat(graph): add C# language extractor - #156

Open
doctor-ew wants to merge 1 commit into
mex-memory:mainfrom
doctor-ew:feat/csharp-extractor
Open

feat(graph): add C# language extractor#156
doctor-ew wants to merge 1 commit into
mex-memory:mainfrom
doctor-ew:feat/csharp-extractor

Conversation

@doctor-ew

Copy link
Copy Markdown

Add code-graph extraction support for C# using tree-sitter-c-sharp (https://github.com/tree-sitter/tree-sitter-c-sharp), following the tree-sitter-only pattern (python.ts/rust.ts), not the TS compiler-based path.

  • New src/graph/extraction/languages/csharp.ts with CSharpWalker extracting: classes/structs/interfaces/enums, methods (incl. constructors/destructors, static, async), properties, fields (const -> constant), parameters, namespaces (block + file-scoped, incl. nesting), using imports, attributes -> decorates, calls/instantiates/extends/implements.
  • New fixture src/graph/__tests__/fixtures/sample.cs and 11 tests in extractor-csharp.test.ts.
  • Register C# in languages/index.ts and grammars.ts (.cs extension).
  • Vendor tree-sitter-c-sharp.wasm from tree-sitter-c-sharp@0.23.5 directly — not tree-sitter-wasms@0.1.12's copy of the same filename. That build is a different grammar revision: several fields node-types.json declares (variable_declarator.name, using_directive.name) resolve to undefined via childForFieldName against it. Verified by diffing behavior against both wasms; documented in docs/extractors.md.

Known, documented limitation: base_list has no field structure and doesn't syntactically distinguish a base class from an implemented interface. The extractor uses a first-listed-entry-is-the-base-class heuristic (extends for entry 0 on a class/struct, implements for the rest; every entry is extends on an interface) — a documented best-effort, not a semantic guarantee.

Not in scope for this pass: generics/type-parameter capture, LINQ query clauses, dedicated record/delegate node kinds (mapped to class/type_alias for now).

Validated against a real ~640-file C# codebase (a .NET Azure Functions calculation engine, external to this repo): 694 .cs-tree files, 0 partial/failed, 22,694 nodes / 25,250 edges, no regressions in the existing 533-test suite.

Fixes #155


What

Adds a C# (.cs) language extractor to the code graph.

Why

Closes #155 — C# had no extractor; .cs files were silently skipped by every graph build.

Type of change

  • Bug fix
  • New feature
  • Refactor
  • Docs
  • CI/Tooling

How to test

  1. npm test — runs the new extractor-csharp.test.ts (11 assertions) alongside the full suite (533/533 passing locally).
  2. mex graph --root <a C# project> on a real .cs codebase and inspect .mex/graph.db.

Checklist

  • Tests pass (npm test)
  • No breaking changes (or documented below)
  • Tested locally with a real project

Code-graph changes

  • This PR targets main
  • A linked issue agrees on the bounded extractor/resolver scope
  • The change follows the frozen LanguageExtractor interface
  • A focused fixture and assertions for the expected node/edge shape are included
  • Any new grammar WASM, extension mapping, extractor, or resolver is registered
  • No graph identity, reconciliation, schema, or drift-semantics changes are included

Add code-graph extraction support for C# using tree-sitter-c-sharp
(https://github.com/tree-sitter/tree-sitter-c-sharp), following the
tree-sitter-only pattern (python.ts/rust.ts), not the TS compiler-based path.

- New `src/graph/extraction/languages/csharp.ts` with `CSharpWalker`
  extracting: classes/structs/interfaces/enums, methods (incl.
  constructors/destructors, static, async), properties, fields (const ->
  constant), parameters, namespaces (block + file-scoped, incl. nesting),
  using imports, attributes -> decorates, calls/instantiates/extends/implements.
- New fixture `src/graph/__tests__/fixtures/sample.cs` and 11 tests in
  `extractor-csharp.test.ts`.
- Register C# in `languages/index.ts` and `grammars.ts` (`.cs` extension).
- Vendor `tree-sitter-c-sharp.wasm` from tree-sitter-c-sharp@0.23.5 directly
  (not tree-sitter-wasms@0.1.12's copy of the same filename -- that build is a
  different grammar revision and silently drops several documented fields;
  see docs/extractors.md for the verified detail).

Validated against a real ~640-file C# codebase (a .NET Azure Functions
calculation engine): 694 .cs-tree files, 0 partial/failed, 22,694 nodes /
25,250 edges, no regressions in the existing 533-test suite.

Fixes mex-memory#155

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.

[C#] Add code-graph extractor

1 participant