From a649c3daf3785521dd387dd941a65a3c4905cd18 Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Sat, 21 Jun 2025 15:28:36 +0200 Subject: [PATCH] copilot: Fix config dir logic to support Flatpak environments (cherry-pick #32901) (#33159) Cherry-picked copilot: Fix config dir logic to support Flatpak environments (#32901) Closes #30784 In github copilot we were not handling the config path correctly for FLATPAK. * Only tested on mac don't have access to other platform. But this should work on other platform as well. It follows the similar pattern seen in zed config path resolution. - [x] Macos - [ ] Linux - [ ] Linux with Flatpak - [ ] Windows Release Notes: - Fix copilot config detection for flatpack Co-authored-by: Umesh Yadav <23421535+imumesh18@users.noreply.github.com> --- Cargo.lock | 1 + crates/copilot/Cargo.toml | 1 + crates/copilot/src/copilot_chat.rs | 13 ++++++++----- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d5a32e803a12e93405c88b7f7ad66b71d93fe740..63cc81619a14a3e1b5b59b2048fd12bee56df588 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3345,6 +3345,7 @@ dependencies = [ "collections", "command_palette_hooks", "ctor", + "dirs 4.0.0", "editor", "fs", "futures 0.3.31", diff --git a/crates/copilot/Cargo.toml b/crates/copilot/Cargo.toml index c859d912b416c4ef0dd00bb9735ff1d99230200e..234875d420bd035a1c2d0955a4a68d165ef702d1 100644 --- a/crates/copilot/Cargo.toml +++ b/crates/copilot/Cargo.toml @@ -29,6 +29,7 @@ chrono.workspace = true client.workspace = true collections.workspace = true command_palette_hooks.workspace = true +dirs.workspace = true fs.workspace = true futures.workspace = true gpui.workspace = true diff --git a/crates/copilot/src/copilot_chat.rs b/crates/copilot/src/copilot_chat.rs index 7e8240c942d2dc8a0e7fea029b6c6236badebaa4..a80ac5682cde668dff88a19c663cb06c6363e794 100644 --- a/crates/copilot/src/copilot_chat.rs +++ b/crates/copilot/src/copilot_chat.rs @@ -360,12 +360,15 @@ pub fn copilot_chat_config_dir() -> &'static PathBuf { static COPILOT_CHAT_CONFIG_DIR: OnceLock = OnceLock::new(); COPILOT_CHAT_CONFIG_DIR.get_or_init(|| { - if cfg!(target_os = "windows") { - home_dir().join("AppData").join("Local") + let config_dir = if cfg!(target_os = "windows") { + dirs::data_local_dir().expect("failed to determine LocalAppData directory") } else { - home_dir().join(".config") - } - .join("github-copilot") + std::env::var("XDG_CONFIG_HOME") + .map(PathBuf::from) + .unwrap_or_else(|_| home_dir().join(".config")) + }; + + config_dir.join("github-copilot") }) }