Skip to content

fix(csharp): emit type references for properties - #1591

Closed
Synvoya wants to merge 1 commit into
Graphify-Labs:v8from
Synvoya:fix/csharp-property-type-references
Closed

Synvoya wants to merge 1 commit into
Graphify-Labs:v8from
Synvoya:fix/csharp-property-type-references

Conversation

@Synvoya

@Synvoya Synvoya commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

C# auto-properties drop their type references. public Widget Main { get; set; } and public List<Widget> Items { get; set; } emit no references(field) edges — so a class whose state is declared as properties (idiomatic modern C#) has no field edges at all.

Root cause

In graphify/extract.py, the class-body walker has a C# field_declaration handler but no property_declaration handler (the existing property_declaration branches are guarded on the PHP/Kotlin/Swift ts_module, so none fire for tree_sitter_c_sharp).

Fix

Add a C# property_declaration branch mirroring the field handler. A property exposes its type on the node directly (no variable_declaration wrapper), so read child_by_field_name("type") and run _csharp_collect_type_refs (like the Java/PHP/Kotlin siblings) — yielding both the container field ref and the generic_arg ref, with the same ref_token/qualified/ref_qualifier metadata as the field path.

Verification

  • Added Owner/Workers properties to the fixture and test_csharp_property_type_references_have_field_context (fails before the fix, passes after).
  • test_languages.py + test_multilang.py: 343 passed, 0 failed. ruff clean.

Before → after: DataProcessor → Processor (field), DataProcessor → List (field), and DataProcessor → Processor (generic_arg) are now emitted.

Note: fully-qualified generic names (System.Collections.Generic.List<T>) still drop the type argument — a pre-existing limitation of _csharp_collect_type_refs's qualified_name branch, out of scope for this change.

The C# class-body walker only handled field_declaration, so a
property's type produced no references(field) edge. In idiomatic C#,
auto-properties (`public Widget Main { get; set; }`) — not bare fields
— are the standard way to declare state, so this silently dropped most
of a class's type relationships.

Add a property_declaration branch alongside the field_declaration
handler, guarded the same way (ts_module == tree_sitter_c_sharp,
parent_class_nid set). A property exposes its type on the node directly
(no variable_declaration wrapper), so read it via
child_by_field_name("type") and collect refs with
_csharp_collect_type_refs, mirroring the Java/PHP/Kotlin siblings so
List<Widget> yields both the List field ref and the Widget generic_arg
ref. Only emit when target != parent_class_nid.
@safishamsi

Copy link
Copy Markdown
Member

Merged as bb5e519 (your authorship). Auto-property type + generic-arg refs, mirroring field_declaration. Full suite 2788.

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.

2 participants