ast-grep-outline
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseUse ast-grep outline
使用ast-grep outline
ast-grep outlineRead code in stages: find candidate files with search or file names, outline
them, then open only the source range the outline points to. Defaults adapt to
input: a file shows its local structure with member digests; a directory shows
only its exported surface as grouped names.
ast-grep outline分阶段阅读代码:通过搜索或文件名找到候选文件,生成其结构概览,然后仅打开概览指向的源代码范围。默认行为会适配输入:针对文件时,会显示其本地结构及成员摘要;针对目录时,仅显示按名称分组的导出内容。
When To Use It
适用场景
Understand a file before editing. Get a table of contents, dependencies,
and public entry points before reading implementation details:
shell
ast-grep outline <file>
ast-grep outline <file> --items imports
ast-grep outline <file> --items exportsMap an unfamiliar directory. Scan the public surface of a subtree, then
narrow by symbol type when you know what you are looking for:
shell
ast-grep outline <dir> --items exports
ast-grep outline <dir> --type struct,enum,functionZoom into a known symbol. After search finds a likely name, list its
members with line numbers instead of reading the whole body:
shell
ast-grep outline <file> --match <symbol> --type class --view expandedTrace dependency direction. Find which files import a package or module to
decide where a change belongs:
shell
ast-grep outline <dir> --items imports --view signaturesReview changed files after editing. Git tells you what changed; outline
summarizes the resulting structure and public surface:
shell
ast-grep outline $(git diff --name-only HEAD) --items exports编辑前理解文件内容:在阅读实现细节前,先获取目录、依赖项和公共入口点:
shell
ast-grep outline <file>
ast-grep outline <file> --items imports
ast-grep outline <file> --items exports梳理陌生目录结构:扫描子树的公共接口,当明确目标后,按符号类型缩小范围:
shell
ast-grep outline <dir> --items exports
ast-grep outline <dir> --type struct,enum,function聚焦已知符号:搜索找到目标名称后,列出其成员及对应行号,无需阅读整个代码体:
shell
ast-grep outline <file> --match <symbol> --type class --view expanded追踪依赖方向:找出哪些文件导入了某个包或模块,以确定修改位置:
shell
ast-grep outline <dir> --items imports --view signatures编辑后审查变更文件:Git会告诉你哪些内容发生了变更;outline则会总结变更后的结构和公共接口:
shell
ast-grep outline $(git diff --name-only HEAD) --items exportsArgument Guide
参数指南
- selects top-level items:
--items <KIND>for local declarations (file default),structurefor public API (directory default),exportsfor dependencies,importswhen import/export edges matter together.all - controls detail, from least to most:
--view <VIEW>for directory scans,namesfor one line per item,signaturesfor signatures plus member names,digestfor one line per member with its line number.expanded - filters top-level items by name or signature. Rust regex, case-sensitive; it never matches members.
--match <REGEX> - keeps only some top-level symbol types, such as
--type <TYPE[,TYPE...]>. Member types like--type class,functionnever match top-level items.method,field - hides private members when the view prints members.
--pub-members - emits one JSON object per file with precise ranges. Use it only to pipe or post-process entries; prefer text for navigation.
--json=stream
- 用于选择顶层条目:
--items <KIND>表示本地声明(文件默认值),structure表示公共API(目录默认值),exports表示依赖项,imports用于同时关注导入/导出关联。all - 控制显示细节程度,从少到多依次为:
--view <VIEW>用于目录扫描,names每个条目一行,signatures包含签名及成员名称,digest每个成员一行并附带行号。expanded - 按名称或签名过滤顶层条目。使用Rust正则表达式,区分大小写;该参数不会匹配成员。
--match <REGEX> - 仅保留特定类型的顶层符号,例如
--type <TYPE[,TYPE...]>。成员类型如--type class,function不会匹配顶层条目。method,field - 在显示成员时隐藏私有成员。
--pub-members - 为每个文件输出一个包含精确范围的JSON对象。仅用于管道传输或后处理条目;导航时优先使用文本格式。
--json=stream
Limits
局限性
outlineast-grep runrgundefinedoutlineast-grep runrg