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