en un clic
ast-grep
// Use when searching or replacing code patterns - use ast-grep instead of text search for semantic accuracy
// Use when searching or replacing code patterns - use ast-grep instead of text search for semantic accuracy
Navigate code with IDE features and run proactive LSP diagnostics on files/folders/batches. Use as PRIMARY for code intelligence and type/error checks.
Use when writing a new pi-lens ast-grep rule YAML file — covers schema, drop path, gotchas, and NAPI runner constraints
Use when writing a new pi-lens tree-sitter query rule YAML file — covers schema, S-expression syntax, capture names, predicates, and gotchas
| name | ast-grep |
| description | Use when searching or replacing code patterns - use ast-grep instead of text search for semantic accuracy |
Use ast_grep_search and ast_grep_replace for semantic code search/replace. ast-grep understands code structure, not just text.
fetchMetrics($ARGS) not fetchMetricspaths to relevant filespaths, then fall back to grepapply: false before apply: truefunction $NAME($$$) { $$$ } not function $NAME(selector unless expert — narrows to AST node kind; does not extract metavariablesfrom "$PATH" matches literal "$PATH", not a wildcard| Syntax | Matches | Named? |
|---|---|---|
$X | single node | yes — captures the node |
$$$ | zero or more nodes | no — unnamed wildcard |
$$$ARGS | zero or more nodes | yes — captures the list |
Use $$$ when you don't need the captured value; $$$NAME when you do.
| Pattern | Matches |
|---|---|
fetchMetrics($ARGS) | call with any single arg |
fetchMetrics($$$ARGS) | call with any number of args |
function $NAME($$$) { $$$ } | function declaration |
import { $NAMES } from $PATH | named import (no quotes on path) |
const $X = $Y | variable declaration |
# console.log inside a class method
pattern: console.log($$$)
inside:
kind: method_definition
stopBy: end
Use kind: directly when you want to match a node type without a pattern:
# any arrow function
kind: arrow_function
❌ $VAR inside quotes — matches literal "$VAR", not a metavar
from "$PATH" → use grep for wildcard path matching
from "./utils" → ✅ exact string literal works fine
❌ Trailing comma in objects
{ type: $T, } → use { type: $T }
❌ Shorthand property mismatch
{ runnerId: $RID } → won't match { runnerId }
use { runnerId } or { runnerId, $$$REST }
❌ Unnamed $$$ when you need the value
foo($$$) → captures nothing; use foo($$$ARGS) to inspect matches
No matches? Simplify and retry once. Still nothing? Fall back to grep or lsp_navigation.