Merge pull request #18827 from Veykril/push-zqsplmtwsxxk

minor: Honor `CARGO_TARGET_DIR` for cargo target dir config
This commit is contained in:
Lukas Wirth 2025-01-03 12:43:43 +00:00 committed by GitHub
commit 3d6300330d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2126,7 +2126,10 @@ impl Config {
fn target_dir_from_config(&self, source_root: Option<SourceRootId>) -> Option<Utf8PathBuf> {
self.cargo_targetDir(source_root).as_ref().and_then(|target_dir| match target_dir {
TargetDirectory::UseSubdirectory(true) => {
Some(Utf8PathBuf::from("target/rust-analyzer"))
let env_var = env::var("CARGO_TARGET_DIR").ok();
let mut path = Utf8PathBuf::from(env_var.as_deref().unwrap_or("target"));
path.push("rust-analyzer");
Some(path)
}
TargetDirectory::UseSubdirectory(false) => None,
TargetDirectory::Directory(dir) => Some(dir.clone()),