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