settings.rs

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