extracting-code-structure

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Code Structure Exploration Tools

代码结构探索工具

Always invoke extracting-code-structure skill to extract file structure - do not execute bash commands directly.
请始终调用extracting-code-structure技能来提取文件结构——不要直接执行bash命令。

Recognizing Structure Questions

识别结构类问题

These keywords mean use structure tools, NOT grep/search:
  • "all the methods/functions/classes in..."
  • "list of function signatures"
  • "what functions/exports/API..."
  • "package API" or "module exports"
  • "method signatures with receivers" (Dart/Flutter, TypeScript)
  • "what's available in..."
These keywords mean use search (Grep tool or extracting-code-structure skill):
  • "where is X defined"
  • "find calls to X"
  • "search for pattern Y"
出现以下关键词时,请使用结构工具,而非grep/搜索工具:
  • "文件中的所有方法/函数/类……"
  • "函数签名列表"
  • "有哪些函数/导出内容/API……"
  • "包API" 或 "模块导出内容"
  • "带接收者的方法签名"(Dart/Flutter、TypeScript)
  • "……中有哪些可用内容"
出现以下关键词时,请使用搜索工具(Grep工具或extracting-code-structure技能):
  • "X定义在哪里"
  • "查找对X的调用"
  • "搜索模式Y"

Before You Choose a Tool

选择工具前的思考

Ask yourself:
  1. Am I listing/exploring what exists? → Structure tools
  2. Am I finding WHERE something is? → Search tools (Grep or ast-grep)
  3. Am I understanding HOW something works? → Read
请自问:
  1. 我是否要列出/探索现有内容?→ 使用结构工具
  2. 我是否要查找内容的位置?→ 使用搜索工具(Grep或ast-grep)
  3. 我是否要理解内容的工作原理?→ 直接阅读代码

When to Get File Outline vs Read

何时获取文件大纲 vs 直接阅读

Get outline/index when:
  • File is large (>500 lines)
  • Need to see what's available (functions, classes, exports)
  • Exploring unfamiliar code
  • Want to decide what to read in detail
  • Saves 90%+ context vs reading entire file
Just use Read when:
  • File is small (<500 lines)
  • Already know what you're looking for
  • Need to understand implementation details
  • extracting-code-structure pattern already targets what you need
获取大纲/索引的场景:
  • 文件较大(超过500行)
  • 需要了解可用内容(函数、类、导出项)
  • 探索陌生代码
  • 决定需要详细阅读的内容
  • 相比阅读整个文件,可节省90%以上的上下文时间
直接阅读的场景:
  • 文件较小(不足500行)
  • 已经明确要查找的内容
  • 需要理解实现细节
  • extracting-code-structure模式已精准定位目标内容

Anti-Patterns

反模式

DON'T use grep/rg/Grep tool for:
  • Extracting function/method lists
  • Getting API overviews
  • Finding all exports/public members
  • Getting signatures/interfaces
These are STRUCTURE queries, not SEARCH queries.
不要将grep/rg/Grep工具用于以下场景:
  • 提取函数/方法列表
  • 获取API概览
  • 查找所有导出项/公共成员
  • 获取签名/接口
这些属于结构查询,而非搜索查询。

Default Strategy

默认策略

Invoke extracting-code-structure skill for extracting file structure (functions, classes, exports) efficiently without reading entire files.
Use ast-grep patterns, Dart/Flutter analyzer, ctags, or language-specific tools to get outlines and signatures. Dart/Flutter and JavaScript/TypeScript support have highest priority.
调用extracting-code-structure技能,无需读取整个文件即可高效提取文件结构(函数、类、导出内容)。
优先使用ast-grep模式、Dart/Flutter分析器、ctags或特定语言工具来获取大纲和签名。Dart/Flutter与JavaScript/TypeScript的支持优先级最高。

Exploration Strategy

探索策略

Tiered approach (try in order):
  1. ast-grep with known patterns - Fast, targeted (highest priority)
    • Extract exports, functions, classes with specific patterns
    • See code structure guide for patterns, including comprehensive Dart/Flutter support
  2. Toolchain-specific approaches - When available
    • Dart/Flutter analyzer - Comprehensive structure extraction for .dart files
      • See code structure guide for Dart/Flutter patterns
    • ctags/universal-ctags: Symbol index across languages
    • See code structure guide for examples
  3. Read file - Last resort for exploration
    • Sometimes necessary to understand structure
分层方法(按顺序尝试):
  1. 带已知模式的ast-grep - 快速、针对性强(优先级最高)
    • 提取导出项、函数、类的特定模式
    • 如需模式参考,可查看代码结构指南,其中包含全面的Dart/Flutter支持内容
  2. 特定工具链方法 - 当有可用工具时
    • Dart/Flutter分析器 - 为.dart文件提供全面的结构提取
      • 如需Dart/Flutter模式参考,可查看代码结构指南
    • ctags/universal-ctags: 跨语言符号索引
    • 如需示例,可查看代码结构指南
  3. 阅读文件 - 探索的最后手段
    • 有时需要通过阅读来理解结构

Key Principle

核心原则

Use structure tools to decide what to read, then read selectively.
Don't read 1000-line files blind. Get an outline first, then read the 50 lines you actually need.
先用结构工具决定阅读内容,再选择性阅读。
不要盲目阅读1000行的文件。先获取大纲,再阅读真正需要的50行内容。

Skill Combinations

技能组合

For Discovery and Exploration

发现与探索场景

  • extracting-code-structure → fd: Find files of a specific type, then get structure
  • extracting-code-structure → ripgrep: Understand structure, then search for specific patterns
  • extracting-code-structure → analyzing-code-structure: Get outline, then perform structural refactoring
  • extracting-code-structure → jq/yq: Understand API structures before extracting data
  • extracting-code-structure → fd:查找特定类型的文件,然后提取结构
  • extracting-code-structure → ripgrep:理解结构后,搜索特定模式
  • extracting-code-structure → analyzing-code-structure:获取大纲后,执行结构化重构
  • extracting-code-structure → jq/yq:理解API结构后,提取数据

In Refactoring Workflows

重构工作流场景

  • extracting-code-structure → fzf → analyzing-code-structure: Interactive selection of components to refactor
  • extracting-code-structure → ripgrep → sd: Find patterns and perform replacements
  • extracting-code-structure → fzf → analyzing-code-structure:交互式选择要重构的组件
  • extracting-code-structure → ripgrep → sd:查找模式并执行替换

For Documentation and Analysis

文档与分析场景

  • extracting-code-structure → tokei: Get statistics for specific code components
  • extracting-code-structure → bat: View structure with syntax highlighting
  • extracting-code-structure → tokei:获取特定代码组件的统计数据
  • extracting-code-structure → bat:带语法高亮查看结构

Multi-Skill Workflows

多技能工作流

  • extracting-code-structure → ripgrep → analyzing-code-structure → bat: Complete code analysis and refactoring pipeline
  • extracting-code-structure → fd → jq/yq: Find and analyze configuration structures
  • extracting-code-structure → fzf → sd: Interactive selection and modification of code elements
  • extracting-code-structure → ripgrep → analyzing-code-structure → bat:完整的代码分析与重构流程
  • extracting-code-structure → fd → jq/yq:查找并分析配置结构
  • extracting-code-structure → fzf → sd:交互式选择并修改代码元素

Integration Examples

集成示例

bash
undefined
bash
undefined

Get structure and find all methods

Get structure and find all methods

ast-grep -r 'function $FUNC($$$ARGS) {$$$BODY}' src/ | fzf | cut -d: -f1 | xargs -I {} bat {}
ast-grep -r 'function $FUNC($$$ARGS) {$$$BODY}' src/ | fzf | cut -d: -f1 | xargs -I {} bat {}

Understand API and extract usage

Understand API and extract usage

yq '.endpoints' api.yml | fzf | ripgrep -A 10 -B 5
undefined
yq '.endpoints' api.yml | fzf | ripgrep -A 10 -B 5
undefined

Detailed Patterns

详细模式

For language-specific extraction patterns, ast-grep examples, ctags usage, and integration strategies, load code structure guide when needing:
  • Dart/Flutter specific patterns and analyzer usage
  • Language-specific extraction strategies
  • ctags configuration and usage
  • Comprehensive workflow examples
  • Tool selection guidance for different languages
如需特定语言的提取模式、ast-grep示例、ctags用法及集成策略,可加载代码结构指南,获取以下内容:
  • Dart/Flutter特定模式与分析器用法
  • 特定语言的提取策略
  • ctags配置与使用方法
  • 全面的工作流示例
  • 不同语言的工具选择指南