| name | search-code |
| description | Search for code patterns in Syncpack. Use when finding symbols, implementations, or understanding how code is used. Covers ast-grep for Rust and grep/rg for other cases. |
Search Code
Guide for searching the Syncpack codebase effectively.
Golden Rule
Use ast-grep for Rust files — it filters out comments, strings, and docs.
Quick Reference
| Looking for... | Use |
|---|
| Rust symbols, patterns, structs | ast-grep |
| Multiple file types | grep/rg |
| Content in comments intentionally | grep/rg |
| Non-Rust files (JSON, MD, TOML) | grep/rg |
ast-grep Examples
ast-grep -p 'pub struct $NAME' src/
ast-grep -p 'Specifier::new' src/
ast-grep -p 'pub enum $NAME' src/
ast-grep -p 'impl $TYPE' src/
ast-grep -p 'pub fn run($$$) -> i32' src/
ast-grep -p 'match $EXPR { $$$ }' src/
Pattern Syntax
| Pattern | Matches |
|---|
$NAME | Single identifier |
$$$ | Zero or more items (arguments, fields, etc.) |
$_ | Any single expression |
When to Use grep/rg
rg "TODO" --type rust --type md
rg "FIXME" src/
rg "version" Cargo.toml
rg -i "error" src/
Common Searches
Find where a type is used
ast-grep -p 'Context' src/
Find all InstanceState assignments
ast-grep -p 'InstanceState::valid' src/
ast-grep -p 'InstanceState::fixable' src/
ast-grep -p 'InstanceState::unfixable' src/
Find test files
find src -name '*_test.rs'
Find command implementations
ast-grep -p 'pub fn run($$$) -> i32' src/commands/
Tips
- Start broad, then narrow with more specific patterns
- Use
ast-grep output to find the file, then read_file to understand context
- Chain searches: find the type, then find where it's constructed