1mod language;
2mod terminal;
3mod theme;
4pub use language::*;
5pub use terminal::*;
6pub use theme::*;
7
8use std::env;
9
10use collections::HashMap;
11use gpui::{App, SharedString};
12use release_channel::ReleaseChannel;
13use schemars::JsonSchema;
14use serde::{Deserialize, Serialize};
15
16use crate::ActiveSettingsProfileName;
17
18#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
19pub struct SettingsContent {
20 #[serde(flatten)]
21 pub project: ProjectSettingsContent,
22
23 #[serde(flatten)]
24 pub theme: ThemeSettingsContent,
25
26 /// Configuration of audio in Zed.
27 pub audio: Option<AudioSettingsContent>,
28 pub auto_update: Option<bool>,
29
30 // todo!() comments?!
31 pub base_keymap: Option<BaseKeymapContent>,
32
33 /// The list of custom Git hosting providers.
34 pub git_hosting_providers: Option<Vec<GitHostingProviderConfig>>,
35
36 /// Whether or not to enable Helix mode.
37 ///
38 /// Default: false
39 pub helix_mode: Option<bool>,
40 /// A map of log scopes to the desired log level.
41 /// Useful for filtering out noisy logs or enabling more verbose logging.
42 ///
43 /// Example: {"log": {"client": "warn"}}
44 pub log: Option<HashMap<String, String>>,
45
46 pub proxy: Option<String>,
47
48 /// The URL of the Zed server to connect to.
49 pub server_url: Option<String>,
50
51 /// Control what info is collected by Zed.
52 pub telemetry: Option<TelemetrySettingsContent>,
53
54 /// Configuration of the terminal in Zed.
55 pub terminal: Option<TerminalSettingsContent>,
56
57 pub title_bar: Option<TitleBarSettingsContent>,
58
59 /// Whether or not to enable Vim mode.
60 ///
61 /// Default: false
62 pub vim_mode: Option<bool>,
63}
64
65impl SettingsContent {
66 pub fn languages_mut(&mut self) -> &mut HashMap<SharedString, LanguageSettingsContent> {
67 &mut self.project.all_languages.languages.0
68 }
69}
70
71// todo!() what should this be?
72#[derive(Debug, Default, Serialize, Deserialize, JsonSchema)]
73pub struct ServerSettingsContent {
74 #[serde(flatten)]
75 pub project: ProjectSettingsContent,
76}
77
78#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
79pub struct UserSettingsContent {
80 #[serde(flatten)]
81 pub content: SettingsContent,
82
83 pub dev: Option<SettingsContent>,
84 pub nightly: Option<SettingsContent>,
85 pub preview: Option<SettingsContent>,
86 pub stable: Option<SettingsContent>,
87
88 pub macos: Option<SettingsContent>,
89 pub windows: Option<SettingsContent>,
90 pub linux: Option<SettingsContent>,
91
92 #[serde(default)]
93 pub profiles: HashMap<String, SettingsContent>,
94}
95
96pub struct ExtensionsSettingsContent {
97 pub all_languages: AllLanguageSettingsContent,
98}
99
100impl UserSettingsContent {
101 pub fn for_release_channel(&self) -> Option<&SettingsContent> {
102 match *release_channel::RELEASE_CHANNEL {
103 ReleaseChannel::Dev => self.dev.as_ref(),
104 ReleaseChannel::Nightly => self.nightly.as_ref(),
105 ReleaseChannel::Preview => self.preview.as_ref(),
106 ReleaseChannel::Stable => self.stable.as_ref(),
107 }
108 }
109
110 pub fn for_os(&self) -> Option<&SettingsContent> {
111 match env::consts::OS {
112 "macos" => self.macos.as_ref(),
113 "linux" => self.linux.as_ref(),
114 "windows" => self.windows.as_ref(),
115 _ => None,
116 }
117 }
118
119 pub fn for_profile(&self, cx: &App) -> Option<&SettingsContent> {
120 let Some(active_profile) = cx.try_global::<ActiveSettingsProfileName>() else {
121 return None;
122 };
123 self.profiles.get(&active_profile.0)
124 }
125}
126
127/// Base key bindings scheme. Base keymaps can be overridden with user keymaps.
128///
129/// Default: VSCode
130#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default)]
131pub enum BaseKeymapContent {
132 #[default]
133 VSCode,
134 JetBrains,
135 SublimeText,
136 Atom,
137 TextMate,
138 Emacs,
139 Cursor,
140 None,
141}
142
143#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
144pub struct ProjectSettingsContent {
145 #[serde(flatten)]
146 pub all_languages: AllLanguageSettingsContent,
147
148 #[serde(flatten)]
149 pub worktree: WorktreeSettingsContent,
150}
151
152#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, Debug)]
153pub struct TitleBarSettingsContent {
154 /// Controls when the title bar is visible: "always" | "never" | "hide_in_full_screen".
155 ///
156 /// Default: "always"
157 pub show: Option<TitleBarVisibilityContent>,
158 /// Whether to show the branch icon beside branch switcher in the title bar.
159 ///
160 /// Default: false
161 pub show_branch_icon: Option<bool>,
162 /// Whether to show onboarding banners in the title bar.
163 ///
164 /// Default: true
165 pub show_onboarding_banner: Option<bool>,
166 /// Whether to show user avatar in the title bar.
167 ///
168 /// Default: true
169 pub show_user_picture: Option<bool>,
170 /// Whether to show the branch name button in the titlebar.
171 ///
172 /// Default: true
173 pub show_branch_name: Option<bool>,
174 /// Whether to show the project host and name in the titlebar.
175 ///
176 /// Default: true
177 pub show_project_items: Option<bool>,
178 /// Whether to show the sign in button in the title bar.
179 ///
180 /// Default: true
181 pub show_sign_in: Option<bool>,
182 /// Whether to show the menus in the title bar.
183 ///
184 /// Default: false
185 pub show_menus: Option<bool>,
186}
187
188#[derive(Copy, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Debug)]
189#[serde(rename_all = "snake_case")]
190pub enum TitleBarVisibilityContent {
191 Always,
192 Never,
193 HideInFullScreen,
194}
195
196/// Configuration of audio in Zed.
197#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
198pub struct AudioSettingsContent {
199 /// Opt into the new audio system.
200 #[serde(rename = "experimental.rodio_audio", default)]
201 pub rodio_audio: Option<bool>,
202 /// Requires 'rodio_audio: true'
203 ///
204 /// Use the new audio systems automatic gain control for your microphone.
205 /// This affects how loud you sound to others.
206 #[serde(rename = "experimental.control_input_volume", default)]
207 pub control_input_volume: Option<bool>,
208 /// Requires 'rodio_audio: true'
209 ///
210 /// Use the new audio systems automatic gain control on everyone in the
211 /// call. This makes call members who are too quite louder and those who are
212 /// too loud quieter. This only affects how things sound for you.
213 #[serde(rename = "experimental.control_output_volume", default)]
214 pub control_output_volume: Option<bool>,
215}
216
217/// A custom Git hosting provider.
218#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
219pub struct GitHostingProviderConfig {
220 /// The type of the provider.
221 ///
222 /// Must be one of `github`, `gitlab`, or `bitbucket`.
223 pub provider: GitHostingProviderKind,
224
225 /// The base URL for the provider (e.g., "https://code.corp.big.com").
226 pub base_url: String,
227
228 /// The display name for the provider (e.g., "BigCorp GitHub").
229 pub name: String,
230}
231
232#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
233#[serde(rename_all = "snake_case")]
234pub enum GitHostingProviderKind {
235 Github,
236 Gitlab,
237 Bitbucket,
238}
239
240#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
241pub struct WorktreeSettingsContent {
242 /// The displayed name of this project. If not set, the root directory name
243 /// will be displayed.
244 ///
245 /// Default: none
246 pub project_name: Option<String>,
247
248 /// Completely ignore files matching globs from `file_scan_exclusions`. Overrides
249 /// `file_scan_inclusions`.
250 ///
251 /// Default: [
252 /// "**/.git",
253 /// "**/.svn",
254 /// "**/.hg",
255 /// "**/.jj",
256 /// "**/CVS",
257 /// "**/.DS_Store",
258 /// "**/Thumbs.db",
259 /// "**/.classpath",
260 /// "**/.settings"
261 /// ]
262 pub file_scan_exclusions: Option<Vec<String>>,
263
264 /// Always include files that match these globs when scanning for files, even if they're
265 /// ignored by git. This setting is overridden by `file_scan_exclusions`.
266 /// Default: [
267 /// ".env*",
268 /// "docker-compose.*.yml",
269 /// ]
270 pub file_scan_inclusions: Option<Vec<String>>,
271
272 /// Treat the files matching these globs as `.env` files.
273 /// Default: [ "**/.env*" ]
274 pub private_files: Option<Vec<String>>,
275}
276/// Control what info is collected by Zed.
277#[derive(Default, Clone, Serialize, Deserialize, JsonSchema, Debug)]
278pub struct TelemetrySettingsContent {
279 /// Send debug info like crash reports.
280 ///
281 /// Default: true
282 pub diagnostics: Option<bool>,
283 /// Send anonymized usage data like what languages you're using Zed with.
284 ///
285 /// Default: true
286 pub metrics: Option<bool>,
287}