
6

在VSCode中配置Rust的nightly模式
source link: https://note.qidong.name/2023/02/vscode-rust-nightly/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

在VSCode中配置Rust的nightly模式
2023-02-24 23:44:22 +08 字数:805 标签: vscode rust
因为某些原因而不得不使用nightly模式时,一般直接切换系统版本:
rustup default nightly
以上配置对VSCode来说,是简单有效的。 但是,如果一个代码库中包含多个项目,只有个别项目是nightly时,就需要给VSCode一些特殊的配置。
原理 ¶
需要配置两个文件、三个东西:
- 自动运行
cargo check
检查时,使用nightly
版本。 - 点击编辑区按钮,运行单个测试用例时,使用
nightly
版本。 - 在【Run and Debug】中运行某个launcher时,使用
nightly
版本。
基本的配置原理,都是把cargo
变成cargo +nightly
。
只是需要为上述三种不同的使用入口,做不同形式的相同配置。
配置settings.json
¶
在项目根目录下的.vscode/settings.json
中,添加以下内容:
{
...
"rust-analyzer.runnables.command": "cargo +nightly",
"rust-analyzer.check.overrideCommand": [
"cargo",
"+nightly",
"check",
"--workspace",
"--message-format=json",
"--all-targets"
]
}
rust-analyzer.runnables.command
对应原理2,使能编辑区的单个测试用例。rust-analyzer.check.overrideCommand
对应原理1,完整替换状态栏【rust-analyzer】的命令。
配置launch.json
¶
在项目根目录下的.vscode/launch.json
中,添加以下内容:
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "UT",
"cargo": {
"args": [
"+nightly",
"test",
"--no-run"
]
},
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
其中,关键是在cargo.args
的开头,加上+nightly
这一项。
至于其它内容,都可以沿用自动生成或手动填入的内容。
对一个多目标、或多项目的代码库,可以在launch.json
中添加多个launcher。
通过有选择地加上+nightly
,可以自动区分nightly和stable项目。
结论 ¶
- 最简单有效的方案,还是全局配置、切换nightly版本。
- 不然就给VSCode上库两个文件,固化配置方案。
- VSCode官网文档相关信息,几乎无用,整个就没有nightly字样。
- Rust项目,没大事不要用nightly。
</div
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK