Skip to content

Commit c187939

Browse files
committed
Auto merge of #17888 - Tyrubias:remove-invocation-location, r=Veykril
chore(config): remove `invocationLocation` in favor of `invocationStrategy` These flags were added to help rust-analyzer integrate with repos requiring non-Cargo invocations. The consensus is that having two independent settings are no longer needed. This change removes `invocationLocation` in favor of `invocationStrategy` and changes the internal representation of `InvocationStrategy::Once` to hold the workspace root. Closes #17848.
2 parents ba973db + b0f20c7 commit c187939

File tree

8 files changed

+33
-173
lines changed

8 files changed

+33
-173
lines changed

crates/project-model/src/build_dependencies.rs

+4-15
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use serde::Deserialize;
1919
use toolchain::Tool;
2020

2121
use crate::{
22-
utf8_stdout, CargoConfig, CargoFeatures, CargoWorkspace, InvocationLocation,
23-
InvocationStrategy, ManifestPath, Package, Sysroot, TargetKind,
22+
utf8_stdout, CargoConfig, CargoFeatures, CargoWorkspace, InvocationStrategy, ManifestPath,
23+
Package, Sysroot, TargetKind,
2424
};
2525

2626
/// Output of the build script and proc-macro building steps for a workspace.
@@ -63,10 +63,7 @@ impl WorkspaceBuildScripts {
6363
progress: &dyn Fn(String),
6464
sysroot: &Sysroot,
6565
) -> io::Result<WorkspaceBuildScripts> {
66-
let current_dir = match &config.invocation_location {
67-
InvocationLocation::Root(root) if config.run_build_script_command.is_some() => root,
68-
_ => workspace.workspace_root(),
69-
};
66+
let current_dir = workspace.workspace_root();
7067

7168
let allowed_features = workspace.workspace_features();
7269
let cmd = Self::build_command(
@@ -89,15 +86,7 @@ impl WorkspaceBuildScripts {
8986
) -> io::Result<Vec<WorkspaceBuildScripts>> {
9087
assert_eq!(config.invocation_strategy, InvocationStrategy::Once);
9188

92-
let current_dir = match &config.invocation_location {
93-
InvocationLocation::Root(root) => root,
94-
InvocationLocation::Workspace => {
95-
return Err(io::Error::new(
96-
io::ErrorKind::Other,
97-
"Cannot run build scripts from workspace with invocation strategy `once`",
98-
))
99-
}
100-
};
89+
let current_dir = workspace_root;
10190
let cmd = Self::build_command(
10291
config,
10392
&Default::default(),

crates/project-model/src/cargo_workspace.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use serde_json::from_value;
1313
use span::Edition;
1414
use toolchain::Tool;
1515

16-
use crate::{utf8_stdout, InvocationLocation, ManifestPath, Sysroot};
16+
use crate::{utf8_stdout, ManifestPath, Sysroot};
1717
use crate::{CfgOverrides, InvocationStrategy};
1818

1919
/// [`CargoWorkspace`] represents the logical structure of, well, a Cargo
@@ -100,7 +100,6 @@ pub struct CargoConfig {
100100
/// Extra env vars to set when invoking the cargo command
101101
pub extra_env: FxHashMap<String, String>,
102102
pub invocation_strategy: InvocationStrategy,
103-
pub invocation_location: InvocationLocation,
104103
/// Optional path to use instead of `target` when building
105104
pub target_dir: Option<Utf8PathBuf>,
106105
}

crates/project-model/src/lib.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,13 @@ fn utf8_stdout(mut cmd: Command) -> anyhow::Result<String> {
186186
Ok(stdout.trim().to_owned())
187187
}
188188

189-
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
189+
#[derive(Clone, Debug, Default, PartialEq, Eq)]
190190
pub enum InvocationStrategy {
191191
Once,
192192
#[default]
193193
PerWorkspace,
194194
}
195195

196-
#[derive(Clone, Debug, Default, PartialEq, Eq)]
197-
pub enum InvocationLocation {
198-
Root(AbsPathBuf),
199-
#[default]
200-
Workspace,
201-
}
202-
203196
/// A set of cfg-overrides per crate.
204197
#[derive(Default, Debug, Clone, Eq, PartialEq)]
205198
pub struct CfgOverrides {

crates/rust-analyzer/src/config.rs

+2-48
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,6 @@ config_data! {
8080
pub(crate) cargo_autoreload: bool = true,
8181
/// Run build scripts (`build.rs`) for more precise code analysis.
8282
cargo_buildScripts_enable: bool = true,
83-
/// Specifies the working directory for running build scripts.
84-
/// - "workspace": run build scripts for a workspace in the workspace's root directory.
85-
/// This is incompatible with `#rust-analyzer.cargo.buildScripts.invocationStrategy#` set to `once`.
86-
/// - "root": run build scripts in the project's root directory.
87-
/// This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
88-
/// is set.
89-
cargo_buildScripts_invocationLocation: InvocationLocation = InvocationLocation::Workspace,
9083
/// Specifies the invocation strategy to use when running the build scripts command.
9184
/// If `per_workspace` is set, the command will be executed for each workspace.
9285
/// If `once` is set, the command will be executed once.
@@ -101,8 +94,7 @@ config_data! {
10194
/// If there are multiple linked projects/workspaces, this command is invoked for
10295
/// each of them, with the working directory being the workspace root
10396
/// (i.e., the folder containing the `Cargo.toml`). This can be overwritten
104-
/// by changing `#rust-analyzer.cargo.buildScripts.invocationStrategy#` and
105-
/// `#rust-analyzer.cargo.buildScripts.invocationLocation#`.
97+
/// by changing `#rust-analyzer.cargo.buildScripts.invocationStrategy#`.
10698
///
10799
/// By default, a cargo invocation will be constructed for the configured
108100
/// targets and features, with the following base command line:
@@ -182,14 +174,6 @@ config_data! {
182174
///
183175
/// For example for `cargo check`: `dead_code`, `unused_imports`, `unused_variables`,...
184176
check_ignore: FxHashSet<String> = FxHashSet::default(),
185-
/// Specifies the working directory for running checks.
186-
/// - "workspace": run checks for workspaces in the corresponding workspaces' root directories.
187-
// FIXME: Ideally we would support this in some way
188-
/// This falls back to "root" if `#rust-analyzer.check.invocationStrategy#` is set to `once`.
189-
/// - "root": run checks in the project's root directory.
190-
/// This config only has an effect when `#rust-analyzer.check.overrideCommand#`
191-
/// is set.
192-
check_invocationLocation | checkOnSave_invocationLocation: InvocationLocation = InvocationLocation::Workspace,
193177
/// Specifies the invocation strategy to use when running the check command.
194178
/// If `per_workspace` is set, the command will be executed for each workspace.
195179
/// If `once` is set, the command will be executed once.
@@ -212,8 +196,7 @@ config_data! {
212196
/// If there are multiple linked projects/workspaces, this command is invoked for
213197
/// each of them, with the working directory being the workspace root
214198
/// (i.e., the folder containing the `Cargo.toml`). This can be overwritten
215-
/// by changing `#rust-analyzer.check.invocationStrategy#` and
216-
/// `#rust-analyzer.check.invocationLocation#`.
199+
/// by changing `#rust-analyzer.check.invocationStrategy#`.
217200
///
218201
/// If `$saved_file` is part of the command, rust-analyzer will pass
219202
/// the absolute path of the saved file to the provided command. This is
@@ -1868,12 +1851,6 @@ impl Config {
18681851
InvocationStrategy::Once => project_model::InvocationStrategy::Once,
18691852
InvocationStrategy::PerWorkspace => project_model::InvocationStrategy::PerWorkspace,
18701853
},
1871-
invocation_location: match self.cargo_buildScripts_invocationLocation(None) {
1872-
InvocationLocation::Root => {
1873-
project_model::InvocationLocation::Root(self.root_path.clone())
1874-
}
1875-
InvocationLocation::Workspace => project_model::InvocationLocation::Workspace,
1876-
},
18771854
run_build_script_command: self.cargo_buildScripts_overrideCommand(None).clone(),
18781855
extra_args: self.cargo_extraArgs(None).clone(),
18791856
extra_env: self.cargo_extraEnv(None).clone(),
@@ -1930,14 +1907,6 @@ impl Config {
19301907
crate::flycheck::InvocationStrategy::PerWorkspace
19311908
}
19321909
},
1933-
invocation_location: match self.check_invocationLocation(None) {
1934-
InvocationLocation::Root => {
1935-
crate::flycheck::InvocationLocation::Root(self.root_path.clone())
1936-
}
1937-
InvocationLocation::Workspace => {
1938-
crate::flycheck::InvocationLocation::Workspace
1939-
}
1940-
},
19411910
}
19421911
}
19431912
Some(_) | None => FlycheckConfig::CargoCommand {
@@ -2348,13 +2317,6 @@ pub(crate) enum InvocationStrategy {
23482317
#[derive(Serialize, Deserialize, Debug, Clone)]
23492318
struct CheckOnSaveTargets(#[serde(with = "single_or_array")] Vec<String>);
23502319

2351-
#[derive(Serialize, Deserialize, Debug, Clone)]
2352-
#[serde(rename_all = "snake_case")]
2353-
enum InvocationLocation {
2354-
Root,
2355-
Workspace,
2356-
}
2357-
23582320
#[derive(Serialize, Deserialize, Debug, Clone)]
23592321
#[serde(rename_all = "snake_case")]
23602322
enum LifetimeElisionDef {
@@ -3196,14 +3158,6 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
31963158
"The command will be executed once."
31973159
],
31983160
},
3199-
"InvocationLocation" => set! {
3200-
"type": "string",
3201-
"enum": ["workspace", "root"],
3202-
"enumDescriptions": [
3203-
"The command will be executed in the corresponding workspace root.",
3204-
"The command will be executed in the project root."
3205-
],
3206-
},
32073161
"Option<CheckOnSaveTargets>" => set! {
32083162
"anyOf": [
32093163
{

crates/rust-analyzer/src/flycheck.rs

+8-29
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,13 @@ use toolchain::Tool;
1515

1616
use crate::command::{CommandHandle, ParseFromLine};
1717

18-
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
18+
#[derive(Clone, Debug, Default, PartialEq, Eq)]
1919
pub(crate) enum InvocationStrategy {
2020
Once,
2121
#[default]
2222
PerWorkspace,
2323
}
2424

25-
#[derive(Clone, Debug, Default, PartialEq, Eq)]
26-
pub(crate) enum InvocationLocation {
27-
Root(AbsPathBuf),
28-
#[default]
29-
Workspace,
30-
}
31-
3225
#[derive(Clone, Debug, PartialEq, Eq)]
3326
pub(crate) struct CargoOptions {
3427
pub(crate) target_triples: Vec<String>,
@@ -79,7 +72,6 @@ pub(crate) enum FlycheckConfig {
7972
args: Vec<String>,
8073
extra_env: FxHashMap<String, String>,
8174
invocation_strategy: InvocationStrategy,
82-
invocation_location: InvocationLocation,
8375
},
8476
}
8577

@@ -424,30 +416,17 @@ impl FlycheckActor {
424416
cmd.args(&options.extra_args);
425417
Some(cmd)
426418
}
427-
FlycheckConfig::CustomCommand {
428-
command,
429-
args,
430-
extra_env,
431-
invocation_strategy,
432-
invocation_location,
433-
} => {
419+
FlycheckConfig::CustomCommand { command, args, extra_env, invocation_strategy } => {
434420
let mut cmd = Command::new(command);
435421
cmd.envs(extra_env);
436422

437-
match invocation_location {
438-
InvocationLocation::Workspace => {
439-
match invocation_strategy {
440-
InvocationStrategy::Once => {
441-
cmd.current_dir(&self.root);
442-
}
443-
InvocationStrategy::PerWorkspace => {
444-
// FIXME: cmd.current_dir(&affected_workspace);
445-
cmd.current_dir(&self.root);
446-
}
447-
}
423+
match invocation_strategy {
424+
InvocationStrategy::Once => {
425+
cmd.current_dir(&self.root);
448426
}
449-
InvocationLocation::Root(root) => {
450-
cmd.current_dir(root);
427+
InvocationStrategy::PerWorkspace => {
428+
// FIXME: cmd.current_dir(&affected_workspace);
429+
cmd.current_dir(&self.root);
451430
}
452431
}
453432

crates/rust-analyzer/src/reload.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -764,18 +764,22 @@ impl GlobalState {
764764
FlycheckConfig::CargoCommand { .. } => {
765765
crate::flycheck::InvocationStrategy::PerWorkspace
766766
}
767-
FlycheckConfig::CustomCommand { invocation_strategy, .. } => invocation_strategy,
767+
FlycheckConfig::CustomCommand { ref invocation_strategy, .. } => {
768+
invocation_strategy.clone()
769+
}
768770
};
769771

770772
self.flycheck = match invocation_strategy {
771-
crate::flycheck::InvocationStrategy::Once => vec![FlycheckHandle::spawn(
772-
0,
773-
sender,
774-
config,
775-
None,
776-
self.config.root_path().clone(),
777-
None,
778-
)],
773+
crate::flycheck::InvocationStrategy::Once => {
774+
vec![FlycheckHandle::spawn(
775+
0,
776+
sender,
777+
config,
778+
None,
779+
self.config.root_path().clone(),
780+
None,
781+
)]
782+
}
779783
crate::flycheck::InvocationStrategy::PerWorkspace => {
780784
self.workspaces
781785
.iter()

docs/user/generated_config.adoc

+2-24
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,6 @@ Automatically refresh project info via `cargo metadata` on
4545
--
4646
Run build scripts (`build.rs`) for more precise code analysis.
4747
--
48-
[[rust-analyzer.cargo.buildScripts.invocationLocation]]rust-analyzer.cargo.buildScripts.invocationLocation (default: `"workspace"`)::
49-
+
50-
--
51-
Specifies the working directory for running build scripts.
52-
- "workspace": run build scripts for a workspace in the workspace's root directory.
53-
This is incompatible with `#rust-analyzer.cargo.buildScripts.invocationStrategy#` set to `once`.
54-
- "root": run build scripts in the project's root directory.
55-
This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
56-
is set.
57-
--
5848
[[rust-analyzer.cargo.buildScripts.invocationStrategy]]rust-analyzer.cargo.buildScripts.invocationStrategy (default: `"per_workspace"`)::
5949
+
6050
--
@@ -75,8 +65,7 @@ option.
7565
If there are multiple linked projects/workspaces, this command is invoked for
7666
each of them, with the working directory being the workspace root
7767
(i.e., the folder containing the `Cargo.toml`). This can be overwritten
78-
by changing `#rust-analyzer.cargo.buildScripts.invocationStrategy#` and
79-
`#rust-analyzer.cargo.buildScripts.invocationLocation#`.
68+
by changing `#rust-analyzer.cargo.buildScripts.invocationStrategy#`.
8069

8170
By default, a cargo invocation will be constructed for the configured
8271
targets and features, with the following base command line:
@@ -209,16 +198,6 @@ List of `cargo check` (or other command specified in `check.command`) diagnostic
209198

210199
For example for `cargo check`: `dead_code`, `unused_imports`, `unused_variables`,...
211200
--
212-
[[rust-analyzer.check.invocationLocation]]rust-analyzer.check.invocationLocation (default: `"workspace"`)::
213-
+
214-
--
215-
Specifies the working directory for running checks.
216-
- "workspace": run checks for workspaces in the corresponding workspaces' root directories.
217-
This falls back to "root" if `#rust-analyzer.check.invocationStrategy#` is set to `once`.
218-
- "root": run checks in the project's root directory.
219-
This config only has an effect when `#rust-analyzer.check.overrideCommand#`
220-
is set.
221-
--
222201
[[rust-analyzer.check.invocationStrategy]]rust-analyzer.check.invocationStrategy (default: `"per_workspace"`)::
223202
+
224203
--
@@ -250,8 +229,7 @@ Cargo, you might also want to change
250229
If there are multiple linked projects/workspaces, this command is invoked for
251230
each of them, with the working directory being the workspace root
252231
(i.e., the folder containing the `Cargo.toml`). This can be overwritten
253-
by changing `#rust-analyzer.check.invocationStrategy#` and
254-
`#rust-analyzer.check.invocationLocation#`.
232+
by changing `#rust-analyzer.check.invocationStrategy#`.
255233

256234
If `$saved_file` is part of the command, rust-analyzer will pass
257235
the absolute path of the saved file to the provided command. This is

0 commit comments

Comments
 (0)