formulahendry / vscode-code-runner

Code Runner for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner
MIT License
2.2k stars 294 forks source link

Configuration: code-runner.executorMap for "rust": "cargo run" uses file names as an argument e.g.: `cargo run "c:\ar\rs\sors\src\main.rs"` the correct answer is `cargo run` #410

Open wasmup opened 5 years ago

wasmup commented 5 years ago

Describe the bug Description of what the bug is. After editing Configuration: code-runner.executorMap from: "rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt", to: "rust": "cargo run", When clicking play button, code-runner command runs: cargo run "c:\ar\rs\sors\src\main.rs" The correct command is: cargo run note: without extra arguments. if you put any thing after cargo run it will be used as user program argument, so the correct way to run is just cargo run.

To Reproduce Steps to reproduce the behavior:

  1. set: "code-runner.executorMap": { "rust": "cargo run", },

  2. and run this file "main.rs" (prints arguments list):

    use std::env; fn main() { for argument in env::args() { println!(" {}", argument); } }

output is: cargo run "c:\ar\rs\sors\src\main.rs" Finished dev [unoptimized + debuginfo] target(s) in 0.02s Running target\debug\sors.exe c:\ar\rs\sors\src\main.rs target\debug\sors.exe c:\ar\rs\sors\src\main.rs

Expected behavior cargo run


Thank you.

schrodog commented 5 years ago

a workaround is using "code-runner.customCommand" to set custom command, but that is not by language

asv7c2 commented 5 years ago

@aramazani On Windows you can use such config:

"code-runner.executorMap": {
    "rust": "cargo run && echo $fileName > nul"
}

By using variable in string, code-runner will not inject filename.

wasmup commented 5 years ago

Thanks, I'm using this for Linux now:

  "code-runner.executorMap": {
    "rust": "cargo run # $fileName",
  },
comfortablynick commented 5 years ago

I had this issue as well; for me, just ending the line with a comment works, which allows the rest of the line to be ignored by the shell:

cargo run # "path/to/main.rs"

This works on Windows with PowerShell as integrated terminal, and should work on bash/zsh/fish as well.

doggy8088 commented 4 years ago

@formulahendry If you can add a $empty that put nothing in the command line. That will be awesome!

Jontyshaw commented 3 years ago

谢谢,我现在正在Linux上使用它:

  "code-runner.executorMap": {
    "rust": "cargo run # $fileName",
  },

It;s OK, thank you.

adam248 commented 2 years ago

when will this be added to the vscode extension? thanks

rust-kotlin commented 2 years ago

I am using the cargo run --bin $fileNameWithoutExt to run the binary crate I am editing.

bradley-001 commented 1 year ago

Beautiful solution! "rust": "cargo run # $fileName" worked great for me; thanks guys!