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<ActivePaneModifiers>,
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 ActivePaneModifiers {
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#[skip_serializing_none]
365#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug, PartialEq, Eq)]
366pub struct StatusBarSettingsContent {
367 /// Whether to show the status bar.
368 ///
369 /// Default: true
370 #[serde(rename = "experimental.show", default)]
371 pub show: Option<bool>,
372 /// Whether to display the active language button in the status bar.
373 ///
374 /// Default: true
375 pub active_language_button: Option<bool>,
376 /// Whether to show the cursor position button in the status bar.
377 ///
378 /// Default: true
379 pub cursor_position_button: Option<bool>,
380}
381
382#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom)]
383#[serde(rename_all = "snake_case")]
384pub enum AutosaveSetting {
385 /// Disable autosave.
386 Off,
387 /// Save after inactivity period of `milliseconds`.
388 AfterDelay { milliseconds: u64 },
389 /// Autosave when focus changes.
390 OnFocusChange,
391 /// Autosave when the active window changes.
392 OnWindowChange,
393}
394
395impl AutosaveSetting {
396 pub fn should_save_on_close(&self) -> bool {
397 matches!(
398 &self,
399 AutosaveSetting::OnFocusChange
400 | AutosaveSetting::OnWindowChange
401 | AutosaveSetting::AfterDelay { .. }
402 )
403 }
404}
405
406#[derive(
407 Copy,
408 Clone,
409 Debug,
410 Serialize,
411 Deserialize,
412 PartialEq,
413 Eq,
414 JsonSchema,
415 MergeFrom,
416 strum::VariantArray,
417 strum::VariantNames,
418)]
419#[serde(rename_all = "snake_case")]
420pub enum PaneSplitDirectionHorizontal {
421 Up,
422 Down,
423}
424
425#[derive(
426 Copy,
427 Clone,
428 Debug,
429 Serialize,
430 Deserialize,
431 PartialEq,
432 Eq,
433 JsonSchema,
434 MergeFrom,
435 strum::VariantArray,
436 strum::VariantNames,
437)]
438#[serde(rename_all = "snake_case")]
439pub enum PaneSplitDirectionVertical {
440 Left,
441 Right,
442}
443
444#[skip_serializing_none]
445#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Default)]
446#[serde(rename_all = "snake_case")]
447pub struct CenteredLayoutSettings {
448 /// The relative width of the left padding of the central pane from the
449 /// workspace when the centered layout is used.
450 ///
451 /// Default: 0.2
452 pub left_padding: Option<f32>,
453 // The relative width of the right padding of the central pane from the
454 // workspace when the centered layout is used.
455 ///
456 /// Default: 0.2
457 pub right_padding: Option<f32>,
458}
459
460#[derive(
461 Copy,
462 Clone,
463 Default,
464 Serialize,
465 Deserialize,
466 JsonSchema,
467 MergeFrom,
468 PartialEq,
469 Debug,
470 strum::VariantArray,
471 strum::VariantNames,
472)]
473#[serde(rename_all = "snake_case")]
474pub enum OnLastWindowClosed {
475 /// Match platform conventions by default, so don't quit on macOS, and quit on other platforms
476 #[default]
477 PlatformDefault,
478 /// Quit the application the last window is closed
479 QuitApp,
480}
481
482impl OnLastWindowClosed {
483 pub fn is_quit_app(&self) -> bool {
484 match self {
485 OnLastWindowClosed::PlatformDefault => false,
486 OnLastWindowClosed::QuitApp => true,
487 }
488 }
489}
490
491#[skip_serializing_none]
492#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug)]
493pub struct ProjectPanelSettingsContent {
494 /// Whether to show the project panel button in the status bar.
495 ///
496 /// Default: true
497 pub button: Option<bool>,
498 /// Whether to hide gitignore files in the project panel.
499 ///
500 /// Default: false
501 pub hide_gitignore: Option<bool>,
502 /// Customize default width (in pixels) taken by project panel
503 ///
504 /// Default: 240
505 pub default_width: Option<f32>,
506 /// The position of project panel
507 ///
508 /// Default: left
509 pub dock: Option<DockSide>,
510 /// Spacing between worktree entries in the project panel.
511 ///
512 /// Default: comfortable
513 pub entry_spacing: Option<ProjectPanelEntrySpacing>,
514 /// Whether to show file icons in the project panel.
515 ///
516 /// Default: true
517 pub file_icons: Option<bool>,
518 /// Whether to show folder icons or chevrons for directories in the project panel.
519 ///
520 /// Default: true
521 pub folder_icons: Option<bool>,
522 /// Whether to show the git status in the project panel.
523 ///
524 /// Default: true
525 pub git_status: Option<bool>,
526 /// Amount of indentation (in pixels) for nested items.
527 ///
528 /// Default: 20
529 pub indent_size: Option<f32>,
530 /// Whether to reveal it in the project panel automatically,
531 /// when a corresponding project entry becomes active.
532 /// Gitignored entries are never auto revealed.
533 ///
534 /// Default: true
535 pub auto_reveal_entries: Option<bool>,
536 /// Whether to fold directories automatically
537 /// when directory has only one directory inside.
538 ///
539 /// Default: true
540 pub auto_fold_dirs: Option<bool>,
541 /// Whether the project panel should open on startup.
542 ///
543 /// Default: true
544 pub starts_open: Option<bool>,
545 /// Scrollbar-related settings
546 pub scrollbar: Option<ScrollbarSettingsContent>,
547 /// Which files containing diagnostic errors/warnings to mark in the project panel.
548 ///
549 /// Default: all
550 pub show_diagnostics: Option<ShowDiagnostics>,
551 /// Settings related to indent guides in the project panel.
552 pub indent_guides: Option<ProjectPanelIndentGuidesSettings>,
553 /// Whether to hide the root entry when only one folder is open in the window.
554 ///
555 /// Default: false
556 pub hide_root: Option<bool>,
557 /// Whether to hide the hidden entries in the project panel.
558 ///
559 /// Default: false
560 pub hide_hidden: Option<bool>,
561 /// Whether to stick parent directories at top of the project panel.
562 ///
563 /// Default: true
564 pub sticky_scroll: Option<bool>,
565 /// Whether to enable drag-and-drop operations in the project panel.
566 ///
567 /// Default: true
568 pub drag_and_drop: Option<bool>,
569}
570
571#[derive(
572 Copy,
573 Clone,
574 Debug,
575 Default,
576 Serialize,
577 Deserialize,
578 JsonSchema,
579 MergeFrom,
580 PartialEq,
581 Eq,
582 strum::VariantArray,
583 strum::VariantNames,
584)]
585#[serde(rename_all = "snake_case")]
586pub enum ProjectPanelEntrySpacing {
587 /// Comfortable spacing of entries.
588 #[default]
589 Comfortable,
590 /// The standard spacing of entries.
591 Standard,
592}
593
594#[skip_serializing_none]
595#[derive(
596 Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq, Default,
597)]
598pub struct ProjectPanelIndentGuidesSettings {
599 pub show: Option<ShowIndentGuides>,
600}