rust-code-navigator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Rust Code Navigator

Rust代码导航器

Navigate large Rust codebases efficiently using Language Server Protocol.
使用语言服务器协议(LSP)高效浏览大型Rust代码库。

Usage

使用方法

/rust-code-navigator <symbol> [in file.rs:line]
Examples:
  • /rust-code-navigator parse_config
    - Find definition of parse_config
  • /rust-code-navigator MyStruct in src/lib.rs:42
    - Navigate from specific location
/rust-code-navigator <symbol> [in file.rs:line]
示例:
  • /rust-code-navigator parse_config
    - 查找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

找到定义

undefined
undefined

Config (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, } ​
文档说明: 应用服务器的配置信息。
undefined

References Found

找到引用

undefined
undefined

References to
Config
(5 found)

Config
的引用(共5处)

LocationContext
src/main.rs:10
let config = Config::load()?;
src/server.rs:25
fn new(config: Config) -> Self
src/server.rs:42
self.config.port
src/tests.rs:15
Config::default()
src/cli.rs:8
config: Option<Config>
undefined
位置上下文
src/main.rs:10
let config = Config::load()?;
src/server.rs:25
fn new(config: Config) -> Self
src/server.rs:42
self.config.port
src/tests.rs:15
Config::default()
src/cli.rs:8
config: Option<Config>
undefined

Common Patterns

常见模式

User SaysLSP 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

错误处理

ErrorCauseSolution
"No LSP server"rust-analyzer not runningSuggest:
rustup component add rust-analyzer
"Symbol not found"Typo or not in scopeSearch with workspaceSymbol first
"Multiple definitions"Generics or macrosShow all and let user choose
错误信息原因解决方案
"No LSP server"rust-analyzer未运行建议执行:
rustup component add rust-analyzer
"Symbol not found"拼写错误或符号不在作用域内先使用workspaceSymbol进行搜索
"Multiple definitions"泛型或宏导致显示所有结果并让用户选择

Related Skills

相关工具

WhenSee
Call relationshipsrust-call-graph
Project structurerust-symbol-analyzer
Trait implementationsrust-trait-explorer
Safe refactoringrust-refactor-helper
场景查看
调用关系rust-call-graph
项目结构rust-symbol-analyzer
Trait实现rust-trait-explorer
安全重构rust-refactor-helper