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