0

I'm trying to setup visual studio code for rust to do debugging. In my launch.json file I have

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) Launch",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceRoot}/target/debug/vscode-rust-debug-example.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "externalConsole": true,
            "preLaunchTask": "localcargobuildtask"
        }
    ]
}

and in my tasks.json I have

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "localcargobuildtask",
            "command": "echo hi",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }        
    ]
}

Where "echo hi" is in my tasks I eventually want to have something like "cargo build" or "cargo test" or whatever. But this is just a starting step.

But when I press F5 the output I get is

> Executing task: C:\programs\VSCodeWorkspaces\RustProjects\vscode-rust-debug-example-debug-config-included\echo hi  <

The terminal process terminated with exit code: 2

Terminal will be reused by tasks, press any key to close it.

Rather than running "echo" from where ever the terminal finds it (working directory first, then check global path variable like you would expect) it is actually looking for a program named "echo" in my root folder of the workspace.

How do I tell visual studio code "No I don't want you to run workspace/echo, I want you to run echo in workspace" ? Or is there another more direct way to tell visual studio code "compile this before you debug it" ?

DanielV
  • 643
  • 4
  • 14

1 Answers1

0

The answer to this question How to debug Rust unit tests on Windows? suggests that changing

"command": "cargo build",

into

"command": "cargo",
    "args": [
        "build"
    ],

in the tasks.json file works and somehow it does. Maybe the editor is configured to search the %path% for single word commands, or maybe some plugin I installed overwrote the "cargo" command. Maybe the reason echo wasn't found is because it is a terminal command, not a program. Maybe the error message was a lie and it was only reporting that it couldn't find workspacefolder\command despite checking %path%? Or maybe none of that. I have no idea. It is some pretty idiosyncratic behavior.

DanielV
  • 643
  • 4
  • 14
  • I eventually found a bare minimum answer to my question. If someone finds a more detailed response and can confirm or deny my suspicion that this is a big bug then I will accept that answer instead, thank you. – DanielV May 17 '19 at 00:00