rust-code-navigator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRust Code Navigator
Rust代码导航器
Navigate large Rust codebases efficiently using Language Server Protocol.
使用语言服务器协议(LSP)高效浏览大型Rust代码库。
Usage
使用方法
/rust-code-navigator <symbol> [in file.rs:line]Examples:
- - Find definition of parse_config
/rust-code-navigator parse_config - - Navigate from specific location
/rust-code-navigator MyStruct in src/lib.rs:42
/rust-code-navigator <symbol> [in file.rs:line]示例:
- - 查找parse_config的定义
/rust-code-navigator parse_config - - 从指定位置进行导航
/rust-code-navigator MyStruct in src/lib.rs:42
LSP Operations
LSP操作
1. Go to Definition
1. 跳转定义
Find where a symbol is defined.
LSP(
operation: "goToDefinition",
filePath: "src/main.rs",
line: 25,
character: 10
)Use when:
- User asks "where is X defined?"
- User wants to understand a type/function
- Ctrl+click equivalent
查找符号的定义位置。
LSP(
operation: "goToDefinition",
filePath: "src/main.rs",
line: 25,
character: 10
)适用场景:
- 用户询问"X定义在哪里?"
- 用户想要了解某个类型/函数
- 等同于Ctrl+点击操作
2. Find References
2. 查找引用
Find all usages of a symbol.
LSP(
operation: "findReferences",
filePath: "src/lib.rs",
line: 15,
character: 8
)Use when:
- User asks "who uses X?"
- Before refactoring/renaming
- Understanding impact of changes
查找符号的所有使用位置。
LSP(
operation: "findReferences",
filePath: "src/lib.rs",
line: 15,
character: 8
)适用场景:
- 用户询问"谁在使用X?"
- 重构/重命名之前
- 了解代码变更的影响范围
3. Hover Information
3. 悬停信息
Get type and documentation for a symbol.
LSP(
operation: "hover",
filePath: "src/main.rs",
line: 30,
character: 15
)Use when:
- User asks "what type is X?"
- User wants documentation
- Quick type checking
获取符号的类型和文档说明。
LSP(
operation: "hover",
filePath: "src/main.rs",
line: 30,
character: 15
)适用场景:
- 用户询问"X是什么类型?"
- 用户想要查看文档说明
- 快速类型检查
Workflow
工作流程
User: "Where is the Config struct defined?"
│
▼
[1] Search for "Config" in workspace
LSP(operation: "workspaceSymbol", ...)
│
▼
[2] If multiple results, ask user to clarify
│
▼
[3] Go to definition
LSP(operation: "goToDefinition", ...)
│
▼
[4] Show file path and context
Read surrounding code for context用户: "Config结构体定义在哪里?"
│
▼
[1] 在工作区中搜索"Config"
LSP(operation: "workspaceSymbol", ...)
│
▼
[2] 如果存在多个结果,询问用户以明确需求
│
▼
[3] 执行跳转定义操作
LSP(operation: "goToDefinition", ...)
│
▼
[4] 显示文件路径和上下文
读取周边代码以获取上下文信息Output Format
输出格式
Definition Found
找到定义
undefinedundefinedConfig (struct)
Config (struct)
Defined in:
src/config.rs:15
rust #[derive(Debug, Clone)] pub struct Config { pub name: String, pub port: u16, pub debug: bool, } Documentation: Configuration for the application server.
undefined定义位置:
src/config.rs:15
rust #[derive(Debug, Clone)] pub struct Config { pub name: String, pub port: u16, pub debug: bool, } 文档说明: 应用服务器的配置信息。
undefinedReferences Found
找到引用
undefinedundefinedReferences to Config
(5 found)
Config对Config
的引用(共5处)
Config| Location | Context |
|---|---|
| src/main.rs:10 | |
| src/server.rs:25 | |
| src/server.rs:42 | |
| src/tests.rs:15 | |
| src/cli.rs:8 | |
undefined| 位置 | 上下文 |
|---|---|
| src/main.rs:10 | |
| src/server.rs:25 | |
| src/server.rs:42 | |
| src/tests.rs:15 | |
| src/cli.rs:8 | |
undefinedCommon Patterns
常见模式
| User Says | LSP Operation |
|---|---|
| "Where is X defined?" | goToDefinition |
| "Who uses X?" | findReferences |
| "What type is X?" | hover |
| "Find all structs" | workspaceSymbol |
| "What's in this file?" | documentSymbol |
| 用户提问 | LSP操作 |
|---|---|
| "X定义在哪里?" | goToDefinition |
| "谁在使用X?" | findReferences |
| "X是什么类型?" | hover |
| "查找所有结构体" | workspaceSymbol |
| "这个文件里有什么内容?" | documentSymbol |
Error Handling
错误处理
| Error | Cause | Solution |
|---|---|---|
| "No LSP server" | rust-analyzer not running | Suggest: |
| "Symbol not found" | Typo or not in scope | Search with workspaceSymbol first |
| "Multiple definitions" | Generics or macros | Show all and let user choose |
| 错误信息 | 原因 | 解决方案 |
|---|---|---|
| "No LSP server" | rust-analyzer未运行 | 建议执行: |
| "Symbol not found" | 拼写错误或符号不在作用域内 | 先使用workspaceSymbol进行搜索 |
| "Multiple definitions" | 泛型或宏导致 | 显示所有结果并让用户选择 |
Related Skills
相关工具
| When | See |
|---|---|
| Call relationships | rust-call-graph |
| Project structure | rust-symbol-analyzer |
| Trait implementations | rust-trait-explorer |
| Safe refactoring | rust-refactor-helper |
| 场景 | 查看 |
|---|---|
| 调用关系 | rust-call-graph |
| 项目结构 | rust-symbol-analyzer |
| Trait实现 | rust-trait-explorer |
| 安全重构 | rust-refactor-helper |