-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix: corrected C# tree-sitter query #7813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mrubens @jr @cte @hannesrudolph I wanted to start by saying that Roo Code is a huge contribution to open source—its versatility and widespread usage are truly inspiring, and I’m proud to contribute. I’ve just submitted PR #7813, “fix: corrected C# tree-sitter query,” which resolves the issue where C# files were detected but not properly indexed, resulting in fallback to basic text processing. Key improvements: Automated Review Feedback: roomote[bot] has already reviewed the change and confirmed that it successfully addresses the indexing issues described in issue #5238 and #6048 . Could you please take a look when you have a moment? I’d appreciate any feedback or approval so we can merge this and restore full C# support. Thanks, and keep up the amazing work with Roo Code! Best regards, |
@mubeen-zulfiqar This is so awesome! I had a strange feeling about CBI being worse than originally. And turns out it was because 95% of my codebases are C#. Thank you! ❤️ @KJ7LNW Do you think we need to vet all the queries for at least basic parsing. I dont understand how this slipped by with all the corpus tests there are in the most t-s project directories. |
@adamhill Thanks a lot! 🙌 Seeing someone hit that issue in real life makes this work worthwhile — this definitely helps folks whose projects are heavily C#. I appreciate you sharing that feedback. Really glad to be contributing alongside you on Roo Code! |
I am not familiar enough with C# to check this directly, but make sure that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @mubeen-zulfiqar!
@mrubens @daniel-lxs |
Related GitHub Issue
Closes: #5238 #6048
Description
Problem Summary
Roo-Code was failing to process and embed C# files despite having complete infrastructure support for C# language parsing. C# files were being detected but not properly indexed, resulting in missing code embeddings.
Root Cause Analysis
Issue Location
File:
src/services/tree-sitter/queries/c-sharp.ts
Problem: Incorrect tree-sitter query patterns using malformed syntax that captured only node names instead of full AST definitions.
Technical Details
How Roo-Code Processes Files
Language Detection:
src/services/code-index/processors/file-watcher.ts
detects file typesTree-sitter Parsing:
src/services/tree-sitter/languageParser.ts
loads language parsersAST Query Execution:
src/services/code-index/processors/parser.ts
executes queriesEmbedding Generation: Captured code blocks are sent for embedding
Failure Point
In
src/services/code-index/processors/parser.ts
, the processing logic:Result: C# queries returned
captures.length === 0
, triggering "unsupported language" fallback behavior.Broken Query Patterns
Original (Incorrect):
Problem: The syntax
@name.definition.class
attempts to capture nested attributes, but tree-sitter expects separate capture names.Query Pattern Syntax Explanation
Why We Use Separate Captures:
(node_type name: (identifier) @name) @definition.type
(node_type name: (identifier) @name.definition.type)
Technical Reason:
The correct syntax uses separate captures
(@name) @definition.type)
to capture both:@name
- captures the identifier text for the name@definition.type
- captures the full AST node for the definitionThe incorrect nested syntax
(@name.definition.type)
attempts to create nested capture attributes which tree-sitter does not support, resulting in zero captures and causing the "unsupported language" fallback behavior.Future Contributors: Always use separate captures to prevent regressions. This pattern is consistent across all working language queries (Python, JavaScript, etc.).
Fix Applied
Updated C# Query Patterns
Fixed Syntax:
Key Changes
Separated Captures: Changed from
@name.definition.type
to@name) @definition.type
Proper Node Targeting: Each query now captures both the identifier name and the full AST node
Consistent Syntax: Matches the working pattern used by Python, JavaScript, and other supported languages
Qualified Namespace Support: Uses
(qualified_name)
instead of(identifier)
to capture nested namespaces likeMyCompany.MyProduct.MyModule
File-Scoped Namespace Support: Added support for C# 10+ file-scoped namespace declarations
Verification Process
Debug Test Results
Before Fix:
Query captures:
0
Status: "language may be unsupported"
Embedding: Fallback to full file content
After Fix:
Query captures:
>0
(depends on C# file content)Status: Proper semantic parsing
Embedding: Individual code blocks (classes, methods, properties, etc.)
Test Procedure
This update has been tested on a project containing several hundred C# files, delivering excellent results. An example test is shown below.
Test File Used
Build Result
Extension:
bin/roo-cline-3.27.0.vsix
(27.22 MB)Download: Download the VSIX
Status: Successfully built with C# fixes
Files Updated: (
src/services/tree-sitter/queries/c-sharp.ts
)Impact
C# Support: Now fully functional with proper semantic parsing
Other Languages: Unaffected (already working correctly)
Performance: No degradation - same processing pipeline
Compatibility: Maintains all existing Roo-Code functionality
Get in Touch
Discord:
mubeen_zulfiqar
Email: [email protected]
Important
Fixes C# tree-sitter query patterns in
c-sharp.ts
to enable proper AST node capturing and embedding generation.c-sharp.ts
to correctly capture AST nodes.@name.definition.type
to@name) @definition.type
.>0
, enabling proper semantic parsing and embedding of C# code blocks.This description was created by
for aa9213b. You can customize this summary. It will automatically update as commits are pushed.