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