Skip to content

Fix C# support: wire tree-sitter-c-sharp grammar into parser#2

Merged
DeusData merged 1 commit intoDeusData:mainfrom
bhicks329:fix/csharp-tree-sitter-grammar
Feb 28, 2026
Merged

Fix C# support: wire tree-sitter-c-sharp grammar into parser#2
DeusData merged 1 commit intoDeusData:mainfrom
bhicks329:fix/csharp-tree-sitter-grammar

Conversation

@bhicks329
Copy link
Copy Markdown
Contributor

Problem

C# is listed as a supported language in the README but every .cs file produces:

unsupported language: c-sharp

The language spec in internal/lang/csharp.go is fully defined, but the tree-sitter grammar was commented out in parser.go with:

// C# skipped: upstream module path mismatch (tree-sitter-c-sharp vs tree-sitter-c_sharp)

Root Cause

There is no actual module path mismatch. github.com/tree-sitter/tree-sitter-c-sharp is a valid Go module path — hyphens are permitted in module paths. The Go package inside the module uses underscores (tree_sitter_c_sharp), which is standard Go convention for packages derived from hyphenated names. Every other grammar in this repo follows exactly the same pattern (e.g. tree-sitter-cpptree_sitter_cpp).

Fix

  • Add import tree_sitter_c_sharp "github.com/tree-sitter/tree-sitter-c-sharp/bindings/go" to parser.go
  • Add lang.CSharp: tree_sitter.NewLanguage(tree_sitter_c_sharp.Language()) to the language map
  • Promote the dependency from indirect to direct in go.mod
  • Remove the C# skip from TestAllLanguagesLoad
  • Add TestParseCSharp to verify class and method parsing

Result

Before: 107 nodes / 110 edges on a 61-file C# codebase (only folder/file structure)
After: 1,255 nodes / 1,339 edges (995 methods, 90 classes, 2 enums fully parsed)

All existing tests continue to pass.

🤖 Generated with Claude Code

C# was listed as a supported language but every .cs file produced
"unsupported language: c-sharp" because the tree-sitter grammar was
never wired up. The comment cited a "module path mismatch", but
github.com/tree-sitter/tree-sitter-c-sharp is a valid Go module path
(hyphens are allowed); the Go package inside simply uses underscores
(tree_sitter_c_sharp), which is standard Go convention.

Fix: add the import and map lang.CSharp to tree_sitter_c_sharp.Language()
in parser.go. Also remove the C# skip from TestAllLanguagesLoad and add
TestParseCSharp to verify class and method parsing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@DeusData
Copy link
Copy Markdown
Owner

Merged into main via local rebase + merge. Thank you for fixing C# support!

@DeusData DeusData closed this Feb 28, 2026
@DeusData DeusData reopened this Feb 28, 2026
@DeusData DeusData merged commit e81202d into DeusData:main Feb 28, 2026
DeusData added a commit that referenced this pull request Mar 9, 2026
Fix C# support: wire tree-sitter-c-sharp grammar into parser
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