VS code 的 rust 开发环境配置

本人在 VS code 环境中进行 rust 学习的编辑器配置。

插件

单词拼写检查

  • Code Spell Checker

Debug工具

  • CodeLLDB

行内错误提示

  • Error Lens

TOML文件支持,智能提示、格式化

  • Even Better TOML

字体

image

配置

  • 打开 VS code 的 seating.json 文件,按需填入以下配置即可。
{
    "editor.fontFamily": "Fira Code, monospace", //字体
    "editor.fontLigatures": true, //连字
    "editor.formatOnSave": true, //保存时格式化
    "editor.formatOnType": true, //输入一行后格式化
    "editor.formatOnPaste": true, //粘贴后格式化
    "[rust]": {
        "editor.defaultFormatter": "rust-lang.rust-analyzer", //默认格式化工具
     },
}

代理配置

看基金、股票价格

  • 韭菜盒子

主题

  • Bluloco Light Theme

image

图标

  • Material Icon Theme

image

色块括号

  • indent-rainbow

很好用的一个插件,特别是涉及到多个括号嵌套的场景时。

image

cargo-msrv

  • cargo-msrv

解决项目依赖问题

https://github.com/foresterre/cargo-msrv?tab=readme-ov-file

查找你的最低支持 Rust 版本!

用法:cargo msrv [选项] <命令>

命令:
  find    查找 MSRV
  list    显示依赖项的 MSRV
  set     将当前 crate 的 MSRV 设置为给定的 Rust 版本
  show    显示你的 crate 的 MSRV,如 Cargo 清单中所指定
  verify  验证 MSRV 是否可满足
  help    打印此消息或给定子命令的帮助

选项:
      --path <Crate 目录>
          Cargo 项目目录的路径

      --manifest-path <Cargo 清单>
          Cargo 清单文件的路径

  -h, --help
          打印帮助(使用 '-h' 查看摘要)

  -V, --version
          打印版本

用户输出选项:
      --output-format <格式>
          设置用户输出的格式

          [默认:human]

          可能的值:
          - human:   进度条渲染到 stderr
          - json:    Json 状态更新打印到 stdout
          - minimal: 最小输出,通常只有结果,如 MSRV 或验证是否成功或失败

      --no-user-output
          禁用用户输出

调试输出选项:
      --no-log
          禁用日志记录

      --log-target <日志目标>
          指定程序应输出日志的位置

          [默认:file]
          [可能的值:file, stdout]

      --log-level <级别>
          指定应记录的日志严重程度

          [默认:info]
          [可能的值:trace, debug, info, warn, error]


            你可以提供一个自定义的兼容性 `check` 命令作为最后一个参数(仅当通过双破折号语法提供此参数时,
            例如 `$ cargo msrv -- custom command`)。
            然后,这个自定义检查命令将用于验证 Rust 版本是否兼容。
            自定义 `check` 命令应该可以通过 rustup 运行,因为它们将被传递给 rustup,
            如下所示:`rustup run <toolchain> <命令...>`。注意:你只需要提供 <命令...> 部分。

            默认情况下,自定义检查命令是 `cargo check`。

JSON 格式
通过提供 --output-format json 标志可以启用 JSON 输出:cargo msrv find --output-format json。 事件以 json 行的形式打印。事件类型由 type 键指示。

posted @ 2023-01-31 16:37  贤云曳贺  阅读(247)  评论(0)    收藏  举报