Skip to content

[C#] Add code-graph extractor #155

Description

@doctor-ew

Target branch: main

Language

  • Language: C#
  • File extensions: .cs
  • Tree-sitter grammar repository: https://github.com/tree-sitter/tree-sitter-c-sharp
  • Grammar version or commit: tree-sitter-c-sharp@0.23.5 (npm) — note: use this package's own bundled tree-sitter-c_sharp.wasm, not tree-sitter-wasms@0.1.12's copy of the same filename; they are different grammar revisions and several documented fields (variable_declarator.name, using_directive.name) resolve to undefined via childForFieldName against the older build.
  • Grammar license: MIT

Scope

A tree-sitter-only extractor (no compiler integration, following the python.ts/rust.ts pattern rather than typescript.ts's compiler-based path) covering the common C# declaration and reference surface: classes, interfaces, structs, enums (with members), methods (incl. constructors/destructors, static, async), properties, fields (incl. constconstant), parameters, namespaces (block and file-scoped, including nesting), using imports, attributes as decorates, calls/instantiates/extends/implements references.

Known, documented limitation: base_list has no field structure and does not syntactically distinguish a base class from an implemented interface (verified against node-types.json). 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 first pass: generics/type-parameter capture (typeParameters), LINQ query-clause references, records/delegates get a best-fit existing NodeKind (class, type_alias) rather than dedicated kinds.

Expected nodes

class, struct, interface, enum, enum_member, method, function (local functions), property, field, constant (const fields), parameter, namespace, type_alias (delegates), file.

Expected edges

contains, calls, imports (using), extends, implements, instantiates (new T()), decorates (attributes).

Required proof

  • I have read Extending the code graph
  • The language exists in the shared Language vocabulary ("csharp" is already in LANGUAGES, src/graph/types.ts) — no core vocabulary addition needed
  • The extractor will use the frozen LanguageExtractor interface
  • A compatible grammar WASM file will be vendored and registered
  • File extensions and the extractor will be registered
  • A representative fixture will be added
  • Focused tests will assert node and edge shape
  • npm run typecheck, npm test, and npm run build will pass
  • No identity, reconciliation, schema, or drift-semantics changes are included

Blocked by

None.

Additional context

Implementation is done and validated: 11 focused tests (extractor-csharp.test.ts) plus a full local npm test run (533/533 passing, no regressions), and a real-world smoke test against a ~640-file C# codebase (a .NET Azure Functions calculation engine) — 694 .cs-tree files, 0 partial/failed, 22,694 nodes / 25,250 edges. Opening a PR against this issue next.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions