Support Structural Search & Replace via AST-Grep #9411
wheelo
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I’d like to propose a new feature that could significantly improve code search and modification inside the extension:
Structural Search & Replace Using AST-Grep
Roo Code is a fantastic extension, and it already leverages tree-sitter internally for parsing and understanding files. However, the current functionality is still somewhat limited and not as streamlined or extensible as it could be. Giving the LLM direct access to an AST-Grep tool would provide a much simpler and more powerful way to facilitate operations such as codebase_search, search_files, and other structural code queries.
Another scenario where AST-Grep would be highly beneficial is during the apply workflow. When users request a code change, Roo Code typically prompts them to apply the modification using model-generated edits. Relying on the AI model for every Apply operation can be overwhelming and sometimes problematic, because many small or deterministic code edits do not require the model at all. These cases can be handled more reliably and efficiently using structural or rule-based replacements, which AST-Grep excels at.
To address these issues, I’d like to request an option for AST-based structural matching and rewriting, powered by AST-grep
Proposed Feature
1. Expose AST-Grep as an AI Tool for the LLM
Giving the LLM direct access to AST-Grep would enable advanced, structural code queries that go far beyond text search.
This would dramatically improve AI-assisted refactoring, analysis, and context gathering.
Moreover, u can use ast-grep with some advanced model Skill such as Claude Code Skill. Unlike traditional text-based search (grep, ripgrep), ast-grep understands the structure of your code, allowing you to find patterns like:
"Find all async functions that don't have error handling"
"Locate all React components that use a specific hook"
"Find functions with more than 3 parameters"
"Search for console.log calls inside class methods"
something like this
The skill should be automatically detected by some model such as Claude Code.
2. Allow Roo Code to use AST-Grep as the underlying engine for “Apply Changes”
When Roo Code applies the generated patch, instead of (or in addition to) plain text search/replace, it could:
This ensures that even if formatting or small details differ, the correct code can still be matched reliably.
Example use cases:
3. Optional: Use AST-Grep within the code indexing pipeline
It could possibly already be used, because I found some Tree-sitter code in the code indexing.
Why This Matters
For an AI coding assistant, structural operations can massively upgrade both precision and user trust.
Closing Thoughts
I believe AST-Grep integration could be a powerful enhancement for Roo Code, it is Semantic-Based Search.
Beta Was this translation helpful? Give feedback.
All reactions