推荐使用 rust-analyzer,它比已停止维护的 RLS 更快更稳定,是 Rust 官方推荐的 VSCode 语言服务器;需安装官方扩展、确保 Rust 工具链完整、配置 workspace 并验证功能是否生效。

现在推荐用 rust-analyzer,它比 RLS 更快、更稳定,官方已停止维护 RLS,rust-analyzer 成为 Rust 官方推荐的 VSCode 语言服务器。
打开 VSCode 扩展市场(Ctrl+Shift+X),搜索 rust-analyzer,选择由 rust-lang 发布的官方扩展,点击安装。装完后重启 VSCode 或重新加载窗口(Ctrl+Shift+P → “Developer: Reload Window”)。
rust-analyzer 需要 cargo 和 rustc 正常工作:
rustup toolchain list 确认已安装稳定版(如 stable-x86_64-pc-windows-msvc)cargo --version 和 rustc --version 检查是否可调用rustup install stable + rustup default stable
在项目根目录创建 .vscode/settings.json,启用关键功能:
{
"rust-analyzer.checkOnSave.command": "check",
"rust-analyzer.cargo.loadOutDirsFromCheck": true,
"rust-analyzer.procMacro.enable": true,
"files.associations": {
"*.rs": "rust"
}
}其中 loadOutDirsFromCheck 支持自定义构建路径(如 cargo build --target wasm32-unknown-unknown),procMacro.enable 启用宏展开支持(需 nightly 工具链配合 rustup component add rust-src rustc-dev)。
打开一个 .rs 文件,观察右下角状态栏是否显示 rust-analyzer;将光标停在函数名上应出现签名提示;按 Ctrl+Click 可跳转定义;保存时若有错误会实时标红并显示 LSP 报错。
如果没反应,尝试 Ctrl+Shift+P → “rust-analyzer: Restart Server”,或检查输出面板(Ctrl+Shift+U)中 “Rust Analyzer” 日志是否有报错。
以上就是VSCode for Rust:配置RLS/rust-analyzer的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号