VSCode Rust 环境配置

先安装插件

rust-analyzer

在此,再推荐大家几个好用的插件:

  1. Even Better TOML,支持 .toml 文件完整特性
  2. Error Lens, 更好的获得错误展示
  3. One Dark Pro, 非常好看的 VSCode 主题
  4. CodeLLDB, Debugger 程序

配置完可以做到

  1. 代码提示补全
  2. F5调试
  3. 代码自动格式化

配置VSCode

  1. json launch.json

内容如下:

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "rust", 
            "type": "lldb",
            "request": "launch", 
            "program": "${workspaceRoot}/target/debug/${workspaceFolderBasename}", 
            "args": [], 
            "cwd": "${workspaceRoot}",
            "preLaunchTask":"build"
        }
    ]
}
  1. json settings.json

内容如下:

{
    "[rust]":{
    "editor.defaultFormatter":"rust-lang.rust-analyzer",
    "editor.formatOnSave": true,// Makes the magiceditor.formatOnSave":true
    "rust-analyzer.checkOnSave.command": "clippy"
    },
}
  1. json tasks.json

内容如下:

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "cargo",
			"command": "build",
			"problemMatcher": [
				"$rustc"
			],
			"group": "build",
			"label": "build"
		}
	]
}

Enjoy~~~

posted @ 2024-11-28 20:09  Maguyusi  阅读(150)  评论(0)    收藏  举报