Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,10 @@ config_data! {
/// This config takes a map of crate names with the exported proc-macro names to ignore as values.
procMacro_ignored: FxHashMap<Box<str>, Box<[Box<str>]>> = FxHashMap::default(),

/// Subcommand used for bench runnables instead of `bench`.
runnables_bench_command: String = "bench".to_owned(),
/// Override the subcommand used for bench runnables.
runnables_bench_overrideCommand: Option<Vec<String>> = None,
/// Command to be executed instead of 'cargo' for runnables.
runnables_command: Option<String> = None,
/// Additional arguments to be passed to cargo for runnables such as
Expand All @@ -921,6 +925,10 @@ config_data! {
/// they will end up being interpreted as options to
/// [`rustc`’s built-in test harness (“libtest”)](https://doc.rust-lang.org/rustc/tests/index.html#cli-arguments).
runnables_extraTestBinaryArgs: Vec<String> = vec!["--nocapture".to_owned()],
/// Subcommand used for test runnables instead of `test`.
runnables_test_command: String = "test".to_owned(),
/// Override the subcommand used for test runnables.
runnables_test_overrideCommand: Option<Vec<String>> = None,

/// Path to the Cargo.toml of the rust compiler workspace, for usage in rustc_private
/// projects, or "discover" to try to automatically find it if the `rustc-dev` component
Expand Down Expand Up @@ -1572,6 +1580,14 @@ pub struct RunnablesConfig {
pub cargo_extra_args: Vec<String>,
/// Additional arguments for the binary being run, if it is a test or benchmark.
pub extra_test_binary_args: Vec<String>,
/// Subcommand used for doctest runnables instead of `test`.
pub test_command: String,
/// Override the subcommand used for test runnables.
pub test_override_command: Option<Vec<String>>,
/// Subcommand used for doctest runnables instead of `bench`.
pub bench_command: String,
/// Override the subcommand used for bench runnables.
pub bench_override_command: Option<Vec<String>>,
}

/// Configuration for workspace symbol search requests.
Expand Down Expand Up @@ -2499,6 +2515,10 @@ impl Config {
override_cargo: self.runnables_command(source_root).clone(),
cargo_extra_args: self.runnables_extraArgs(source_root).clone(),
extra_test_binary_args: self.runnables_extraTestBinaryArgs(source_root).clone(),
test_command: self.runnables_test_command(source_root).clone(),
test_override_command: self.runnables_test_overrideCommand(source_root).clone(),
bench_command: self.runnables_bench_command(source_root).clone(),
bench_override_command: self.runnables_bench_overrideCommand(source_root).clone(),
}
}

Expand Down
20 changes: 14 additions & 6 deletions crates/rust-analyzer/src/target_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ impl CargoTargetSpec {

match kind {
RunnableKind::Test { test_id, attr } => {
cargo_args.push("test".to_owned());
let subcommand =
config.test_override_command.unwrap_or_else(|| vec![config.test_command]);
cargo_args.extend(subcommand);
executable_args.push(test_id.to_string());
if let TestId::Path(_) = test_id {
executable_args.push("--exact".to_owned());
Expand All @@ -134,12 +136,16 @@ impl CargoTargetSpec {
}
}
RunnableKind::TestMod { path } => {
cargo_args.push("test".to_owned());
let subcommand =
config.test_override_command.unwrap_or_else(|| vec![config.test_command]);
cargo_args.extend(subcommand);
executable_args.push(path.clone());
executable_args.extend(extra_test_binary_args);
}
RunnableKind::Bench { test_id } => {
cargo_args.push("bench".to_owned());
let subcommand =
config.bench_override_command.unwrap_or_else(|| vec![config.bench_command]);
cargo_args.extend(subcommand);
executable_args.push(test_id.to_string());
if let TestId::Path(_) = test_id {
executable_args.push("--exact".to_owned());
Expand All @@ -154,10 +160,12 @@ impl CargoTargetSpec {
}
RunnableKind::Bin => {
let subcommand = match spec {
Some(CargoTargetSpec { target_kind: TargetKind::Test, .. }) => "test",
_ => "run",
Some(CargoTargetSpec { target_kind: TargetKind::Test, .. }) => {
config.test_override_command.unwrap_or_else(|| vec![config.test_command])
}
_ => vec!["run".to_owned()],
};
cargo_args.push(subcommand.to_owned());
cargo_args.extend(subcommand);
}
}

Expand Down
28 changes: 28 additions & 0 deletions docs/book/src/configuration_generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,20 @@ Default: `false`
Exclude tests from find-all-references and call-hierarchy.


## rust-analyzer.runnables.bench.command {#runnables.bench.command}

Default: `"bench"`

Subcommand used for bench runnables instead of `bench`.


## rust-analyzer.runnables.bench.overrideCommand {#runnables.bench.overrideCommand}

Default: `null`

Override the subcommand used for bench runnables.


## rust-analyzer.runnables.command {#runnables.command}

Default: `null`
Expand Down Expand Up @@ -1385,6 +1399,20 @@ they will end up being interpreted as options to
[`rustc`’s built-in test harness (“libtest”)](https://doc.rust-lang.org/rustc/tests/index.html#cli-arguments).


## rust-analyzer.runnables.test.command {#runnables.test.command}

Default: `"test"`

Subcommand used for test runnables instead of `test`.


## rust-analyzer.runnables.test.overrideCommand {#runnables.test.overrideCommand}

Default: `null`

Override the subcommand used for test runnables.


## rust-analyzer.rustc.source {#rustc.source}

Default: `null`
Expand Down
52 changes: 52 additions & 0 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2822,6 +2822,32 @@
}
}
},
{
"title": "Runnables",
"properties": {
"rust-analyzer.runnables.bench.command": {
"markdownDescription": "Subcommand used for bench runnables instead of `bench`.",
"default": "bench",
"type": "string"
}
}
},
{
"title": "Runnables",
"properties": {
"rust-analyzer.runnables.bench.overrideCommand": {
"markdownDescription": "Override the subcommand used for bench runnables.",
"default": null,
"type": [
"null",
"array"
],
"items": {
"type": "string"
}
}
}
},
{
"title": "Runnables",
"properties": {
Expand Down Expand Up @@ -2863,6 +2889,32 @@
}
}
},
{
"title": "Runnables",
"properties": {
"rust-analyzer.runnables.test.command": {
"markdownDescription": "Subcommand used for test runnables instead of `test`.",
"default": "test",
"type": "string"
}
}
},
{
"title": "Runnables",
"properties": {
"rust-analyzer.runnables.test.overrideCommand": {
"markdownDescription": "Override the subcommand used for test runnables.",
"default": null,
"type": [
"null",
"array"
],
"items": {
"type": "string"
}
}
}
},
{
"title": "Rustc",
"properties": {
Expand Down