Skip to content

Commit 4673236

Browse files
committed
Remove simplistic interpolation for manifest-path
1 parent 7db5029 commit 4673236

File tree

7 files changed

+32
-87
lines changed

7 files changed

+32
-87
lines changed

crates/flycheck/src/lib.rs

+5-21
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub use cargo_metadata::diagnostic::{
2323

2424
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
2525
pub enum InvocationStrategy {
26-
OnceInRoot,
26+
Once,
2727
#[default]
2828
PerWorkspace,
2929
}
@@ -317,26 +317,10 @@ impl FlycheckActor {
317317
(cmd, args, invocation_strategy)
318318
}
319319
};
320-
if let InvocationStrategy::PerWorkspace = invocation_strategy {
321-
let mut with_manifest_path = false;
322-
for arg in args {
323-
if let Some(_) = arg.find("$manifest_path") {
324-
with_manifest_path = true;
325-
cmd.arg(arg.replace(
326-
"$manifest_path",
327-
&self.root.join("Cargo.toml").display().to_string(),
328-
));
329-
} else {
330-
cmd.arg(arg);
331-
}
332-
}
333-
334-
if !with_manifest_path {
335-
cmd.current_dir(&self.root);
336-
}
337-
} else {
338-
cmd.args(args);
339-
}
320+
match invocation_strategy {
321+
InvocationStrategy::PerWorkspace => cmd.current_dir(&self.root),
322+
InvocationStrategy::Once => cmd.args(args),
323+
};
340324
cmd
341325
}
342326

crates/project-model/src/build_scripts.rs

+2-25
Original file line numberDiff line numberDiff line change
@@ -62,30 +62,7 @@ impl WorkspaceBuildScripts {
6262
let mut cmd = match config.run_build_script_command.as_deref() {
6363
Some([program, args @ ..]) => {
6464
let mut cmd = Command::new(program);
65-
66-
// FIXME: strategy and workspace root are coupled, express that in code
67-
if let (InvocationStrategy::PerWorkspace, Some(workspace_root)) =
68-
(config.invocation_strategy, workspace_root)
69-
{
70-
let mut with_manifest_path = false;
71-
for arg in args {
72-
if let Some(_) = arg.find("$manifest_path") {
73-
with_manifest_path = true;
74-
cmd.arg(arg.replace(
75-
"$manifest_path",
76-
&workspace_root.join("Cargo.toml").display().to_string(),
77-
));
78-
} else {
79-
cmd.arg(arg);
80-
}
81-
}
82-
83-
if !with_manifest_path {
84-
cmd.current_dir(workspace_root);
85-
}
86-
} else {
87-
cmd.args(args);
88-
}
65+
cmd.args(args);
8966
cmd
9067
}
9168
_ => {
@@ -176,7 +153,7 @@ impl WorkspaceBuildScripts {
176153
workspaces: &[&CargoWorkspace],
177154
progress: &dyn Fn(String),
178155
) -> io::Result<Vec<WorkspaceBuildScripts>> {
179-
assert_eq!(config.invocation_strategy, InvocationStrategy::OnceInRoot);
156+
assert_eq!(config.invocation_strategy, InvocationStrategy::Once);
180157
let cmd = Self::build_command(config, None)?;
181158
// NB: Cargo.toml could have been modified between `cargo metadata` and
182159
// `cargo check`. We shouldn't assume that package ids we see here are

crates/project-model/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ fn utf8_stdout(mut cmd: Command) -> Result<String> {
160160

161161
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
162162
pub enum InvocationStrategy {
163-
OnceInRoot,
163+
Once,
164164
#[default]
165165
PerWorkspace,
166166
}

crates/rust-analyzer/src/config.rs

+11-19
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,9 @@ config_data! {
7070
/// Run build scripts (`build.rs`) for more precise code analysis.
7171
cargo_buildScripts_enable: bool = "true",
7272
/// Specifies the invocation strategy to use when running the build scripts command.
73-
/// If `per_workspace` is set, the command will be executed for each workspace and all
74-
/// occurrences of `$manifest_path` in the command will be replaced by the corresponding
75-
/// manifest path of the workspace that the command is being invoked for. If interpolation
76-
/// for the manifest path happens at least once, the commands will be executed from the
77-
/// project root, otherwise the commands will be executed from the corresponding workspace
78-
/// root.
79-
/// If `once_in_root` is set, the command will be executed once in the project root.
73+
/// If `per_workspace` is set, the command will be executed for each workspace from the
74+
/// corresponding workspace root.
75+
/// If `once` is set, the command will be executed once in the project root.
8076
/// This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
8177
/// is set.
8278
cargo_buildScripts_invocationStrategy: InvocationStrategy = "\"per_workspace\"",
@@ -134,13 +130,9 @@ config_data! {
134130
/// Set to `"all"` to pass `--all-features` to Cargo.
135131
checkOnSave_features: Option<CargoFeaturesDef> = "null",
136132
/// Specifies the invocation strategy to use when running the checkOnSave command.
137-
/// If `per_workspace` is set, the command will be executed for each workspace and all
138-
/// occurrences of `$manifest_path` in the command will be replaced by the corresponding
139-
/// manifest path of the workspace that the command is being invoked for. If interpolation
140-
/// for the manifest path happens at least once, the commands will be executed from the
141-
/// project root, otherwise the commands will be executed from the corresponding workspace
142-
/// root.
143-
/// If `once_in_root` is set, the command will be executed once in the project root.
133+
/// If `per_workspace` is set, the command will be executed for each workspace from the
134+
/// corresponding workspace root.
135+
/// If `once` is set, the command will be executed once in the project root.
144136
/// This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
145137
/// is set.
146138
checkOnSave_invocationStrategy: InvocationStrategy = "\"per_workspace\"",
@@ -1079,7 +1071,7 @@ impl Config {
10791071
unset_test_crates: UnsetTestCrates::Only(self.data.cargo_unsetTest.clone()),
10801072
wrap_rustc_in_build_scripts: self.data.cargo_buildScripts_useRustcWrapper,
10811073
invocation_strategy: match self.data.cargo_buildScripts_invocationStrategy {
1082-
InvocationStrategy::OnceInRoot => project_model::InvocationStrategy::OnceInRoot,
1074+
InvocationStrategy::Once => project_model::InvocationStrategy::Once,
10831075
InvocationStrategy::PerWorkspace => project_model::InvocationStrategy::PerWorkspace,
10841076
},
10851077
run_build_script_command: self.data.cargo_buildScripts_overrideCommand.clone(),
@@ -1106,7 +1098,7 @@ impl Config {
11061098
return None;
11071099
}
11081100
let invocation_strategy = match self.data.checkOnSave_invocationStrategy {
1109-
InvocationStrategy::OnceInRoot => flycheck::InvocationStrategy::OnceInRoot,
1101+
InvocationStrategy::Once => flycheck::InvocationStrategy::Once,
11101102
InvocationStrategy::PerWorkspace => flycheck::InvocationStrategy::PerWorkspace,
11111103
};
11121104
let flycheck_config = match &self.data.checkOnSave_overrideCommand {
@@ -1622,7 +1614,7 @@ enum CargoFeaturesDef {
16221614
#[derive(Deserialize, Debug, Clone)]
16231615
#[serde(rename_all = "snake_case")]
16241616
enum InvocationStrategy {
1625-
OnceInRoot,
1617+
Once,
16261618
PerWorkspace,
16271619
}
16281620

@@ -2042,9 +2034,9 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
20422034
},
20432035
"InvocationStrategy" => set! {
20442036
"type": "string",
2045-
"enum": ["per_workspace", "once_in_root"],
2037+
"enum": ["per_workspace", "once"],
20462038
"enumDescriptions": [
2047-
"The command will be executed for each workspace and `{manifest-path}` usages will be interpolated with the corresponding workspace manifests. If `{manifest-path}` is used, the commands will be executed in the project root, otherwise in the corresponding workspace roots.",
2039+
"The command will be executed for each workspace from the corresponding workspace root.",
20482040
"The command will be executed once in the project root."
20492041
],
20502042
},

crates/rust-analyzer/src/reload.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ impl GlobalState {
477477
| FlycheckConfig::CustomCommand { invocation_strategy, .. }) = config;
478478

479479
self.flycheck = match invocation_strategy {
480-
flycheck::InvocationStrategy::OnceInRoot => vec![FlycheckHandle::spawn(
480+
flycheck::InvocationStrategy::Once => vec![FlycheckHandle::spawn(
481481
0,
482482
Box::new(move |msg| sender.send(msg).unwrap()),
483483
config.clone(),

docs/user/generated_config.adoc

+6-14
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,9 @@ Run build scripts (`build.rs`) for more precise code analysis.
2828
+
2929
--
3030
Specifies the invocation strategy to use when running the build scripts command.
31-
If `per_workspace` is set, the command will be executed for each workspace and all
32-
occurrences of `$manifest_path` in the command will be replaced by the corresponding
33-
manifest path of the workspace that the command is being invoked for. If interpolation
34-
for the manifest path happens at least once, the commands will be executed from the
35-
project root, otherwise the commands will be executed from the corresponding workspace
36-
root.
37-
If `once_in_root` is set, the command will be executed once in the project root.
31+
If `per_workspace` is set, the command will be executed for each workspace from the
32+
corresponding workspace root.
33+
If `once` is set, the command will be executed once in the project root.
3834
This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
3935
is set.
4036
--
@@ -136,13 +132,9 @@ Set to `"all"` to pass `--all-features` to Cargo.
136132
+
137133
--
138134
Specifies the invocation strategy to use when running the checkOnSave command.
139-
If `per_workspace` is set, the command will be executed for each workspace and all
140-
occurrences of `$manifest_path` in the command will be replaced by the corresponding
141-
manifest path of the workspace that the command is being invoked for. If interpolation
142-
for the manifest path happens at least once, the commands will be executed from the
143-
project root, otherwise the commands will be executed from the corresponding workspace
144-
root.
145-
If `once_in_root` is set, the command will be executed once in the project root.
135+
If `per_workspace` is set, the command will be executed for each workspace from the
136+
corresponding workspace root.
137+
If `once` is set, the command will be executed once in the project root.
146138
This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
147139
is set.
148140
--

editors/code/package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -422,15 +422,15 @@
422422
"type": "boolean"
423423
},
424424
"rust-analyzer.cargo.buildScripts.invocationStrategy": {
425-
"markdownDescription": "Specifies the invocation strategy to use when running the build scripts command.\nIf `per_workspace` is set, the command will be executed for each workspace and all\noccurrences of `$manifest_path` in the command will be replaced by the corresponding\nmanifest path of the workspace that the command is being invoked for. If interpolation\nfor the manifest path happens at least once, the commands will be executed from the\nproject root, otherwise the commands will be executed from the corresponding workspace\nroot.\nIf `once_in_root` is set, the command will be executed once in the project root.\nThis config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`\nis set.",
425+
"markdownDescription": "Specifies the invocation strategy to use when running the build scripts command.\nIf `per_workspace` is set, the command will be executed for each workspace from the\ncorresponding workspace root.\nIf `once` is set, the command will be executed once in the project root.\nThis config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`\nis set.",
426426
"default": "per_workspace",
427427
"type": "string",
428428
"enum": [
429429
"per_workspace",
430-
"once_in_root"
430+
"once"
431431
],
432432
"enumDescriptions": [
433-
"The command will be executed for each workspace and `{manifest-path}` usages will be interpolated with the corresponding workspace manifests. If `{manifest-path}` is used, the commands will be executed in the project root, otherwise in the corresponding workspace roots.",
433+
"The command will be executed for each workspace from the corresponding workspace root.",
434434
"The command will be executed once in the project root."
435435
]
436436
},
@@ -560,15 +560,15 @@
560560
]
561561
},
562562
"rust-analyzer.checkOnSave.invocationStrategy": {
563-
"markdownDescription": "Specifies the invocation strategy to use when running the checkOnSave command.\nIf `per_workspace` is set, the command will be executed for each workspace and all\noccurrences of `$manifest_path` in the command will be replaced by the corresponding\nmanifest path of the workspace that the command is being invoked for. If interpolation\nfor the manifest path happens at least once, the commands will be executed from the\nproject root, otherwise the commands will be executed from the corresponding workspace\nroot.\nIf `once_in_root` is set, the command will be executed once in the project root.\nThis config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`\nis set.",
563+
"markdownDescription": "Specifies the invocation strategy to use when running the checkOnSave command.\nIf `per_workspace` is set, the command will be executed for each workspace from the\ncorresponding workspace root.\nIf `once` is set, the command will be executed once in the project root.\nThis config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`\nis set.",
564564
"default": "per_workspace",
565565
"type": "string",
566566
"enum": [
567567
"per_workspace",
568-
"once_in_root"
568+
"once"
569569
],
570570
"enumDescriptions": [
571-
"The command will be executed for each workspace and `{manifest-path}` usages will be interpolated with the corresponding workspace manifests. If `{manifest-path}` is used, the commands will be executed in the project root, otherwise in the corresponding workspace roots.",
571+
"The command will be executed for each workspace from the corresponding workspace root.",
572572
"The command will be executed once in the project root."
573573
]
574574
},

0 commit comments

Comments
 (0)