解决rust-analyzer加载时间过长等问题

若出现下述类似的问题,可以尝试使用本文的方法进行解决。

  1. vscode 一直卡在 fetching metadata 阶段

  2. 出现报错 Blocking waiting for file lock on package cache

  3. 出现报错 proc macro command not expanded: No proc-macros present for crate rust-analyzer(unresolved-proc-macro)

  4. 出现报错 ERROR FetchBuildDataError: error: the --keep-going flag is unstable, and only available on the nightly channel of Cargo, but this is the stable channel See https://doc.xxxx-xxxx.org/book/appendix-07-nightly-rust.html for more information about Rust release channels. See https://xxxx.com/rust-lang/cargo/issues/10496 for more information about the --keep-going flag.

配置国内源

出现 1、2 可以尝试下述方法:

删除cargo的缓存

rm -rf ~/.cargo/.package-cache

执行 cargo metadata

重启 VSCode

出现 3、4 可以尝试下述方法:

尝试更新Rust版本

  • rustup --version 查看rustup版本

  • rustup toolchain list 查看已安装的版本

  • rustup default 【指定版本的名称】 切换到指定版本要更新Rust,可以使用以下命令:4

  • rustup update 升级所有安装的版本

  • rustup install stable 安装最新的稳定版

  • rustup install beta 安装最新的测试版

  • rustup install nightly 安装最新的每日构建版

重启 VSCode

文章作者: 小森森
版权声明: 本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 小森森博客
博客 经验
喜欢就支持一下吧
打赏
微信 微信
支付宝 支付宝