除錯
ast-grep — Structural Code Search, Lint & Rewrite
Use ast-grep (sg) for structural code search, lint, and rewrite using AST patterns. Prefer ast-grep over grep/ripgrep/sed whenever the task involves matching code by syntactic structure rather than plain text — e.g. finding function calls with specific argument shapes, locating patterns inside particular contexts (a call inside a loop, an import inside a class), renaming symbols while respecting scope, enforcing lint rules based on AST node kinds, or performing large-scale codemod rewrites. Also use during refactoring to find all call sites of a function, all instances of an error handling pattern (like .map_err closures), all trait method implementations, or any repeated code pattern you want to extract or replace. Triggers: "ast-grep", "sg", "structural search", "codemod", "code pattern", "syntax-aware search", "find all call sites", "find everywhere we use", or any code search where the shape of the code matters more than the literal text.