Skip to content

Commit 2ddb4e1

Browse files
committed
Make runnables workspace
1 parent 55078f0 commit 2ddb4e1

File tree

4 files changed

+24
-22
lines changed

4 files changed

+24
-22
lines changed

src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,6 @@ config_data! {
124124
/// This config takes a map of crate names with the exported proc-macro names to ignore as values.
125125
procMacro_ignored: FxHashMap<Box<str>, Box<[Box<str>]>> = FxHashMap::default(),
126126

127-
/// Command to be executed instead of 'cargo' for runnables.
128-
runnables_command: Option<String> = None,
129-
/// Additional arguments to be passed to cargo for runnables such as
130-
/// tests or binaries. For example, it may be `--release`.
131-
runnables_extraArgs: Vec<String> = vec![],
132-
/// Additional arguments to be passed through Cargo to launched tests, benchmarks, or
133-
/// doc-tests.
134-
///
135-
/// Unless the launched target uses a
136-
/// [custom test harness](https://doc.rust-lang.org/cargo/reference/cargo-targets.html#the-harness-field),
137-
/// they will end up being interpreted as options to
138-
/// [`rustc`’s built-in test harness (“libtest”)](https://doc.rust-lang.org/rustc/tests/index.html#cli-arguments).
139-
runnables_extraTestBinaryArgs: Vec<String> = vec!["--show-output".to_owned()],
140-
141127
/// Path to the Cargo.toml of the rust compiler workspace, for usage in rustc_private
142128
/// projects, or "discover" to try to automatically find it if the `rustc-dev` component
143129
/// is installed.
@@ -367,7 +353,7 @@ config_data! {
367353
checkOnSave | checkOnSave_enable: bool = true,
368354

369355

370-
/// Check all targets and tests (`--all-targets`). Defaults to
356+
/// Check all targets and tests (`--all-targets`). Defaults to
371357
/// `#rust-analyzer.cargo.allTargets#`.
372358
check_allTargets | checkOnSave_allTargets: Option<bool> = None,
373359
/// Cargo command to use for `cargo check`.
@@ -433,6 +419,20 @@ config_data! {
433419
/// If false, `-p <package>` will be passed instead.
434420
check_workspace: bool = true,
435421

422+
/// Command to be executed instead of 'cargo' for runnables.
423+
runnables_command: Option<String> = None,
424+
/// Additional arguments to be passed to cargo for runnables such as
425+
/// tests or binaries. For example, it may be `--release`.
426+
runnables_extraArgs: Vec<String> = vec![],
427+
/// Additional arguments to be passed through Cargo to launched tests, benchmarks, or
428+
/// doc-tests.
429+
///
430+
/// Unless the launched target uses a
431+
/// [custom test harness](https://doc.rust-lang.org/cargo/reference/cargo-targets.html#the-harness-field),
432+
/// they will end up being interpreted as options to
433+
/// [`rustc`’s built-in test harness (“libtest”)](https://doc.rust-lang.org/rustc/tests/index.html#cli-arguments).
434+
runnables_extraTestBinaryArgs: Vec<String> = vec!["--show-output".to_owned()],
435+
436436
/// Additional arguments to `rustfmt`.
437437
rustfmt_extraArgs: Vec<String> = vec![],
438438
/// Advanced option, fully override the command rust-analyzer uses for
@@ -1972,11 +1972,11 @@ impl Config {
19721972
*self.cargo_buildScripts_rebuildOnSave(source_root)
19731973
}
19741974

1975-
pub fn runnables(&self) -> RunnablesConfig {
1975+
pub fn runnables(&self, source_root: Option<SourceRootId>) -> RunnablesConfig {
19761976
RunnablesConfig {
1977-
override_cargo: self.runnables_command().clone(),
1978-
cargo_extra_args: self.runnables_extraArgs().clone(),
1979-
extra_test_binary_args: self.runnables_extraTestBinaryArgs().clone(),
1977+
override_cargo: self.runnables_command(source_root).clone(),
1978+
cargo_extra_args: self.runnables_extraArgs(source_root).clone(),
1979+
extra_test_binary_args: self.runnables_extraTestBinaryArgs(source_root).clone(),
19801980
}
19811981
}
19821982

src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,7 @@ pub(crate) fn handle_runnables(
852852
) -> anyhow::Result<Vec<lsp_ext::Runnable>> {
853853
let _p = tracing::info_span!("handle_runnables").entered();
854854
let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
855+
let source_root = snap.analysis.source_root_id(file_id).ok();
855856
let line_index = snap.file_line_index(file_id)?;
856857
let offset = params.position.and_then(|it| from_proto::offset(&line_index, it).ok());
857858
let target_spec = TargetSpec::for_file(&snap, file_id)?;
@@ -894,7 +895,7 @@ pub(crate) fn handle_runnables(
894895
}
895896

896897
// Add `cargo check` and `cargo test` for all targets of the whole package
897-
let config = snap.config.runnables();
898+
let config = snap.config.runnables(source_root);
898899
match target_spec {
899900
Some(TargetSpec::Cargo(spec)) => {
900901
let is_crate_no_std = snap.analysis.is_crate_no_std(spec.crate_id)?;

src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/to_proto.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1365,8 +1365,9 @@ pub(crate) fn runnable(
13651365
snap: &GlobalStateSnapshot,
13661366
runnable: Runnable,
13671367
) -> Cancellable<Option<lsp_ext::Runnable>> {
1368-
let config = snap.config.runnables();
13691368
let target_spec = TargetSpec::for_file(snap, runnable.nav.file_id)?;
1369+
let source_root = snap.analysis.source_root_id(runnable.nav.file_id).ok();
1370+
let config = snap.config.runnables(source_root);
13701371

13711372
match target_spec {
13721373
Some(TargetSpec::Cargo(spec)) => {

src/tools/rust-analyzer/crates/rust-analyzer/src/target_spec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl CargoTargetSpec {
113113
kind: &RunnableKind,
114114
cfg: &Option<CfgExpr>,
115115
) -> (Vec<String>, Vec<String>) {
116-
let config = snap.config.runnables();
116+
let config = snap.config.runnables(None);
117117
let extra_test_binary_args = config.extra_test_binary_args;
118118

119119
let mut cargo_args = Vec::new();

0 commit comments

Comments
 (0)