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