1mod base_keymap_setting;
2mod content_into_gpui;
3mod editable_setting_control;
4mod editorconfig_store;
5mod keymap_file;
6mod settings_file;
7mod settings_store;
8mod vscode_import;
9
10pub use settings_macros::RegisterSetting;
11
12pub mod settings_content {
13 pub use ::settings_content::*;
14}
15
16pub mod fallible_options {
17 pub use ::settings_content::{FallibleOption, parse_json};
18}
19
20#[doc(hidden)]
21pub mod private {
22 pub use crate::settings_store::{RegisteredSetting, SettingValue};
23 pub use inventory;
24}
25
26use gpui::{App, Global};
27
28use rust_embed::RustEmbed;
29use std::env;
30use std::{borrow::Cow, fmt, str};
31use util::asset_str;
32
33pub use ::settings_content::*;
34pub use base_keymap_setting::*;
35pub use content_into_gpui::IntoGpui;
36pub use editable_setting_control::*;
37pub use editorconfig_store::{
38 Editorconfig, EditorconfigEvent, EditorconfigProperties, EditorconfigStore,
39};
40pub use keymap_file::{
41 KeyBindingValidator, KeyBindingValidatorRegistration, KeybindSource, KeybindUpdateOperation,
42 KeybindUpdateTarget, KeymapFile, KeymapFileLoadResult,
43};
44pub use settings_file::*;
45pub use settings_json::*;
46pub use settings_store::{
47 InvalidSettingsError, LSP_SETTINGS_SCHEMA_URL_PREFIX, LocalSettingsKind, LocalSettingsPath,
48 MigrationStatus, Settings, SettingsFile, SettingsJsonSchemaParams, SettingsKey,
49 SettingsLocation, SettingsParseResult, SettingsStore,
50};
51
52pub use vscode_import::{VsCodeSettings, VsCodeSettingsSource};
53
54pub use keymap_file::ActionSequence;
55
56#[derive(Clone, Debug, PartialEq)]
57pub struct ActiveSettingsProfileName(pub String);
58
59impl Global for ActiveSettingsProfileName {}
60
61pub trait UserSettingsContentExt {
62 fn for_profile(&self, cx: &App) -> Option<&SettingsContent>;
63 fn for_release_channel(&self) -> Option<&SettingsContent>;
64 fn for_os(&self) -> Option<&SettingsContent>;
65}
66
67impl UserSettingsContentExt for UserSettingsContent {
68 fn for_profile(&self, cx: &App) -> Option<&SettingsContent> {
69 let Some(active_profile) = cx.try_global::<ActiveSettingsProfileName>() else {
70 return None;
71 };
72 self.profiles.get(&active_profile.0)
73 }
74
75 fn for_release_channel(&self) -> Option<&SettingsContent> {
76 self.release_channel_overrides
77 .get_by_key(release_channel::RELEASE_CHANNEL.dev_name())
78 }
79
80 fn for_os(&self) -> Option<&SettingsContent> {
81 self.platform_overrides.get_by_key(env::consts::OS)
82 }
83}
84
85#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, PartialOrd, Ord, serde::Serialize)]
86pub struct WorktreeId(usize);
87
88impl From<WorktreeId> for usize {
89 fn from(value: WorktreeId) -> Self {
90 value.0
91 }
92}
93
94impl WorktreeId {
95 pub fn from_usize(handle_id: usize) -> Self {
96 Self(handle_id)
97 }
98
99 pub fn from_proto(id: u64) -> Self {
100 Self(id as usize)
101 }
102
103 pub fn to_proto(self) -> u64 {
104 self.0 as u64
105 }
106
107 pub fn to_usize(self) -> usize {
108 self.0
109 }
110}
111
112impl fmt::Display for WorktreeId {
113 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
114 std::fmt::Display::fmt(&self.0, f)
115 }
116}
117
118#[derive(RustEmbed)]
119#[folder = "../../assets"]
120#[include = "settings/*"]
121#[include = "keymaps/*"]
122#[exclude = "*.DS_Store"]
123pub struct SettingsAssets;
124
125pub fn init(cx: &mut App) {
126 let settings = SettingsStore::new(cx, &default_settings());
127 cx.set_global(settings);
128 SettingsStore::observe_active_settings_profile_name(cx).detach();
129}
130
131pub fn default_settings() -> Cow<'static, str> {
132 asset_str::<SettingsAssets>("settings/default.json")
133}
134
135pub fn default_semantic_token_rules() -> Cow<'static, str> {
136 asset_str::<SettingsAssets>("settings/default_semantic_token_rules.json")
137}
138
139#[cfg(target_os = "macos")]
140pub const DEFAULT_KEYMAP_PATH: &str = "keymaps/default-macos.json";
141
142#[cfg(target_os = "windows")]
143pub const DEFAULT_KEYMAP_PATH: &str = "keymaps/default-windows.json";
144
145#[cfg(not(any(target_os = "macos", target_os = "windows")))]
146pub const DEFAULT_KEYMAP_PATH: &str = "keymaps/default-linux.json";
147
148pub fn default_keymap() -> Cow<'static, str> {
149 asset_str::<SettingsAssets>(DEFAULT_KEYMAP_PATH)
150}
151
152pub const VIM_KEYMAP_PATH: &str = "keymaps/vim.json";
153
154pub fn vim_keymap() -> Cow<'static, str> {
155 asset_str::<SettingsAssets>(VIM_KEYMAP_PATH)
156}
157
158pub fn initial_user_settings_content() -> Cow<'static, str> {
159 asset_str::<SettingsAssets>("settings/initial_user_settings.json")
160}
161
162pub fn initial_server_settings_content() -> Cow<'static, str> {
163 asset_str::<SettingsAssets>("settings/initial_server_settings.json")
164}
165
166pub fn initial_project_settings_content() -> Cow<'static, str> {
167 asset_str::<SettingsAssets>("settings/initial_local_settings.json")
168}
169
170pub fn initial_keymap_content() -> Cow<'static, str> {
171 asset_str::<SettingsAssets>("keymaps/initial.json")
172}
173
174pub fn initial_tasks_content() -> Cow<'static, str> {
175 asset_str::<SettingsAssets>("settings/initial_tasks.json")
176}
177
178pub fn initial_debug_tasks_content() -> Cow<'static, str> {
179 asset_str::<SettingsAssets>("settings/initial_debug_tasks.json")
180}
181
182pub fn initial_local_debug_tasks_content() -> Cow<'static, str> {
183 asset_str::<SettingsAssets>("settings/initial_local_debug_tasks.json")
184}