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