mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 21:54:42 +00:00
Remove simplistic interpolation for manifest-path
This commit is contained in:
parent
7db50294a3
commit
46732369f4
7 changed files with 32 additions and 87 deletions
|
@ -23,7 +23,7 @@ pub use cargo_metadata::diagnostic::{
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
|
||||||
pub enum InvocationStrategy {
|
pub enum InvocationStrategy {
|
||||||
OnceInRoot,
|
Once,
|
||||||
#[default]
|
#[default]
|
||||||
PerWorkspace,
|
PerWorkspace,
|
||||||
}
|
}
|
||||||
|
@ -317,26 +317,10 @@ impl FlycheckActor {
|
||||||
(cmd, args, invocation_strategy)
|
(cmd, args, invocation_strategy)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if let InvocationStrategy::PerWorkspace = invocation_strategy {
|
match invocation_strategy {
|
||||||
let mut with_manifest_path = false;
|
InvocationStrategy::PerWorkspace => cmd.current_dir(&self.root),
|
||||||
for arg in args {
|
InvocationStrategy::Once => cmd.args(args),
|
||||||
if let Some(_) = arg.find("$manifest_path") {
|
};
|
||||||
with_manifest_path = true;
|
|
||||||
cmd.arg(arg.replace(
|
|
||||||
"$manifest_path",
|
|
||||||
&self.root.join("Cargo.toml").display().to_string(),
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
cmd.arg(arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !with_manifest_path {
|
|
||||||
cmd.current_dir(&self.root);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
cmd.args(args);
|
|
||||||
}
|
|
||||||
cmd
|
cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,30 +62,7 @@ impl WorkspaceBuildScripts {
|
||||||
let mut cmd = match config.run_build_script_command.as_deref() {
|
let mut cmd = match config.run_build_script_command.as_deref() {
|
||||||
Some([program, args @ ..]) => {
|
Some([program, args @ ..]) => {
|
||||||
let mut cmd = Command::new(program);
|
let mut cmd = Command::new(program);
|
||||||
|
cmd.args(args);
|
||||||
// FIXME: strategy and workspace root are coupled, express that in code
|
|
||||||
if let (InvocationStrategy::PerWorkspace, Some(workspace_root)) =
|
|
||||||
(config.invocation_strategy, workspace_root)
|
|
||||||
{
|
|
||||||
let mut with_manifest_path = false;
|
|
||||||
for arg in args {
|
|
||||||
if let Some(_) = arg.find("$manifest_path") {
|
|
||||||
with_manifest_path = true;
|
|
||||||
cmd.arg(arg.replace(
|
|
||||||
"$manifest_path",
|
|
||||||
&workspace_root.join("Cargo.toml").display().to_string(),
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
cmd.arg(arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !with_manifest_path {
|
|
||||||
cmd.current_dir(workspace_root);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
cmd.args(args);
|
|
||||||
}
|
|
||||||
cmd
|
cmd
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -176,7 +153,7 @@ impl WorkspaceBuildScripts {
|
||||||
workspaces: &[&CargoWorkspace],
|
workspaces: &[&CargoWorkspace],
|
||||||
progress: &dyn Fn(String),
|
progress: &dyn Fn(String),
|
||||||
) -> io::Result<Vec<WorkspaceBuildScripts>> {
|
) -> io::Result<Vec<WorkspaceBuildScripts>> {
|
||||||
assert_eq!(config.invocation_strategy, InvocationStrategy::OnceInRoot);
|
assert_eq!(config.invocation_strategy, InvocationStrategy::Once);
|
||||||
let cmd = Self::build_command(config, None)?;
|
let cmd = Self::build_command(config, None)?;
|
||||||
// NB: Cargo.toml could have been modified between `cargo metadata` and
|
// NB: Cargo.toml could have been modified between `cargo metadata` and
|
||||||
// `cargo check`. We shouldn't assume that package ids we see here are
|
// `cargo check`. We shouldn't assume that package ids we see here are
|
||||||
|
|
|
@ -160,7 +160,7 @@ fn utf8_stdout(mut cmd: Command) -> Result<String> {
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
|
||||||
pub enum InvocationStrategy {
|
pub enum InvocationStrategy {
|
||||||
OnceInRoot,
|
Once,
|
||||||
#[default]
|
#[default]
|
||||||
PerWorkspace,
|
PerWorkspace,
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,13 +70,9 @@ config_data! {
|
||||||
/// Run build scripts (`build.rs`) for more precise code analysis.
|
/// Run build scripts (`build.rs`) for more precise code analysis.
|
||||||
cargo_buildScripts_enable: bool = "true",
|
cargo_buildScripts_enable: bool = "true",
|
||||||
/// Specifies the invocation strategy to use when running the build scripts command.
|
/// Specifies the invocation strategy to use when running the build scripts command.
|
||||||
/// If `per_workspace` is set, the command will be executed for each workspace and all
|
/// If `per_workspace` is set, the command will be executed for each workspace from the
|
||||||
/// occurrences of `$manifest_path` in the command will be replaced by the corresponding
|
/// corresponding workspace root.
|
||||||
/// manifest path of the workspace that the command is being invoked for. If interpolation
|
/// If `once` is set, the command will be executed once in the project root.
|
||||||
/// for the manifest path happens at least once, the commands will be executed from the
|
|
||||||
/// project root, otherwise the commands will be executed from the corresponding workspace
|
|
||||||
/// root.
|
|
||||||
/// If `once_in_root` is set, the command will be executed once in the project root.
|
|
||||||
/// This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
|
/// This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
|
||||||
/// is set.
|
/// is set.
|
||||||
cargo_buildScripts_invocationStrategy: InvocationStrategy = "\"per_workspace\"",
|
cargo_buildScripts_invocationStrategy: InvocationStrategy = "\"per_workspace\"",
|
||||||
|
@ -134,13 +130,9 @@ config_data! {
|
||||||
/// Set to `"all"` to pass `--all-features` to Cargo.
|
/// Set to `"all"` to pass `--all-features` to Cargo.
|
||||||
checkOnSave_features: Option<CargoFeaturesDef> = "null",
|
checkOnSave_features: Option<CargoFeaturesDef> = "null",
|
||||||
/// Specifies the invocation strategy to use when running the checkOnSave command.
|
/// Specifies the invocation strategy to use when running the checkOnSave command.
|
||||||
/// If `per_workspace` is set, the command will be executed for each workspace and all
|
/// If `per_workspace` is set, the command will be executed for each workspace from the
|
||||||
/// occurrences of `$manifest_path` in the command will be replaced by the corresponding
|
/// corresponding workspace root.
|
||||||
/// manifest path of the workspace that the command is being invoked for. If interpolation
|
/// If `once` is set, the command will be executed once in the project root.
|
||||||
/// for the manifest path happens at least once, the commands will be executed from the
|
|
||||||
/// project root, otherwise the commands will be executed from the corresponding workspace
|
|
||||||
/// root.
|
|
||||||
/// If `once_in_root` is set, the command will be executed once in the project root.
|
|
||||||
/// This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
|
/// This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
|
||||||
/// is set.
|
/// is set.
|
||||||
checkOnSave_invocationStrategy: InvocationStrategy = "\"per_workspace\"",
|
checkOnSave_invocationStrategy: InvocationStrategy = "\"per_workspace\"",
|
||||||
|
@ -1079,7 +1071,7 @@ impl Config {
|
||||||
unset_test_crates: UnsetTestCrates::Only(self.data.cargo_unsetTest.clone()),
|
unset_test_crates: UnsetTestCrates::Only(self.data.cargo_unsetTest.clone()),
|
||||||
wrap_rustc_in_build_scripts: self.data.cargo_buildScripts_useRustcWrapper,
|
wrap_rustc_in_build_scripts: self.data.cargo_buildScripts_useRustcWrapper,
|
||||||
invocation_strategy: match self.data.cargo_buildScripts_invocationStrategy {
|
invocation_strategy: match self.data.cargo_buildScripts_invocationStrategy {
|
||||||
InvocationStrategy::OnceInRoot => project_model::InvocationStrategy::OnceInRoot,
|
InvocationStrategy::Once => project_model::InvocationStrategy::Once,
|
||||||
InvocationStrategy::PerWorkspace => project_model::InvocationStrategy::PerWorkspace,
|
InvocationStrategy::PerWorkspace => project_model::InvocationStrategy::PerWorkspace,
|
||||||
},
|
},
|
||||||
run_build_script_command: self.data.cargo_buildScripts_overrideCommand.clone(),
|
run_build_script_command: self.data.cargo_buildScripts_overrideCommand.clone(),
|
||||||
|
@ -1106,7 +1098,7 @@ impl Config {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let invocation_strategy = match self.data.checkOnSave_invocationStrategy {
|
let invocation_strategy = match self.data.checkOnSave_invocationStrategy {
|
||||||
InvocationStrategy::OnceInRoot => flycheck::InvocationStrategy::OnceInRoot,
|
InvocationStrategy::Once => flycheck::InvocationStrategy::Once,
|
||||||
InvocationStrategy::PerWorkspace => flycheck::InvocationStrategy::PerWorkspace,
|
InvocationStrategy::PerWorkspace => flycheck::InvocationStrategy::PerWorkspace,
|
||||||
};
|
};
|
||||||
let flycheck_config = match &self.data.checkOnSave_overrideCommand {
|
let flycheck_config = match &self.data.checkOnSave_overrideCommand {
|
||||||
|
@ -1622,7 +1614,7 @@ enum CargoFeaturesDef {
|
||||||
#[derive(Deserialize, Debug, Clone)]
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
enum InvocationStrategy {
|
enum InvocationStrategy {
|
||||||
OnceInRoot,
|
Once,
|
||||||
PerWorkspace,
|
PerWorkspace,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2042,9 +2034,9 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
|
||||||
},
|
},
|
||||||
"InvocationStrategy" => set! {
|
"InvocationStrategy" => set! {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["per_workspace", "once_in_root"],
|
"enum": ["per_workspace", "once"],
|
||||||
"enumDescriptions": [
|
"enumDescriptions": [
|
||||||
"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.",
|
"The command will be executed for each workspace from the corresponding workspace root.",
|
||||||
"The command will be executed once in the project root."
|
"The command will be executed once in the project root."
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
@ -477,7 +477,7 @@ impl GlobalState {
|
||||||
| FlycheckConfig::CustomCommand { invocation_strategy, .. }) = config;
|
| FlycheckConfig::CustomCommand { invocation_strategy, .. }) = config;
|
||||||
|
|
||||||
self.flycheck = match invocation_strategy {
|
self.flycheck = match invocation_strategy {
|
||||||
flycheck::InvocationStrategy::OnceInRoot => vec![FlycheckHandle::spawn(
|
flycheck::InvocationStrategy::Once => vec![FlycheckHandle::spawn(
|
||||||
0,
|
0,
|
||||||
Box::new(move |msg| sender.send(msg).unwrap()),
|
Box::new(move |msg| sender.send(msg).unwrap()),
|
||||||
config.clone(),
|
config.clone(),
|
||||||
|
|
|
@ -28,13 +28,9 @@ Run build scripts (`build.rs`) for more precise code analysis.
|
||||||
+
|
+
|
||||||
--
|
--
|
||||||
Specifies the invocation strategy to use when running the build scripts command.
|
Specifies the invocation strategy to use when running the build scripts command.
|
||||||
If `per_workspace` is set, the command will be executed for each workspace and all
|
If `per_workspace` is set, the command will be executed for each workspace from the
|
||||||
occurrences of `$manifest_path` in the command will be replaced by the corresponding
|
corresponding workspace root.
|
||||||
manifest path of the workspace that the command is being invoked for. If interpolation
|
If `once` is set, the command will be executed once in the project root.
|
||||||
for the manifest path happens at least once, the commands will be executed from the
|
|
||||||
project root, otherwise the commands will be executed from the corresponding workspace
|
|
||||||
root.
|
|
||||||
If `once_in_root` is set, the command will be executed once in the project root.
|
|
||||||
This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
|
This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
|
||||||
is set.
|
is set.
|
||||||
--
|
--
|
||||||
|
@ -136,13 +132,9 @@ Set to `"all"` to pass `--all-features` to Cargo.
|
||||||
+
|
+
|
||||||
--
|
--
|
||||||
Specifies the invocation strategy to use when running the checkOnSave command.
|
Specifies the invocation strategy to use when running the checkOnSave command.
|
||||||
If `per_workspace` is set, the command will be executed for each workspace and all
|
If `per_workspace` is set, the command will be executed for each workspace from the
|
||||||
occurrences of `$manifest_path` in the command will be replaced by the corresponding
|
corresponding workspace root.
|
||||||
manifest path of the workspace that the command is being invoked for. If interpolation
|
If `once` is set, the command will be executed once in the project root.
|
||||||
for the manifest path happens at least once, the commands will be executed from the
|
|
||||||
project root, otherwise the commands will be executed from the corresponding workspace
|
|
||||||
root.
|
|
||||||
If `once_in_root` is set, the command will be executed once in the project root.
|
|
||||||
This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
|
This config only has an effect when `#rust-analyzer.cargo.buildScripts.overrideCommand#`
|
||||||
is set.
|
is set.
|
||||||
--
|
--
|
||||||
|
|
|
@ -422,15 +422,15 @@
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
"rust-analyzer.cargo.buildScripts.invocationStrategy": {
|
"rust-analyzer.cargo.buildScripts.invocationStrategy": {
|
||||||
"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.",
|
"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.",
|
||||||
"default": "per_workspace",
|
"default": "per_workspace",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": [
|
"enum": [
|
||||||
"per_workspace",
|
"per_workspace",
|
||||||
"once_in_root"
|
"once"
|
||||||
],
|
],
|
||||||
"enumDescriptions": [
|
"enumDescriptions": [
|
||||||
"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.",
|
"The command will be executed for each workspace from the corresponding workspace root.",
|
||||||
"The command will be executed once in the project root."
|
"The command will be executed once in the project root."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -560,15 +560,15 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"rust-analyzer.checkOnSave.invocationStrategy": {
|
"rust-analyzer.checkOnSave.invocationStrategy": {
|
||||||
"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.",
|
"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.",
|
||||||
"default": "per_workspace",
|
"default": "per_workspace",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": [
|
"enum": [
|
||||||
"per_workspace",
|
"per_workspace",
|
||||||
"once_in_root"
|
"once"
|
||||||
],
|
],
|
||||||
"enumDescriptions": [
|
"enumDescriptions": [
|
||||||
"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.",
|
"The command will be executed for each workspace from the corresponding workspace root.",
|
||||||
"The command will be executed once in the project root."
|
"The command will be executed once in the project root."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue