Skip to content

Commit

Permalink
Make runnables workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
alibektas committed Aug 28, 2024
1 parent 55078f0 commit 2ddb4e1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
38 changes: 19 additions & 19 deletions src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,6 @@ 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(),

/// 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
/// tests or binaries. For example, it may be `--release`.
runnables_extraArgs: Vec<String> = vec![],
/// Additional arguments to be passed through Cargo to launched tests, benchmarks, or
/// doc-tests.
///
/// Unless the launched target uses a
/// [custom test harness](https://doc.rust-lang.org/cargo/reference/cargo-targets.html#the-harness-field),
/// 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!["--show-output".to_owned()],

/// 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
/// is installed.
Expand Down Expand Up @@ -367,7 +353,7 @@ config_data! {
checkOnSave | checkOnSave_enable: bool = true,


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

/// 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
/// tests or binaries. For example, it may be `--release`.
runnables_extraArgs: Vec<String> = vec![],
/// Additional arguments to be passed through Cargo to launched tests, benchmarks, or
/// doc-tests.
///
/// Unless the launched target uses a
/// [custom test harness](https://doc.rust-lang.org/cargo/reference/cargo-targets.html#the-harness-field),
/// 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!["--show-output".to_owned()],

/// Additional arguments to `rustfmt`.
rustfmt_extraArgs: Vec<String> = vec![],
/// Advanced option, fully override the command rust-analyzer uses for
Expand Down Expand Up @@ -1972,11 +1972,11 @@ impl Config {
*self.cargo_buildScripts_rebuildOnSave(source_root)
}

pub fn runnables(&self) -> RunnablesConfig {
pub fn runnables(&self, source_root: Option<SourceRootId>) -> RunnablesConfig {
RunnablesConfig {
override_cargo: self.runnables_command().clone(),
cargo_extra_args: self.runnables_extraArgs().clone(),
extra_test_binary_args: self.runnables_extraTestBinaryArgs().clone(),
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(),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,7 @@ pub(crate) fn handle_runnables(
) -> anyhow::Result<Vec<lsp_ext::Runnable>> {
let _p = tracing::info_span!("handle_runnables").entered();
let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
let source_root = snap.analysis.source_root_id(file_id).ok();
let line_index = snap.file_line_index(file_id)?;
let offset = params.position.and_then(|it| from_proto::offset(&line_index, it).ok());
let target_spec = TargetSpec::for_file(&snap, file_id)?;
Expand Down Expand Up @@ -894,7 +895,7 @@ pub(crate) fn handle_runnables(
}

// Add `cargo check` and `cargo test` for all targets of the whole package
let config = snap.config.runnables();
let config = snap.config.runnables(source_root);
match target_spec {
Some(TargetSpec::Cargo(spec)) => {
let is_crate_no_std = snap.analysis.is_crate_no_std(spec.crate_id)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1365,8 +1365,9 @@ pub(crate) fn runnable(
snap: &GlobalStateSnapshot,
runnable: Runnable,
) -> Cancellable<Option<lsp_ext::Runnable>> {
let config = snap.config.runnables();
let target_spec = TargetSpec::for_file(snap, runnable.nav.file_id)?;
let source_root = snap.analysis.source_root_id(runnable.nav.file_id).ok();
let config = snap.config.runnables(source_root);

match target_spec {
Some(TargetSpec::Cargo(spec)) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl CargoTargetSpec {
kind: &RunnableKind,
cfg: &Option<CfgExpr>,
) -> (Vec<String>, Vec<String>) {
let config = snap.config.runnables();
let config = snap.config.runnables(None);
let extra_test_binary_args = config.extra_test_binary_args;

let mut cargo_args = Vec::new();
Expand Down

0 comments on commit 2ddb4e1

Please sign in to comment.