网上已经有很多关于vscode的配置,但都不是很详细。
安装完codelldb插件后,按f5,编辑launch.json
一般的配置如下图:
默认添加配置 codelldb:launch后如下图
需要把红线处位置改为 target/debug/某文件.exe
但是,例如新建一个项目名为"option_test" 运行cargo new option_test后,cargo run 编译后,在target/debug/下生成的是option_test.exe所以launch.json一般改为:
这样没有问题。但亦可以改为:
就是取workspace的顶层目录名,这种方式也涵盖了大部分的需求。
vscode的变量可以参考以下链接。
Visual Studio Code Variables Reference
另:没必要修改setting.json,因为全局的配置未必适合每个工程。
以下是launch.json和tasks.json的配置
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "rust",
"type": "lldb",
"request": "launch",
"program": "${workspaceRoot}/target/debug/${workspaceFolderBasename}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"preLaunchTask":"build",
"externalConsole": true,
}
]
}
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "cargo",
"command": "build",
"problemMatcher": [
"$rustc"
],
"group": "build",
"label": "build"
}
]
}