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