Skip to content

C# classes using primary constructor syntax are sometimes not indexed #237

@d3ara1n

Description

@d3ara1n

Problem

When a C# class uses the C# 12 primary constructor syntax (public class Foo(Bar bar)), the class and all its methods may be completely absent from the CodeGraph index. This breaks search, node lookup, call chain analysis, and context queries for those symbols.

Reproduction

Tested with CodeGraph on a .NET 10 project (298 C# files, 3073 nodes indexed). The classTypes: ['class_declaration'] in csharp.ts should match primary-constructor classes, but results are inconsistent:

Class Syntax Indexed?
DataService public class DataService(IMemoryCache cache, ...) ✅ Yes
InstanceService public class InstanceService(InstanceManager m, ProfileManager p, ...) ❌ No
UpdateService public partial class UpdateService(...) : ILifetimeService ❌ No (only nested IOptions found)

InstanceService has 2 public methods (DeployAndLaunchAsync, Deploy) — neither appears as a node. The file itself is indexed (imports are extracted), but the class declaration and its methods are skipped entirely.

Downstream Impact

  • codegraph_search("InstanceService", kind="class") → empty
  • codegraph_node("InstanceService") → falls through to an import node instead of the class
  • codegraph_callees("PlayAsync") → misses the call to DeployAndLaunchAsync (because the target symbol doesn't exist)
  • codegraph_context("Instance launch workflow") → returns irrelevant URL-launcher helpers instead of the game launch logic

Hypothesis

The inconsistency suggests the issue may not be solely about primary constructors (since DataService is indexed). Possible factors:

  • partial modifier combined with primary constructor
  • Inheritance clause (: ILifetimeService) after the parameter list
  • Parameter types from external projects / git submodules causing tree-sitter parse errors
  • Number of parameters or line count in the parameter list

It would be worth testing tree-sitter-c_sharp's AST output for these patterns to see if class_declaration nodes are produced correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions