Change the default 'Run' settings for the Rust-Analyzer plugin in VS Code

Hi all, new Rust user here. I have a question that I hope you can help me with.

I have installed Rust in my main OS and I've also installed the rust-analyzer plugin in VS Code. When I press the 'Run' option of the rust-analyzer codelens, by default, it runs the following code:

'cargo run --package my_package_name --bin my_package_name'

My question is this... is there any way that I can modify the default behaviour so that the '--quiet' flag can be used i.e when I press the 'Run' option, VS Code will run this code instead:

'cargo run --quiet --package my_package_name --bin my_package_name'?

Many thanks for your help.

hi, My usual practice is to run commands directly on the terminal.

you can configure a task on the terminal, which will be in your project Generate a task.json under the .vscode directory

{
	"tasks": [
		{
			"type": "cargo",
			"command": "run --quiet",
			"problemMatcher": [
				"$rustc"
			],
			"label": "rust: cargo run --quiet"
		}
	]
}

Not really possible today, but I'd very much love to see this!

The relevant issue is Customize Run / Debug with Command Line Arguments · Issue #10408 · rust-lang/rust-analyzer · GitHub

1 Like

Hi,

many thanks for this James. Using your original code as a template, I managed to create a task, but I had to place the "--quiet" flag into a separate "args" section to get the whole thing to work (as shown below):

{
"type": "cargo",
"command": "run",
"args": ["--quiet"],
"problemMatcher": [
"$rustc"
],
"label": "rust: cargo run --quiet",
},

Thanks again.

1 Like

Me too, I think that this would be a great feature to have, shame it didn't get much traction in the community. Thanks for getting back to me so quickly.

All the best.