Skip to content

Commit 0b98d6d

Browse files
authored
Respect XDG_CACHE_HOME on Linux and Mac (#168)
Address #167 When the environmental variable XDG_CACHE_HOME is set, it takes precedence over the cache path rooted at HOME
1 parent b68357e commit 0b98d6d

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src/java.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl Extension for Java {
288288
self.lombok_jar_path(language_server_id, &configuration, worktree)?;
289289
let canonical_lombok_jar_path = path_to_string(current_dir.join(lombok_jar_path))?;
290290

291-
Some(format!("-javaagent:{}", canonical_lombok_jar_path))
291+
Some(format!("-javaagent:{canonical_lombok_jar_path}"))
292292
} else {
293293
None
294294
};

src/jdtls.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,15 +317,28 @@ fn get_jdtls_data_path(worktree: &Worktree) -> zed::Result<PathBuf> {
317317
// we fall back to the the extension's workdir, which may never get cleaned up.
318318
// In future we may want to deliberately manage caches to be able to force-clean them.
319319

320-
let mut env_iter = worktree.shell_env().into_iter();
320+
let env = worktree.shell_env();
321321
let base_cachedir = match current_platform().0 {
322-
Os::Mac => env_iter
323-
.find(|(k, _)| k == "HOME")
324-
.map(|(_, v)| PathBuf::from(v).join("Library").join("Caches")),
325-
Os::Linux => env_iter
326-
.find(|(k, _)| k == "HOME")
327-
.map(|(_, v)| PathBuf::from(v).join(".cache")),
328-
Os::Windows => env_iter
322+
Os::Mac => env
323+
.iter()
324+
.find(|(k, _)| k == "XDG_CACHE_HOME")
325+
.map(|(_, v)| PathBuf::from(v))
326+
.or_else(|| {
327+
env.iter()
328+
.find(|(k, _)| k == "HOME")
329+
.map(|(_, v)| PathBuf::from(v).join("Library").join("Caches"))
330+
}),
331+
Os::Linux => env
332+
.iter()
333+
.find(|(k, _)| k == "XDG_CACHE_HOME")
334+
.map(|(_, v)| PathBuf::from(v))
335+
.or_else(|| {
336+
env.iter()
337+
.find(|(k, _)| k == "HOME")
338+
.map(|(_, v)| PathBuf::from(v).join(".cache"))
339+
}),
340+
Os::Windows => env
341+
.iter()
329342
.find(|(k, _)| k == "APPDATA")
330343
.map(|(_, v)| PathBuf::from(v)),
331344
}

0 commit comments

Comments
 (0)