From d6e558e3c9ba0b0001aa690d147e115d20ca8fb5 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Fri, 2 Aug 2024 15:46:06 -0400 Subject: [PATCH] copilot: Colocate `copilot_chat_config_path` with the rest of the Copilot code (#15703) This PR moves the `copilot_chat_config_path` out of `paths` and into `copilot` with the rest of the Copilot code. Since this doesn't actually return a Zed path, it doesn't belong in `paths`. Release Notes: - N/A --- crates/copilot/src/copilot_chat.rs | 19 ++++++++++++++++++- crates/paths/src/paths.rs | 14 -------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/crates/copilot/src/copilot_chat.rs b/crates/copilot/src/copilot_chat.rs index 4fe76e6e51..a2fca980a5 100644 --- a/crates/copilot/src/copilot_chat.rs +++ b/crates/copilot/src/copilot_chat.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; +use std::sync::OnceLock; use std::{sync::Arc, time::Duration}; use anyhow::{anyhow, Result}; @@ -7,6 +9,7 @@ use futures::{io::BufReader, stream::BoxStream, AsyncBufReadExt, AsyncReadExt, S use gpui::{AppContext, AsyncAppContext, Global}; use http_client::{AsyncBody, HttpClient, Method, Request as HttpRequest}; use isahc::config::Configurable; +use paths::home_dir; use serde::{Deserialize, Serialize}; use settings::watch_config_file; use strum::EnumIter; @@ -164,6 +167,20 @@ pub fn init(fs: Arc, client: Arc, cx: &mut AppContext) { cx.set_global(GlobalCopilotChat(copilot_chat)); } +fn copilot_chat_config_path() -> &'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") + } else { + home_dir().join(".config") + } + .join("github-copilot") + .join("hosts.json") + }) +} + impl CopilotChat { pub fn global(cx: &AppContext) -> Option> { cx.try_global::() @@ -174,7 +191,7 @@ impl CopilotChat { let mut config_file_rx = watch_config_file( cx.background_executor(), fs, - paths::copilot_chat_config_path().clone(), + copilot_chat_config_path().clone(), ); cx.spawn(|cx| async move { diff --git a/crates/paths/src/paths.rs b/crates/paths/src/paths.rs index 1cbdd500c5..768be162d2 100644 --- a/crates/paths/src/paths.rs +++ b/crates/paths/src/paths.rs @@ -212,20 +212,6 @@ pub fn copilot_dir() -> &'static PathBuf { COPILOT_DIR.get_or_init(|| support_dir().join("copilot")) } -pub fn copilot_chat_config_path() -> &'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") - } else { - home_dir().join(".config") - } - .join("github-copilot") - .join("hosts.json") - }) -} - /// Returns the path to the Supermaven directory. pub fn supermaven_dir() -> &'static PathBuf { static SUPERMAVEN_DIR: OnceLock = OnceLock::new();