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