360 Secure SkillHub
360 安全技能中心

Rust Analyzer LSP

这是基于rust-analyzer的Rust语言服务器,核心功能涵盖代码补全、定义跳转、实时错误诊断、符号重命名、代码提取等重构能力,还支持宏展开、类型/参数内联提示。适用于Rust项目开发全流程,可在LSP兼容编辑器自动运行,也能通过cargo命令手动格式化、lint、构建测试,支持多渠道安装与项目自定义配置。

bowen31337
bowen31337
热度 79.65
最近更新 2026-02-26 07:40:35
分类:开发依赖:代码执行 / MCP 服务应用场景:代码生成 / 调试排错

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add rust-analyzer-lsp
Metadata
name
rust-analyzer-lsp
description
Rust language server (rust-analyzer) providing code intelligence and analysis for .rs files. Use when working with Rust code that needs autocomplete, go-to-definition, find references, error detection, or refactoring support.

rust-analyzer LSP

Rust language server integration providing comprehensive code intelligence through rust-analyzer.

Capabilities

  • Code intelligence: Autocomplete, go-to-definition, find references
  • Error detection: Real-time diagnostics for compilation errors
  • Refactoring: Rename symbols, extract function/variable
  • Analysis: Macro expansion, type hints, inlay hints
  • Supported extensions: .rs

Installation

Via rustup (recommended)

rustup component add rust-analyzer

Via Homebrew (macOS)

brew install rust-analyzer

Via package manager (Linux)

# Ubuntu/Debian
sudo apt install rust-analyzer

# Arch Linux
sudo pacman -S rust-analyzer

Manual download

Download pre-built binaries from the releases page.

Verify installation:

rust-analyzer --version

Usage

The language server runs automatically in LSP-compatible editors. For manual operations:

Format code

cargo fmt

Run linter

cargo clippy

Build and test

cargo build
cargo test

Check without building

cargo check

Configuration

Create .rust-analyzer.json in project root:

{
  "checkOnSave": {
    "command": "clippy"
  },
  "inlayHints": {
    "typeHints": true,
    "parameterHints": true
  }
}

Integration Pattern

When editing Rust code:

  1. rust-analyzer provides real-time diagnostics
  2. Run cargo fmt to format code
  3. Use cargo clippy for linting
  4. Run cargo test before committing

Common Cargo Commands

  • cargo new <name> - Create new project
  • cargo build - Compile project
  • cargo run - Build and run
  • cargo test - Run tests
  • cargo check - Fast compile check
  • cargo clippy - Run linter
  • cargo fmt - Format code
  • cargo doc --open - Generate and open docs

More Information