mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 06:23:25 +00:00
Make runnables workspace
This commit is contained in:
parent
c3acdc2fa1
commit
65d39f32d6
4 changed files with 24 additions and 22 deletions
|
@ -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.
|
||||
|
@ -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`.
|
||||
|
@ -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
|
||||
|
@ -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(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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, ¶ms.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)?;
|
||||
|
@ -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)?;
|
||||
|
|
|
@ -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)) => {
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue