mcpField
R
rust-code-navigator

rust-code-navigator

github.com/actionbook开发1.6k3.3k 次安装9 周前更新
代码仓库

关于 rust-code-navigator

借助 Language Server Protocol 操作在 Rust 代码库中导航,适合需要理解代码的开发者。可查找定义、引用及符号信息。

主要功能

  1. 01跳转到符号定义
  2. 02查找符号引用
  3. 03查看类型和文档
  4. 04搜索工作区符号

适用场景

  1. 01定位结构体或函数定义
  2. 02重构前检查符号用法
  3. 03查看符号类型和文档

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/actionbook/rust-skills --skill rust-code-navigator

安装后在 Claude Code 中输入/rust-code-navigator确认已加载。

详细介绍

Rust 代码导航器

使用语言服务器协议高效导航大型 Rust 代码库。

用法

/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 操作

1. 跳转到定义

查找符号的定义位置。

LSP(
  operation: "goToDefinition",
  filePath: "src/main.rs",
  line: 25,
  character: 10
)

适用场景:

  • 用户询问“X 定义在哪里?”
  • 用户想了解某个类型或函数
  • 相当于按住 Ctrl 并单击
2. 查找引用

查找符号的所有用法。

LSP(
  operation: "findReferences",
  filePath: "src/lib.rs",
  line: 15,
  character: 8
)

适用场景:

  • 用户询问“谁在使用 X?”
  • 重构或重命名前
  • 了解变更的影响
3. 悬停信息

获取符号的类型和文档。

LSP(
  operation: "hover",
  filePath: "src/main.rs",
  line: 30,
  character: 15
)

适用场景:

  • 用户询问“X 的类型是什么?”
  • 用户想查看文档
  • 快速检查类型

工作流

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 (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.
找到引用
## References to `Config` (5 found)

| Location | Context |
|----------|---------|
| 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>` |

常见模式

用户表述LSP 操作
“X 定义在哪里?”goToDefinition
“谁在使用 X?”findReferences
“X 的类型是什么?”hover
“查找所有结构体”workspaceSymbol
“这个文件里有什么?”documentSymbol

错误处理

错误原因解决方案
“没有 LSP 服务”rust-analyzer 未运行建议:rustup component add rust-analyzer
“未找到符号”拼写错误或不在作用域内先使用 workspaceSymbol 搜索
“多个定义”泛型或宏显示全部定义并让用户选择

相关技能

场景查看
调用关系rust-call-graph
项目结构rust-symbol-analyzer
Trait 实现rust-trait-explorer
安全重构rust-refactor-helper

评论

支持 Markdown