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