settings.rs

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