Skip to content

Instantly share code, notes, and snippets.

@puffybsd
Last active March 18, 2024 02:16
Show Gist options
  • Save puffybsd/aff5193465b5cba4a07d7f700a357ffc to your computer and use it in GitHub Desktop.
Save puffybsd/aff5193465b5cba4a07d7f700a357ffc to your computer and use it in GitHub Desktop.
executorMap for vscode code runner rust files. Checks if the directory is examples and executes current file, or performs a standard cargo run.
"code-runner.executorMap": {
"rust": "if [ $(basename $dir) = 'examples' ]; then cargo run --example $fileNameWithoutExt; else cargo run; fi",
}
@puffybsd
Copy link
Author

Copy the user settings for "code-runner.executorMap" and update the "rust" attribute (other languages removed for clarity).

@rebelC0der
Copy link

OMG! I wasted 3 days trying to figure out why VSCode/Atom can't run files with code runner and can't see additional crates. No one on Matrix Chat, official forum and Stack Overflow could help and this just made it work! Thanks so much! Do you know how to fix auto completion not working for rand crate for example?

Screenshot_20200116_130818

@Psy-Kosh
Copy link

Psy-Kosh commented Mar 1, 2020

Thanks for pointing out where the key is for this issue. Been driving me batty too. However, doesn't seem like your solution is currently being interpreted properly by it. I'm basically a beginner for both rust and vscode (tried learning rust a few years ago, but didn't get far, chose the wrong documentation to study from, etc..) Anyways, I get this:

image

Am I missing something? At this point should I basically not worry about the conditional and just have it unconditionally do a "cargo run"?

Thanks.

@rustymagnet3000
Copy link

rustymagnet3000 commented May 7, 2021

@Psy-Kosh,

When I ran cargo build it was fine. When I ran it inside VSCode it failed.

All I needed to do was alter /VScode/Preferences/Settings.json:

{
    "explorer.confirmDelete": false,
    "files.autoSave": "afterDelay",
    ....
    ...
    ..
    "code-runner.executorMap": {
        "rust": "if [ $(basename $dir) = 'examples' ]; then cargo run --example $fileNameWithoutExt; else cargo run; fi",
    }
}

hope that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment