aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer/src/config.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-10-02 10:42:03 +0100
committerGitHub <[email protected]>2020-10-02 10:42:03 +0100
commitd8e5265309cf92857c996d4f55372e3b431468bf (patch)
tree101f5f55c324d7cb7bf3c7ae22a553ca4f7bf66c /crates/rust-analyzer/src/config.rs
parent40a028c9a837f4f189b7db82cd4034536af87322 (diff)
parent4ebacf9024d82349c4b95826a4a791bdf384d0df (diff)
Merge #5954
5954: Add flexible configuration for runnables r=popzxc a=popzxc This PR introduces two new configuration options for runnables: `overrideCargo` and `cargoExtraArgs`. These options are applied to all the "run" tasks of rust analyzer, such as binaries and tests. Overall motivation is that rust-analyzer provides similar options, for example, for `rustfmt`, but not for runnables. ## `overrideCargo` This option allows user to replace `cargo` command with something else (well, something that is compatible with the cargo arguments). Motivation is that some projects may have wrappers around cargo (or even whole alternatives to cargo), which do something related to the project, and only then run `cargo`. With this feature, such users will be able to use lens and run tests directly from the IDE rather than from terminal. ![cargo_override](https://user-images.githubusercontent.com/12111581/92306622-2f404f80-ef99-11ea-9bb7-6c6192a2c54a.gif) ## `cargoExtraArgs` This option allows user to add any additional arguments for `cargo`, such as `--release`. It may be useful, for example, if project has big integration tests which take too long in debug mode, or if any other `cargo` flag has to be passed. ![cargo_extra_args](https://user-images.githubusercontent.com/12111581/92306658-821a0700-ef99-11ea-8be9-bf0aff78e154.gif) Co-authored-by: Igor Aleksanov <[email protected]>
Diffstat (limited to 'crates/rust-analyzer/src/config.rs')
-rw-r--r--crates/rust-analyzer/src/config.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 42e1ad376..0ab4c37bf 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -38,6 +38,7 @@ pub struct Config {
38 pub cargo: CargoConfig, 38 pub cargo: CargoConfig,
39 pub rustfmt: RustfmtConfig, 39 pub rustfmt: RustfmtConfig,
40 pub flycheck: Option<FlycheckConfig>, 40 pub flycheck: Option<FlycheckConfig>,
41 pub runnables: RunnablesConfig,
41 42
42 pub inlay_hints: InlayHintsConfig, 43 pub inlay_hints: InlayHintsConfig,
43 pub completion: CompletionConfig, 44 pub completion: CompletionConfig,
@@ -124,6 +125,15 @@ pub enum RustfmtConfig {
124 CustomCommand { command: String, args: Vec<String> }, 125 CustomCommand { command: String, args: Vec<String> },
125} 126}
126 127
128/// Configuration for runnable items, such as `main` function or tests.
129#[derive(Debug, Clone, Default)]
130pub struct RunnablesConfig {
131 /// Custom command to be executed instead of `cargo` for runnables.
132 pub override_cargo: Option<String>,
133 /// Additional arguments for the `cargo`, e.g. `--release`.
134 pub cargo_extra_args: Vec<String>,
135}
136
127#[derive(Debug, Clone, Default)] 137#[derive(Debug, Clone, Default)]
128pub struct ClientCapsConfig { 138pub struct ClientCapsConfig {
129 pub location_link: bool, 139 pub location_link: bool,
@@ -164,6 +174,7 @@ impl Config {
164 extra_args: Vec::new(), 174 extra_args: Vec::new(),
165 features: Vec::new(), 175 features: Vec::new(),
166 }), 176 }),
177 runnables: RunnablesConfig::default(),
167 178
168 inlay_hints: InlayHintsConfig { 179 inlay_hints: InlayHintsConfig {
169 type_hints: true, 180 type_hints: true,
@@ -220,6 +231,10 @@ impl Config {
220 load_out_dirs_from_check: data.cargo_loadOutDirsFromCheck, 231 load_out_dirs_from_check: data.cargo_loadOutDirsFromCheck,
221 target: data.cargo_target.clone(), 232 target: data.cargo_target.clone(),
222 }; 233 };
234 self.runnables = RunnablesConfig {
235 override_cargo: data.runnables_overrideCargo,
236 cargo_extra_args: data.runnables_cargoExtraArgs,
237 };
223 238
224 self.proc_macro_srv = if data.procMacro_enable { 239 self.proc_macro_srv = if data.procMacro_enable {
225 std::env::current_exe().ok().map(|path| (path, vec!["proc-macro".into()])) 240 std::env::current_exe().ok().map(|path| (path, vec!["proc-macro".into()]))
@@ -474,6 +489,9 @@ config_data! {
474 notifications_cargoTomlNotFound: bool = true, 489 notifications_cargoTomlNotFound: bool = true,
475 procMacro_enable: bool = false, 490 procMacro_enable: bool = false,
476 491
492 runnables_overrideCargo: Option<String> = None,
493 runnables_cargoExtraArgs: Vec<String> = Vec::new(),
494
477 rustfmt_extraArgs: Vec<String> = Vec::new(), 495 rustfmt_extraArgs: Vec<String> = Vec::new(),
478 rustfmt_overrideCommand: Option<Vec<String>> = None, 496 rustfmt_overrideCommand: Option<Vec<String>> = None,
479 497