visual-studio-code - 如何配置运行/调试栏任务?

标签 visual-studio-code rust

enter image description here
在此处按“运行”或“调试”时,如何配置执行的内容?这是我看到的:

> Executing task: cargo run --package myproject --bin myproject <
我试图修改tasks.json:
{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cargo",
            "command": "run",
            "problemMatcher": [
                "$rustc"
            ],
            "label": "rust: cargo run",
            "env": {
                "RUST_LOG": "info"
            }
        },
        {
            "type": "cargo",
            "command": "build",
            "problemMatcher": [
                "$rustc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "label": "rust: cargo build",
            "env": {
                "RUST_LOG": "info"
            }
        }
    ]
}

但对任务没有影响。
我正在尝试设置环境变量("RUST_LOG": "info")。

最佳答案

然后使用rust-analyzer
Setting runnable environment variables:
您可以将其添加到您的vscode settings.json中,例如~/.config/Code/User/settings.json

    "rust-analyzer.runnableEnv": {
        "RUST_LOG": "info"
    },
或按ctrl+comma,然后单击Open Settings (JSON)图标的右上角。
然后您对Rust很好:
use std::env;

fn main() -> std::io::Result<()> {
    let key = "RUST_LOG";
    match env::var(key) {
        Ok(val) => println!("{}: {:?}", key, val),
        Err(e) => println!("couldn't interpret {}: {}", key, e),
    }

    Ok(())
}
输出:
RUST_LOG: "info"

关于visual-studio-code - 如何配置运行/调试栏任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66453129/

相关文章:

javascript - 使用 Chrome 调试器无法触发 VS 代码断点 :

network-programming - 如何从 Rust 获取机器的 IP 地址列表?

rust - 如何定义通过引用接受参数的特征函数

rust - 使用跟踪箱将日志写入更多目的地

python - 在子文件夹中启动时,VS Code Python 导入路径在 VS Code 中和运行时的行为不同

visual-studio-code - 如何在visual-studio-code中编辑ansible-vault加密文件?

c# - Visual Studio Code 编译错误 - 必须配置 launch.json

vector - 如何将零添加到整数Vec之前? [复制]

rust - 如何使用 dbus 在 Rust 中检测应用程序的唯一性

visual-studio-code - 有没有办法让 VS Code 'interpret' 成为具有不同语法的文件的一部分?