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