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, InactiveOpacity, 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 #[schemars(range(min = 0.0, max = 1.0))]
260 pub inactive_opacity: Option<InactiveOpacity>,
261}
262
263#[derive(
264 Copy,
265 Clone,
266 Debug,
267 Default,
268 Serialize,
269 Deserialize,
270 PartialEq,
271 JsonSchema,
272 MergeFrom,
273 strum::VariantArray,
274 strum::VariantNames,
275)]
276#[serde(rename_all = "snake_case")]
277pub enum BottomDockLayout {
278 /// Contained between the left and right docks
279 #[default]
280 Contained,
281 /// Takes up the full width of the window
282 Full,
283 /// Extends under the left dock while snapping to the right dock
284 LeftAligned,
285 /// Extends under the right dock while snapping to the left dock
286 RightAligned,
287}
288
289#[derive(
290 Copy,
291 Clone,
292 PartialEq,
293 Default,
294 Serialize,
295 Deserialize,
296 JsonSchema,
297 MergeFrom,
298 Debug,
299 strum::VariantArray,
300 strum::VariantNames,
301)]
302#[serde(rename_all = "snake_case")]
303pub enum CloseWindowWhenNoItems {
304 /// Match platform conventions by default, so "on" on macOS and "off" everywhere else
305 #[default]
306 PlatformDefault,
307 /// Close the window when there are no tabs
308 CloseWindow,
309 /// Leave the window open when there are no tabs
310 KeepWindowOpen,
311}
312
313impl CloseWindowWhenNoItems {
314 pub fn should_close(&self) -> bool {
315 match self {
316 CloseWindowWhenNoItems::PlatformDefault => cfg!(target_os = "macos"),
317 CloseWindowWhenNoItems::CloseWindow => true,
318 CloseWindowWhenNoItems::KeepWindowOpen => false,
319 }
320 }
321}
322
323#[derive(
324 Copy,
325 Clone,
326 PartialEq,
327 Eq,
328 Default,
329 Serialize,
330 Deserialize,
331 JsonSchema,
332 MergeFrom,
333 Debug,
334 strum::VariantArray,
335 strum::VariantNames,
336)]
337#[serde(rename_all = "snake_case")]
338pub enum RestoreOnStartupBehavior {
339 /// Always start with an empty editor
340 None,
341 /// Restore the workspace that was closed last.
342 LastWorkspace,
343 /// Restore all workspaces that were open when quitting Zed.
344 #[default]
345 LastSession,
346}
347
348#[skip_serializing_none]
349#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug, PartialEq)]
350pub struct TabBarSettingsContent {
351 /// Whether or not to show the tab bar in the editor.
352 ///
353 /// Default: true
354 pub show: Option<bool>,
355 /// Whether or not to show the navigation history buttons in the tab bar.
356 ///
357 /// Default: true
358 pub show_nav_history_buttons: Option<bool>,
359 /// Whether or not to show the tab bar buttons.
360 ///
361 /// Default: true
362 pub show_tab_bar_buttons: Option<bool>,
363}
364
365#[skip_serializing_none]
366#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug, PartialEq, Eq)]
367pub struct StatusBarSettingsContent {
368 /// Whether to show the status bar.
369 ///
370 /// Default: true
371 #[serde(rename = "experimental.show", default)]
372 pub show: Option<bool>,
373 /// Whether to display the active language button in the status bar.
374 ///
375 /// Default: true
376 pub active_language_button: Option<bool>,
377 /// Whether to show the cursor position button in the status bar.
378 ///
379 /// Default: true
380 pub cursor_position_button: Option<bool>,
381}
382
383#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom)]
384#[serde(rename_all = "snake_case")]
385pub enum AutosaveSetting {
386 /// Disable autosave.
387 Off,
388 /// Save after inactivity period of `milliseconds`.
389 AfterDelay { milliseconds: u64 },
390 /// Autosave when focus changes.
391 OnFocusChange,
392 /// Autosave when the active window changes.
393 OnWindowChange,
394}
395
396impl AutosaveSetting {
397 pub fn should_save_on_close(&self) -> bool {
398 matches!(
399 &self,
400 AutosaveSetting::OnFocusChange
401 | AutosaveSetting::OnWindowChange
402 | AutosaveSetting::AfterDelay { .. }
403 )
404 }
405}
406
407#[derive(
408 Copy,
409 Clone,
410 Debug,
411 Serialize,
412 Deserialize,
413 PartialEq,
414 Eq,
415 JsonSchema,
416 MergeFrom,
417 strum::VariantArray,
418 strum::VariantNames,
419)]
420#[serde(rename_all = "snake_case")]
421pub enum PaneSplitDirectionHorizontal {
422 Up,
423 Down,
424}
425
426#[derive(
427 Copy,
428 Clone,
429 Debug,
430 Serialize,
431 Deserialize,
432 PartialEq,
433 Eq,
434 JsonSchema,
435 MergeFrom,
436 strum::VariantArray,
437 strum::VariantNames,
438)]
439#[serde(rename_all = "snake_case")]
440pub enum PaneSplitDirectionVertical {
441 Left,
442 Right,
443}
444
445#[skip_serializing_none]
446#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Default)]
447#[serde(rename_all = "snake_case")]
448pub struct CenteredLayoutSettings {
449 /// The relative width of the left padding of the central pane from the
450 /// workspace when the centered layout is used.
451 ///
452 /// Default: 0.2
453 pub left_padding: Option<f32>,
454 // The relative width of the right padding of the central pane from the
455 // workspace when the centered layout is used.
456 ///
457 /// Default: 0.2
458 pub right_padding: Option<f32>,
459}
460
461#[derive(
462 Copy,
463 Clone,
464 Default,
465 Serialize,
466 Deserialize,
467 JsonSchema,
468 MergeFrom,
469 PartialEq,
470 Debug,
471 strum::VariantArray,
472 strum::VariantNames,
473)]
474#[serde(rename_all = "snake_case")]
475pub enum OnLastWindowClosed {
476 /// Match platform conventions by default, so don't quit on macOS, and quit on other platforms
477 #[default]
478 PlatformDefault,
479 /// Quit the application the last window is closed
480 QuitApp,
481}
482
483impl OnLastWindowClosed {
484 pub fn is_quit_app(&self) -> bool {
485 match self {
486 OnLastWindowClosed::PlatformDefault => false,
487 OnLastWindowClosed::QuitApp => true,
488 }
489 }
490}
491
492#[skip_serializing_none]
493#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug)]
494pub struct ProjectPanelSettingsContent {
495 /// Whether to show the project panel button in the status bar.
496 ///
497 /// Default: true
498 pub button: Option<bool>,
499 /// Whether to hide gitignore files in the project panel.
500 ///
501 /// Default: false
502 pub hide_gitignore: Option<bool>,
503 /// Customize default width (in pixels) taken by project panel
504 ///
505 /// Default: 240
506 pub default_width: Option<f32>,
507 /// The position of project panel
508 ///
509 /// Default: left
510 pub dock: Option<DockSide>,
511 /// Spacing between worktree entries in the project panel.
512 ///
513 /// Default: comfortable
514 pub entry_spacing: Option<ProjectPanelEntrySpacing>,
515 /// Whether to show file icons in the project panel.
516 ///
517 /// Default: true
518 pub file_icons: Option<bool>,
519 /// Whether to show folder icons or chevrons for directories in the project panel.
520 ///
521 /// Default: true
522 pub folder_icons: Option<bool>,
523 /// Whether to show the git status in the project panel.
524 ///
525 /// Default: true
526 pub git_status: Option<bool>,
527 /// Amount of indentation (in pixels) for nested items.
528 ///
529 /// Default: 20
530 pub indent_size: Option<f32>,
531 /// Whether to reveal it in the project panel automatically,
532 /// when a corresponding project entry becomes active.
533 /// Gitignored entries are never auto revealed.
534 ///
535 /// Default: true
536 pub auto_reveal_entries: Option<bool>,
537 /// Whether to fold directories automatically
538 /// when directory has only one directory inside.
539 ///
540 /// Default: true
541 pub auto_fold_dirs: Option<bool>,
542 /// Whether the project panel should open on startup.
543 ///
544 /// Default: true
545 pub starts_open: Option<bool>,
546 /// Scrollbar-related settings
547 pub scrollbar: Option<ScrollbarSettingsContent>,
548 /// Which files containing diagnostic errors/warnings to mark in the project panel.
549 ///
550 /// Default: all
551 pub show_diagnostics: Option<ShowDiagnostics>,
552 /// Settings related to indent guides in the project panel.
553 pub indent_guides: Option<ProjectPanelIndentGuidesSettings>,
554 /// Whether to hide the root entry when only one folder is open in the window.
555 ///
556 /// Default: false
557 pub hide_root: Option<bool>,
558 /// Whether to hide the hidden entries in the project panel.
559 ///
560 /// Default: false
561 pub hide_hidden: Option<bool>,
562 /// Whether to stick parent directories at top of the project panel.
563 ///
564 /// Default: true
565 pub sticky_scroll: Option<bool>,
566 /// Whether to enable drag-and-drop operations in the project panel.
567 ///
568 /// Default: true
569 pub drag_and_drop: Option<bool>,
570 /// Whether to automatically open files when pasting them in the project panel.
571 ///
572 /// Default: true
573 pub open_file_on_paste: Option<bool>,
574}
575
576#[derive(
577 Copy,
578 Clone,
579 Debug,
580 Default,
581 Serialize,
582 Deserialize,
583 JsonSchema,
584 MergeFrom,
585 PartialEq,
586 Eq,
587 strum::VariantArray,
588 strum::VariantNames,
589)]
590#[serde(rename_all = "snake_case")]
591pub enum ProjectPanelEntrySpacing {
592 /// Comfortable spacing of entries.
593 #[default]
594 Comfortable,
595 /// The standard spacing of entries.
596 Standard,
597}
598
599#[skip_serializing_none]
600#[derive(
601 Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq, Default,
602)]
603pub struct ProjectPanelIndentGuidesSettings {
604 pub show: Option<ShowIndentGuides>,
605}