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