settings.rs

  1mod base_keymap_setting;
  2mod editable_setting_control;
  3mod keymap_file;
  4pub mod merge_from;
  5mod settings_content;
  6mod settings_file;
  7mod settings_json;
  8mod settings_store;
  9mod settings_ui_core;
 10mod vscode_import;
 11
 12pub use settings_content::*;
 13
 14use gpui::{App, Global};
 15use rust_embed::RustEmbed;
 16use std::{borrow::Cow, fmt, str};
 17use util::asset_str;
 18
 19pub use base_keymap_setting::*;
 20pub use editable_setting_control::*;
 21pub use keymap_file::{
 22    KeyBindingValidator, KeyBindingValidatorRegistration, KeybindSource, KeybindUpdateOperation,
 23    KeybindUpdateTarget, KeymapFile, KeymapFileLoadResult,
 24};
 25pub use settings_file::*;
 26pub use settings_json::*;
 27pub use settings_store::{
 28    InvalidSettingsError, LocalSettingsKind, Settings, SettingsKey, SettingsLocation, SettingsStore,
 29};
 30pub use settings_ui_core::*;
 31
 32pub use vscode_import::{VsCodeSettings, VsCodeSettingsSource};
 33
 34#[derive(Clone, Debug, PartialEq)]
 35pub struct ActiveSettingsProfileName(pub String);
 36
 37impl Global for ActiveSettingsProfileName {}
 38
 39#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, PartialOrd, Ord, serde::Serialize)]
 40pub struct WorktreeId(usize);
 41
 42impl From<WorktreeId> for usize {
 43    fn from(value: WorktreeId) -> Self {
 44        value.0
 45    }
 46}
 47
 48impl WorktreeId {
 49    pub fn from_usize(handle_id: usize) -> Self {
 50        Self(handle_id)
 51    }
 52
 53    pub fn from_proto(id: u64) -> Self {
 54        Self(id as usize)
 55    }
 56
 57    pub fn to_proto(self) -> u64 {
 58        self.0 as u64
 59    }
 60
 61    pub fn to_usize(self) -> usize {
 62        self.0
 63    }
 64}
 65
 66impl fmt::Display for WorktreeId {
 67    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 68        std::fmt::Display::fmt(&self.0, f)
 69    }
 70}
 71
 72#[derive(RustEmbed)]
 73#[folder = "../../assets"]
 74#[include = "settings/*"]
 75#[include = "keymaps/*"]
 76#[exclude = "*.DS_Store"]
 77pub struct SettingsAssets;
 78
 79pub fn init(cx: &mut App) {
 80    let settings = SettingsStore::new(cx, &default_settings());
 81    cx.set_global(settings);
 82    BaseKeymap::register(cx);
 83    SettingsStore::observe_active_settings_profile_name(cx).detach();
 84}
 85
 86pub fn default_settings() -> Cow<'static, str> {
 87    asset_str::<SettingsAssets>("settings/default.json")
 88}
 89
 90#[cfg(target_os = "macos")]
 91pub const DEFAULT_KEYMAP_PATH: &str = "keymaps/default-macos.json";
 92
 93#[cfg(target_os = "windows")]
 94pub const DEFAULT_KEYMAP_PATH: &str = "keymaps/default-windows.json";
 95
 96#[cfg(not(any(target_os = "macos", target_os = "windows")))]
 97pub const DEFAULT_KEYMAP_PATH: &str = "keymaps/default-linux.json";
 98
 99pub fn default_keymap() -> Cow<'static, str> {
100    asset_str::<SettingsAssets>(DEFAULT_KEYMAP_PATH)
101}
102
103pub const VIM_KEYMAP_PATH: &str = "keymaps/vim.json";
104
105pub fn vim_keymap() -> Cow<'static, str> {
106    asset_str::<SettingsAssets>(VIM_KEYMAP_PATH)
107}
108
109pub fn initial_user_settings_content() -> Cow<'static, str> {
110    asset_str::<SettingsAssets>("settings/initial_user_settings.json")
111}
112
113pub fn initial_server_settings_content() -> Cow<'static, str> {
114    asset_str::<SettingsAssets>("settings/initial_server_settings.json")
115}
116
117pub fn initial_project_settings_content() -> Cow<'static, str> {
118    asset_str::<SettingsAssets>("settings/initial_local_settings.json")
119}
120
121pub fn initial_keymap_content() -> Cow<'static, str> {
122    asset_str::<SettingsAssets>("keymaps/initial.json")
123}
124
125pub fn initial_tasks_content() -> Cow<'static, str> {
126    asset_str::<SettingsAssets>("settings/initial_tasks.json")
127}
128
129pub fn initial_debug_tasks_content() -> Cow<'static, str> {
130    asset_str::<SettingsAssets>("settings/initial_debug_tasks.json")
131}
132
133pub fn initial_local_debug_tasks_content() -> Cow<'static, str> {
134    asset_str::<SettingsAssets>("settings/initial_local_debug_tasks.json")
135}