rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.05k stars 1.56k forks source link

Customize Run / Debug with Command Line Arguments #10408

Open JP-Ellis opened 2 years ago

JP-Ellis commented 2 years ago

Having the ability to quickly run and/or debug an individual test has been absolutely fantastic and in the case of tests and benchmarks, this is very straightforward. It would be nice though if the run/debug could be customized in some way within examples/ (and I'm guessing bin/ too?) where the main function could reasonably expect command line arguments.

I'm not sure what might be the best way to approach this. I can see a two main options:

  1. Adding 'Run with args' and 'Debug with args' to the list of possibilities. Four different run/debug options could become a big cluttered, but as this would not apply to most tests / benchmarks, I'm not sure this would be a big issue.
  2. Adding a 'Customize' option which would create a pre-filled entry in launch.json allowing for the task to be run this way (and customized). Perhaps this could apply more generally?
matklad commented 2 years ago

Yeah, this is something I very much want to have, but there's a large design space here. The upstream issue is tracked at https://github.com/microsoft/language-server-protocol/issues/944 but, historically, waiting for the upstream (lsp/vscode) wasn't productive.

So perhaps it makes sense to just do it ourselves. I think this mostly requires coding the VS Code side of things. I think the missing pieces are:

vsrs commented 2 years ago

2. Adding a 'Customize' option which would create a pre-filled entry in launch.json allowing for the task to be run this way (and customized). Perhaps this could apply more generally?

For Debug you can use "rust-analyzer.newDebugConfig" command ("Generate launch configuration" in UI). It works exactly like described: creates a new configuration in launch.json allowing to specify args, environment, etc.

Unfortunately it does not work for Run