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