rust-lsp
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRust Analyzer Agent Skill
Rust Analyzer Agent Skill
When to use
使用场景
MUST use the MCP tools when the task involves:
- Resolving where a symbol is defined, including across crate boundaries
- Finding all references to a function, type, field, or trait method
- Inspecting type signatures, inferred types, or trait implementations
- Searching for symbols by name across a workspace
- Renaming a symbol across all usage sites
SHOULD prefer the MCP tools over grep or file reads when the task requires Rust-aware
semantic understanding (scoping, imports, trait dispatch, macro expansion).
Fall back to grep or file reads when the task is not Rust-specific, targets string literals
or comments, or covers files outside the Rust compilation.
必须在以下任务场景中使用MCP工具:
- 解析符号的定义位置,包括跨crate边界的情况
- 查找函数、类型、字段或trait方法的所有引用
- 检查类型签名、推断类型或trait实现
- 跨工作区按名称搜索符号
- 在所有使用位置安全重命名符号
应优先在任务需要具备Rust感知能力的语义理解(作用域、导入、trait调度、宏展开)时,使用MCP工具而非grep或文件读取。
当任务不涉及Rust特定内容、针对字符串字面量或注释,或覆盖Rust编译范围外的文件时,退而使用grep或文件读取。
Installation
安装
If the Rust LSP tools are not available yet, run from this skill before using the MCP tools. Treat the tools as "not available yet" whenever the current session does not expose the Rust LSP MCP tool APIs: attempt the install/setup path first, then verify whether the tools become usable.
scripts/install.sh如果Rust LSP工具尚未可用,请在使用MCP工具前运行此Skill中的脚本。当当前会话未暴露Rust LSP MCP工具API时,即视为工具“尚未可用”:请先尝试安装/设置流程,然后验证工具是否可用。
scripts/install.shCommon workflows
常见工作流
Navigate to a definition
导航至定义
- at the symbol position
definitions - Read the target file at the returned location
- 在符号位置调用
definitions - 读取返回位置对应的目标文件
Find all callers
查找所有调用者
- at the function name position
references - Review the returned locations
- 在函数名称位置调用
references - 查看返回的位置列表
Inspect a type
检查类型
- at the position — returns the resolved type even for inferred types, trait objects, and generic instantiations
hover
- 在目标位置调用——即使是推断类型、trait对象和泛型实例,也会返回解析后的类型
hover
Find a symbol by name
按名称查找符号
- with the name as query
workspace_symbols - Read the returned location if needed
- 使用名称作为查询参数调用
workspace_symbols - 如有需要,读取返回的位置
Rename a symbol safely
安全重命名符号
- with the file contents
open_document - at the position with the new name
rename_symbol - Apply the returned workspace edits to disk
- when done
close_document
- 使用文件内容调用
open_document - 在目标位置调用并传入新名称
rename_symbol - 将返回的工作区编辑内容应用到磁盘
- 完成后调用
close_document
Update in-memory content for analysis
更新内存中的分析内容
Position-based tools work on saved files without . Use the document
lifecycle only when analyzing unsaved or in-memory content:
open_document- to synchronize contents with rust-analyzer
open_document - to update contents (version auto-increments)
replace_document - when done (idempotent)
close_document
基于位置的工具无需调用即可处理已保存的文件。仅当分析未保存或内存中的内容时,才需要使用文档生命周期流程:
open_document- 调用与rust-analyzer同步内容
open_document - 调用更新内容(版本自动递增)
replace_document - 完成后调用(操作具有幂等性)
close_document
React to project structure changes
响应项目结构变更
- after editing
reload_workspaceor adding/removing cratesCargo.toml - if proc-macro source changed
rebuild_proc_macros
- 在编辑或添加/移除crates后调用
Cargo.tomlreload_workspace - 如果proc-macro源代码发生变更,调用
rebuild_proc_macros