diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 8306571a3d..da1186d5bf 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -30,9 +30,6 @@ fn main() { let app = gpui::App::new(Assets).unwrap(); load_embedded_fonts(&app); - let zed_dir = dirs::home_dir() - .expect("failed to determine home directory") - .join(".zed"); let fs = Arc::new(RealFs); let themes = ThemeRegistry::new(Assets, app.font_cache()); let theme = themes.get(DEFAULT_THEME_NAME).unwrap(); @@ -52,7 +49,7 @@ fn main() { ..Default::default() }, ); - let settings_file = load_settings_file(&app, fs.clone(), zed_dir.join("settings.json")); + let settings_file = load_settings_file(&app, fs.clone()); let login_shell_env_loaded = if stdout_is_a_pty() { Task::ready(()) @@ -106,7 +103,7 @@ fn main() { refresh_window_on_settings_change(settings.clone(), cx); - languages.set_language_server_download_dir(zed_dir); + languages.set_language_server_download_dir(zed::ROOT_PATH.clone()); languages.set_theme(&settings.borrow().theme.editor.syntax); let app_state = Arc::new(AppState { @@ -233,17 +230,13 @@ fn load_embedded_fonts(app: &App) { .unwrap(); } -fn load_settings_file( - app: &App, - fs: Arc, - settings_path: PathBuf, -) -> oneshot::Receiver { +fn load_settings_file(app: &App, fs: Arc) -> oneshot::Receiver { let executor = app.background(); let (tx, rx) = oneshot::channel(); executor .clone() .spawn(async move { - let file = SettingsFile::new(fs, &executor, settings_path).await; + let file = SettingsFile::new(fs, &executor, zed::SETTINGS_PATH.clone()).await; tx.send(file).ok() }) .detach(); diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index db3781287d..43d37b6d98 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -16,20 +16,29 @@ use gpui::{ platform::{WindowBounds, WindowOptions}, ModelHandle, ViewContext, }; +use lazy_static::lazy_static; pub use lsp; use project::Project; pub use project::{self, fs}; use project_panel::ProjectPanel; -use std::sync::Arc; +use std::{path::PathBuf, sync::Arc}; pub use workspace; use workspace::{AppState, Workspace, WorkspaceParams}; action!(About); action!(Quit); +action!(OpenSettings); action!(AdjustBufferFontSize, f32); const MIN_FONT_SIZE: f32 = 6.0; +lazy_static! { + pub static ref ROOT_PATH: PathBuf = dirs::home_dir() + .expect("failed to determine home directory") + .join(".zed"); + pub static ref SETTINGS_PATH: PathBuf = ROOT_PATH.join("settings.json"); +} + pub fn init(app_state: &Arc, cx: &mut gpui::MutableAppContext) { cx.add_global_action(quit); cx.add_global_action({ @@ -40,15 +49,21 @@ pub fn init(app_state: &Arc, cx: &mut gpui::MutableAppContext) { settings_tx.borrow_mut().buffer_font_size = new_size; } }); + cx.add_action(open_settings); workspace::lsp_status::init(cx); cx.add_bindings(vec![ Binding::new("cmd-=", AdjustBufferFontSize(1.), None), Binding::new("cmd--", AdjustBufferFontSize(-1.), None), + Binding::new("cmd-,", OpenSettings, None), ]) } +fn open_settings(workspace: &mut Workspace, _: &OpenSettings, cx: &mut ViewContext) { + workspace.open_paths(&[SETTINGS_PATH.clone()], cx).detach(); +} + pub fn build_workspace( project: ModelHandle, app_state: &Arc,