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