feat(graph): add C# language extractor - #156
Open
doctor-ew wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.src/graph/extraction/languages/csharp.tswithCSharpWalkerextracting: classes/structs/interfaces/enums, methods (incl. constructors/destructors, static, async), properties, fields (const->constant), parameters, namespaces (block + file-scoped, incl. nesting),usingimports, attributes ->decorates, calls/instantiates/extends/implements.src/graph/__tests__/fixtures/sample.csand 11 tests inextractor-csharp.test.ts.languages/index.tsandgrammars.ts(.csextension).tree-sitter-c-sharp.wasmfromtree-sitter-c-sharp@0.23.5directly — nottree-sitter-wasms@0.1.12's copy of the same filename. That build is a different grammar revision: several fieldsnode-types.jsondeclares (variable_declarator.name,using_directive.name) resolve toundefinedviachildForFieldNameagainst it. Verified by diffing behavior against both wasms; documented indocs/extractors.md.Known, documented limitation:
base_listhas 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 (extendsfor entry 0 on a class/struct,implementsfor the rest; every entry isextendson 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/delegatenode kinds (mapped toclass/type_aliasfor 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;
.csfiles were silently skipped by every graph build.Type of change
How to test
npm test— runs the newextractor-csharp.test.ts(11 assertions) alongside the full suite (533/533 passing locally).mex graph --root <a C# project>on a real.cscodebase and inspect.mex/graph.db.Checklist
npm test)Code-graph changes
mainLanguageExtractorinterface