Fix targetDir config name

This commit is contained in:
Lukas Wirth 2024-02-23 21:50:44 +01:00 committed by Lukas Wirth
parent 83a1ad5bfe
commit c8fdcea85c

View File

@ -152,6 +152,13 @@ struct ConfigData {
// FIXME(@poliorcetics): move to multiple targets here too, but this will need more work
// than `checkOnSave_target`
cargo_target: Option<String> = "null",
/// Optional path to a rust-analyzer specific target directory.
/// This prevents rust-analyzer's `cargo check` and initial build-script and proc-macro
/// building from locking the `Cargo.lock` at the expense of duplicating build artifacts.
///
/// Set to `true` to use a subdirectory of the existing target directory or
/// set to a path relative to the workspace to use that path.
cargo_targetDir | rust_analyzerTargetDir: Option<TargetDirectory> = "null",
/// Unsets the implicit `#[cfg(test)]` for the specified crates.
cargo_unsetTest: Vec<String> = "[\"core\"]",
@ -518,14 +525,6 @@ struct ConfigData {
/// tests or binaries. For example, it may be `--release`.
runnables_extraArgs: Vec<String> = "[]",
/// Optional path to a rust-analyzer specific target directory.
/// This prevents rust-analyzer's `cargo check` from locking the `Cargo.lock`
/// at the expense of duplicating build artifacts.
///
/// Set to `true` to use a subdirectory of the existing target directory or
/// set to a path relative to the workspace to use that path.
rust_analyzerTargetDir: Option<TargetDirectory> = "null",
/// 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.
@ -1401,14 +1400,12 @@ pub fn flycheck(&self) -> FlycheckConfig {
}
}
// FIXME: This should be an AbsolutePathBuf
fn target_dir_from_config(&self) -> Option<PathBuf> {
self.data.rust_analyzerTargetDir.as_ref().and_then(|target_dir| match target_dir {
TargetDirectory::UseSubdirectory(yes) if *yes => {
Some(PathBuf::from("target/rust-analyzer"))
}
TargetDirectory::UseSubdirectory(_) => None,
TargetDirectory::Directory(dir) => Some(dir.clone()),
self.data.cargo_targetDir.as_ref().and_then(|target_dir| match target_dir {
TargetDirectory::UseSubdirectory(true) => Some(PathBuf::from("target/rust-analyzer")),
TargetDirectory::UseSubdirectory(false) => None,
TargetDirectory::Directory(dir) if dir.is_relative() => Some(dir.clone()),
TargetDirectory::Directory(_) => None,
})
}
@ -2745,7 +2742,7 @@ fn cargo_target_dir_unset() {
"rust": { "analyzerTargetDir": null }
}))
.unwrap();
assert_eq!(config.data.rust_analyzerTargetDir, None);
assert_eq!(config.data.cargo_targetDir, None);
assert!(
matches!(config.flycheck(), FlycheckConfig::CargoCommand { target_dir, .. } if target_dir.is_none())
);
@ -2764,10 +2761,7 @@ fn cargo_target_dir_subdir() {
"rust": { "analyzerTargetDir": true }
}))
.unwrap();
assert_eq!(
config.data.rust_analyzerTargetDir,
Some(TargetDirectory::UseSubdirectory(true))
);
assert_eq!(config.data.cargo_targetDir, Some(TargetDirectory::UseSubdirectory(true)));
assert!(
matches!(config.flycheck(), FlycheckConfig::CargoCommand { target_dir, .. } if target_dir == Some(PathBuf::from("target/rust-analyzer")))
);
@ -2787,7 +2781,7 @@ fn cargo_target_dir_relative_dir() {
}))
.unwrap();
assert_eq!(
config.data.rust_analyzerTargetDir,
config.data.cargo_targetDir,
Some(TargetDirectory::Directory(PathBuf::from("other_folder")))
);
assert!(