1use std::num::NonZeroUsize;
2
3use collections::HashMap;
4use schemars::JsonSchema;
5use serde::{Deserialize, Serialize};
6use serde_with::skip_serializing_none;
7use settings_macros::MergeFrom;
8
9use crate::{DockPosition, DockSide, ScrollbarSettingsContent, ShowIndentGuides};
10
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]
13pub struct WorkspaceSettingsContent {
14 /// Active pane styling settings.
15 pub active_pane_modifiers: Option<ActivePanelModifiers>,
16 /// Layout mode for the bottom dock
17 ///
18 /// Default: contained
19 pub bottom_dock_layout: Option<BottomDockLayout>,
20 /// Direction to split horizontally.
21 ///
22 /// Default: "up"
23 pub pane_split_direction_horizontal: Option<PaneSplitDirectionHorizontal>,
24 /// Direction to split vertically.
25 ///
26 /// Default: "left"
27 pub pane_split_direction_vertical: Option<PaneSplitDirectionVertical>,
28 /// Centered layout related settings.
29 pub centered_layout: Option<CenteredLayoutSettings>,
30 /// Whether or not to prompt the user to confirm before closing the application.
31 ///
32 /// Default: false
33 pub confirm_quit: Option<bool>,
34 /// Whether or not to show the call status icon in the status bar.
35 ///
36 /// Default: true
37 pub show_call_status_icon: Option<bool>,
38 /// When to automatically save edited buffers.
39 ///
40 /// Default: off
41 pub autosave: Option<AutosaveSetting>,
42 /// Controls previous session restoration in freshly launched Zed instance.
43 /// Values: none, last_workspace, last_session
44 /// Default: last_session
45 pub restore_on_startup: Option<RestoreOnStartupBehavior>,
46 /// Whether to attempt to restore previous file's state when opening it again.
47 /// The state is stored per pane.
48 /// When disabled, defaults are applied instead of the state restoration.
49 ///
50 /// E.g. for editors, selections, folds and scroll positions are restored, if the same file is closed and, later, opened again in the same pane.
51 /// When disabled, a single selection in the very beginning of the file, zero scroll position and no folds state is used as a default.
52 ///
53 /// Default: true
54 pub restore_on_file_reopen: Option<bool>,
55 /// The size of the workspace split drop targets on the outer edges.
56 /// Given as a fraction that will be multiplied by the smaller dimension of the workspace.
57 ///
58 /// Default: `0.2` (20% of the smaller dimension of the workspace)
59 pub drop_target_size: Option<f32>,
60 /// Whether to close the window when using 'close active item' on a workspace with no tabs
61 ///
62 /// Default: auto ("on" on macOS, "off" otherwise)
63 pub when_closing_with_no_tabs: Option<CloseWindowWhenNoItems>,
64 /// Whether to use the system provided dialogs for Open and Save As.
65 /// When set to false, Zed will use the built-in keyboard-first pickers.
66 ///
67 /// Default: true
68 pub use_system_path_prompts: Option<bool>,
69 /// Whether to use the system provided prompts.
70 /// When set to false, Zed will use the built-in prompts.
71 /// Note that this setting has no effect on Linux, where Zed will always
72 /// use the built-in prompts.
73 ///
74 /// Default: true
75 pub use_system_prompts: Option<bool>,
76 /// Aliases for the command palette. When you type a key in this map,
77 /// it will be assumed to equal the value.
78 ///
79 /// Default: true
80 #[serde(default)]
81 pub command_aliases: HashMap<String, String>,
82 /// Maximum open tabs in a pane. Will not close an unsaved
83 /// tab. Set to `None` for unlimited tabs.
84 ///
85 /// Default: none
86 pub max_tabs: Option<NonZeroUsize>,
87 /// What to do when the last window is closed
88 ///
89 /// Default: auto (nothing on macOS, "app quit" otherwise)
90 pub on_last_window_closed: Option<OnLastWindowClosed>,
91 /// Whether to resize all the panels in a dock when resizing the dock.
92 ///
93 /// Default: ["left"]
94 pub resize_all_panels_in_dock: Option<Vec<DockPosition>>,
95 /// Whether to automatically close files that have been deleted on disk.
96 ///
97 /// Default: false
98 pub close_on_file_delete: Option<bool>,
99 /// Whether to allow windows to tab together based on the user’s tabbing preference (macOS only).
100 ///
101 /// Default: false
102 pub use_system_window_tabs: Option<bool>,
103 /// Whether to show padding for zoomed panels.
104 /// When enabled, zoomed bottom panels will have some top padding,
105 /// while zoomed left/right panels will have padding to the right/left (respectively).
106 ///
107 /// Default: true
108 pub zoomed_padding: Option<bool>,
109}
110
111#[skip_serializing_none]
112#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
113pub struct ItemSettingsContent {
114 /// Whether to show the Git file status on a tab item.
115 ///
116 /// Default: false
117 pub git_status: Option<bool>,
118 /// Position of the close button in a tab.
119 ///
120 /// Default: right
121 pub close_position: Option<ClosePosition>,
122 /// Whether to show the file icon for a tab.
123 ///
124 /// Default: false
125 pub file_icons: Option<bool>,
126 /// What to do after closing the current tab.
127 ///
128 /// Default: history
129 pub activate_on_close: Option<ActivateOnClose>,
130 /// Which files containing diagnostic errors/warnings to mark in the tabs.
131 /// This setting can take the following three values:
132 ///
133 /// Default: off
134 pub show_diagnostics: Option<ShowDiagnostics>,
135 /// Whether to always show the close button on tabs.
136 ///
137 /// Default: false
138 pub show_close_button: Option<ShowCloseButton>,
139}
140
141#[skip_serializing_none]
142#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
143pub struct PreviewTabsSettingsContent {
144 /// Whether to show opened editors as preview tabs.
145 /// Preview tabs do not stay open, are reused until explicitly set to be kept open opened (via double-click or editing) and show file names in italic.
146 ///
147 /// Default: true
148 pub enabled: Option<bool>,
149 /// Whether to open tabs in preview mode when selected from the file finder.
150 ///
151 /// Default: false
152 pub enable_preview_from_file_finder: Option<bool>,
153 /// Whether a preview tab gets replaced when code navigation is used to navigate away from the tab.
154 ///
155 /// Default: false
156 pub enable_preview_from_code_navigation: Option<bool>,
157}
158
159#[derive(
160 Copy,
161 Clone,
162 Debug,
163 PartialEq,
164 Default,
165 Serialize,
166 Deserialize,
167 JsonSchema,
168 MergeFrom,
169 strum::VariantArray,
170 strum::VariantNames,
171)]
172#[serde(rename_all = "lowercase")]
173pub enum ClosePosition {
174 Left,
175 #[default]
176 Right,
177}
178
179#[derive(
180 Copy,
181 Clone,
182 Debug,
183 PartialEq,
184 Default,
185 Serialize,
186 Deserialize,
187 JsonSchema,
188 MergeFrom,
189 strum::VariantArray,
190 strum::VariantNames,
191)]
192#[serde(rename_all = "lowercase")]
193pub enum ShowCloseButton {
194 Always,
195 #[default]
196 Hover,
197 Hidden,
198}
199
200#[derive(
201 Copy,
202 Clone,
203 Debug,
204 Default,
205 Serialize,
206 Deserialize,
207 JsonSchema,
208 MergeFrom,
209 PartialEq,
210 Eq,
211 strum::VariantArray,
212 strum::VariantNames,
213)]
214#[serde(rename_all = "snake_case")]
215pub enum ShowDiagnostics {
216 #[default]
217 Off,
218 Errors,
219 All,
220}
221
222#[derive(
223 Copy,
224 Clone,
225 Debug,
226 PartialEq,
227 Default,
228 Serialize,
229 Deserialize,
230 JsonSchema,
231 MergeFrom,
232 strum::VariantArray,
233 strum::VariantNames,
234)]
235#[serde(rename_all = "snake_case")]
236pub enum ActivateOnClose {
237 #[default]
238 History,
239 Neighbour,
240 LeftNeighbour,
241}
242
243#[skip_serializing_none]
244#[derive(Copy, Clone, PartialEq, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]
245#[serde(rename_all = "snake_case")]
246pub struct ActivePanelModifiers {
247 /// Size of the border surrounding the active pane.
248 /// When set to 0, the active pane doesn't have any border.
249 /// The border is drawn inset.
250 ///
251 /// Default: `0.0`
252 pub border_size: Option<f32>,
253 /// Opacity of inactive panels.
254 /// When set to 1.0, the inactive panes have the same opacity as the active one.
255 /// If set to 0, the inactive panes content will not be visible at all.
256 /// Values are clamped to the [0.0, 1.0] range.
257 ///
258 /// Default: `1.0`
259 pub inactive_opacity: Option<f32>,
260}
261
262#[derive(
263 Copy,
264 Clone,
265 Debug,
266 Default,
267 Serialize,
268 Deserialize,
269 PartialEq,
270 JsonSchema,
271 MergeFrom,
272 strum::VariantArray,
273 strum::VariantNames,
274)]
275#[serde(rename_all = "snake_case")]
276pub enum BottomDockLayout {
277 /// Contained between the left and right docks
278 #[default]
279 Contained,
280 /// Takes up the full width of the window
281 Full,
282 /// Extends under the left dock while snapping to the right dock
283 LeftAligned,
284 /// Extends under the right dock while snapping to the left dock
285 RightAligned,
286}
287
288#[derive(
289 Copy,
290 Clone,
291 PartialEq,
292 Default,
293 Serialize,
294 Deserialize,
295 JsonSchema,
296 MergeFrom,
297 Debug,
298 strum::VariantArray,
299 strum::VariantNames,
300)]
301#[serde(rename_all = "snake_case")]
302pub enum CloseWindowWhenNoItems {
303 /// Match platform conventions by default, so "on" on macOS and "off" everywhere else
304 #[default]
305 PlatformDefault,
306 /// Close the window when there are no tabs
307 CloseWindow,
308 /// Leave the window open when there are no tabs
309 KeepWindowOpen,
310}
311
312impl CloseWindowWhenNoItems {
313 pub fn should_close(&self) -> bool {
314 match self {
315 CloseWindowWhenNoItems::PlatformDefault => cfg!(target_os = "macos"),
316 CloseWindowWhenNoItems::CloseWindow => true,
317 CloseWindowWhenNoItems::KeepWindowOpen => false,
318 }
319 }
320}
321
322#[derive(
323 Copy,
324 Clone,
325 PartialEq,
326 Eq,
327 Default,
328 Serialize,
329 Deserialize,
330 JsonSchema,
331 MergeFrom,
332 Debug,
333 strum::VariantArray,
334 strum::VariantNames,
335)]
336#[serde(rename_all = "snake_case")]
337pub enum RestoreOnStartupBehavior {
338 /// Always start with an empty editor
339 None,
340 /// Restore the workspace that was closed last.
341 LastWorkspace,
342 /// Restore all workspaces that were open when quitting Zed.
343 #[default]
344 LastSession,
345}
346
347#[skip_serializing_none]
348#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug, PartialEq)]
349pub struct TabBarSettingsContent {
350 /// Whether or not to show the tab bar in the editor.
351 ///
352 /// Default: true
353 pub show: Option<bool>,
354 /// Whether or not to show the navigation history buttons in the tab bar.
355 ///
356 /// Default: true
357 pub show_nav_history_buttons: Option<bool>,
358 /// Whether or not to show the tab bar buttons.
359 ///
360 /// Default: true
361 pub show_tab_bar_buttons: Option<bool>,
362}
363
364#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom)]
365#[serde(rename_all = "snake_case")]
366pub enum AutosaveSetting {
367 /// Disable autosave.
368 Off,
369 /// Save after inactivity period of `milliseconds`.
370 AfterDelay { milliseconds: u64 },
371 /// Autosave when focus changes.
372 OnFocusChange,
373 /// Autosave when the active window changes.
374 OnWindowChange,
375}
376
377impl AutosaveSetting {
378 pub fn should_save_on_close(&self) -> bool {
379 matches!(
380 &self,
381 AutosaveSetting::OnFocusChange
382 | AutosaveSetting::OnWindowChange
383 | AutosaveSetting::AfterDelay { .. }
384 )
385 }
386}
387
388#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom)]
389#[serde(rename_all = "snake_case")]
390pub enum PaneSplitDirectionHorizontal {
391 Up,
392 Down,
393}
394
395#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom)]
396#[serde(rename_all = "snake_case")]
397pub enum PaneSplitDirectionVertical {
398 Left,
399 Right,
400}
401
402#[skip_serializing_none]
403#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)]
404#[serde(rename_all = "snake_case")]
405pub struct CenteredLayoutSettings {
406 /// The relative width of the left padding of the central pane from the
407 /// workspace when the centered layout is used.
408 ///
409 /// Default: 0.2
410 pub left_padding: Option<f32>,
411 // The relative width of the right padding of the central pane from the
412 // workspace when the centered layout is used.
413 ///
414 /// Default: 0.2
415 pub right_padding: Option<f32>,
416}
417
418#[derive(
419 Copy,
420 Clone,
421 Default,
422 Serialize,
423 Deserialize,
424 JsonSchema,
425 MergeFrom,
426 PartialEq,
427 Debug,
428 strum::VariantArray,
429 strum::VariantNames,
430)]
431#[serde(rename_all = "snake_case")]
432pub enum OnLastWindowClosed {
433 /// Match platform conventions by default, so don't quit on macOS, and quit on other platforms
434 #[default]
435 PlatformDefault,
436 /// Quit the application the last window is closed
437 QuitApp,
438}
439
440impl OnLastWindowClosed {
441 pub fn is_quit_app(&self) -> bool {
442 match self {
443 OnLastWindowClosed::PlatformDefault => false,
444 OnLastWindowClosed::QuitApp => true,
445 }
446 }
447}
448
449#[skip_serializing_none]
450#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug)]
451pub struct ProjectPanelSettingsContent {
452 /// Whether to show the project panel button in the status bar.
453 ///
454 /// Default: true
455 pub button: Option<bool>,
456 /// Whether to hide gitignore files in the project panel.
457 ///
458 /// Default: false
459 pub hide_gitignore: Option<bool>,
460 /// Customize default width (in pixels) taken by project panel
461 ///
462 /// Default: 240
463 pub default_width: Option<f32>,
464 /// The position of project panel
465 ///
466 /// Default: left
467 pub dock: Option<DockSide>,
468 /// Spacing between worktree entries in the project panel.
469 ///
470 /// Default: comfortable
471 pub entry_spacing: Option<ProjectPanelEntrySpacing>,
472 /// Whether to show file icons in the project panel.
473 ///
474 /// Default: true
475 pub file_icons: Option<bool>,
476 /// Whether to show folder icons or chevrons for directories in the project panel.
477 ///
478 /// Default: true
479 pub folder_icons: Option<bool>,
480 /// Whether to show the git status in the project panel.
481 ///
482 /// Default: true
483 pub git_status: Option<bool>,
484 /// Amount of indentation (in pixels) for nested items.
485 ///
486 /// Default: 20
487 pub indent_size: Option<f32>,
488 /// Whether to reveal it in the project panel automatically,
489 /// when a corresponding project entry becomes active.
490 /// Gitignored entries are never auto revealed.
491 ///
492 /// Default: true
493 pub auto_reveal_entries: Option<bool>,
494 /// Whether to fold directories automatically
495 /// when directory has only one directory inside.
496 ///
497 /// Default: true
498 pub auto_fold_dirs: Option<bool>,
499 /// Whether the project panel should open on startup.
500 ///
501 /// Default: true
502 pub starts_open: Option<bool>,
503 /// Scrollbar-related settings
504 pub scrollbar: Option<ScrollbarSettingsContent>,
505 /// Which files containing diagnostic errors/warnings to mark in the project panel.
506 ///
507 /// Default: all
508 pub show_diagnostics: Option<ShowDiagnostics>,
509 /// Settings related to indent guides in the project panel.
510 pub indent_guides: Option<ProjectPanelIndentGuidesSettings>,
511 /// Whether to hide the root entry when only one folder is open in the window.
512 ///
513 /// Default: false
514 pub hide_root: Option<bool>,
515 /// Whether to stick parent directories at top of the project panel.
516 ///
517 /// Default: true
518 pub sticky_scroll: Option<bool>,
519 /// Whether to enable drag-and-drop operations in the project panel.
520 ///
521 /// Default: true
522 pub drag_and_drop: Option<bool>,
523}
524
525#[derive(
526 Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq,
527)]
528#[serde(rename_all = "snake_case")]
529pub enum ProjectPanelEntrySpacing {
530 /// Comfortable spacing of entries.
531 #[default]
532 Comfortable,
533 /// The standard spacing of entries.
534 Standard,
535}
536
537#[skip_serializing_none]
538#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq)]
539pub struct ProjectPanelIndentGuidesSettings {
540 pub show: Option<ShowIndentGuides>,
541}