workspace.rs

  1use std::num::NonZeroUsize;
  2
  3use collections::HashMap;
  4use schemars::JsonSchema;
  5use serde::{Deserialize, Serialize};
  6use settings_macros::{MergeFrom, with_fallible_options};
  7
  8use crate::{
  9    CenteredPaddingSettings, DelayMs, DockPosition, DockSide, InactiveOpacity,
 10    ScrollbarSettingsContent, ShowIndentGuides, serialize_optional_f32_with_two_decimal_places,
 11};
 12
 13#[with_fallible_options]
 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: empty_tab, last_workspace, last_session, launchpad
 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    #[serde(serialize_with = "serialize_optional_f32_with_two_decimal_places")]
 62    pub drop_target_size: Option<f32>,
 63    /// Whether to close the window when using 'close active item' on a workspace with no tabs
 64    ///
 65    /// Default: auto ("on" on macOS, "off" otherwise)
 66    pub when_closing_with_no_tabs: Option<CloseWindowWhenNoItems>,
 67    /// Whether to use the system provided dialogs for Open and Save As.
 68    /// When set to false, Zed will use the built-in keyboard-first pickers.
 69    ///
 70    /// Default: true
 71    pub use_system_path_prompts: Option<bool>,
 72    /// Whether to use the system provided prompts.
 73    /// When set to false, Zed will use the built-in prompts.
 74    /// Note that this setting has no effect on Linux, where Zed will always
 75    /// use the built-in prompts.
 76    ///
 77    /// Default: true
 78    pub use_system_prompts: Option<bool>,
 79    /// Aliases for the command palette. When you type a key in this map,
 80    /// it will be assumed to equal the value.
 81    ///
 82    /// Default: true
 83    #[serde(default)]
 84    pub command_aliases: HashMap<String, String>,
 85    /// Maximum open tabs in a pane. Will not close an unsaved
 86    /// tab. Set to `None` for unlimited tabs.
 87    ///
 88    /// Default: none
 89    pub max_tabs: Option<NonZeroUsize>,
 90    /// What to do when the last window is closed
 91    ///
 92    /// Default: auto (nothing on macOS, "app quit" otherwise)
 93    pub on_last_window_closed: Option<OnLastWindowClosed>,
 94    /// Whether to resize all the panels in a dock when resizing the dock.
 95    ///
 96    /// Default: ["left"]
 97    pub resize_all_panels_in_dock: Option<Vec<DockPosition>>,
 98    /// Whether to automatically close files that have been deleted on disk.
 99    ///
100    /// Default: false
101    pub close_on_file_delete: Option<bool>,
102    /// Whether to allow windows to tab together based on the user’s tabbing preference (macOS only).
103    ///
104    /// Default: false
105    pub use_system_window_tabs: Option<bool>,
106    /// Whether to show padding for zoomed panels.
107    /// When enabled, zoomed bottom panels will have some top padding,
108    /// while zoomed left/right panels will have padding to the right/left (respectively).
109    ///
110    /// Default: true
111    pub zoomed_padding: Option<bool>,
112    /// What draws window decorations/titlebar, the client application (Zed) or display server
113    /// Default: client
114    pub window_decorations: Option<WindowDecorations>,
115}
116
117#[with_fallible_options]
118#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
119pub struct ItemSettingsContent {
120    /// Whether to show the Git file status on a tab item.
121    ///
122    /// Default: false
123    pub git_status: Option<bool>,
124    /// Position of the close button in a tab.
125    ///
126    /// Default: right
127    pub close_position: Option<ClosePosition>,
128    /// Whether to show the file icon for a tab.
129    ///
130    /// Default: false
131    pub file_icons: Option<bool>,
132    /// What to do after closing the current tab.
133    ///
134    /// Default: history
135    pub activate_on_close: Option<ActivateOnClose>,
136    /// Which files containing diagnostic errors/warnings to mark in the tabs.
137    /// This setting can take the following three values:
138    ///
139    /// Default: off
140    pub show_diagnostics: Option<ShowDiagnostics>,
141    /// Whether to always show the close button on tabs.
142    ///
143    /// Default: false
144    pub show_close_button: Option<ShowCloseButton>,
145}
146
147#[with_fallible_options]
148#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
149pub struct PreviewTabsSettingsContent {
150    /// Whether to show opened editors as preview tabs.
151    /// 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.
152    ///
153    /// Default: true
154    pub enabled: Option<bool>,
155    /// Whether to open tabs in preview mode when opened from the project panel with a single click.
156    ///
157    /// Default: true
158    pub enable_preview_from_project_panel: Option<bool>,
159    /// Whether to open tabs in preview mode when selected from the file finder.
160    ///
161    /// Default: false
162    pub enable_preview_from_file_finder: Option<bool>,
163    /// Whether to open tabs in preview mode when opened from a multibuffer.
164    ///
165    /// Default: true
166    pub enable_preview_from_multibuffer: Option<bool>,
167    /// Whether to open tabs in preview mode when code navigation is used to open a multibuffer.
168    ///
169    /// Default: false
170    pub enable_preview_multibuffer_from_code_navigation: Option<bool>,
171    /// Whether to open tabs in preview mode when code navigation is used to open a single file.
172    ///
173    /// Default: true
174    pub enable_preview_file_from_code_navigation: Option<bool>,
175    /// Whether to keep tabs in preview mode when code navigation is used to navigate away from them.
176    /// If `enable_preview_file_from_code_navigation` or `enable_preview_multibuffer_from_code_navigation` is also true, the new tab may replace the existing one.
177    ///
178    /// Default: false
179    pub enable_keep_preview_on_code_navigation: Option<bool>,
180}
181
182#[derive(
183    Copy,
184    Clone,
185    Debug,
186    PartialEq,
187    Default,
188    Serialize,
189    Deserialize,
190    JsonSchema,
191    MergeFrom,
192    strum::VariantArray,
193    strum::VariantNames,
194)]
195#[serde(rename_all = "lowercase")]
196pub enum ClosePosition {
197    Left,
198    #[default]
199    Right,
200}
201
202#[derive(
203    Copy,
204    Clone,
205    Debug,
206    PartialEq,
207    Default,
208    Serialize,
209    Deserialize,
210    JsonSchema,
211    MergeFrom,
212    strum::VariantArray,
213    strum::VariantNames,
214)]
215#[serde(rename_all = "lowercase")]
216pub enum ShowCloseButton {
217    Always,
218    #[default]
219    Hover,
220    Hidden,
221}
222
223#[derive(
224    Copy,
225    Clone,
226    Debug,
227    Default,
228    Serialize,
229    Deserialize,
230    JsonSchema,
231    MergeFrom,
232    PartialEq,
233    Eq,
234    strum::VariantArray,
235    strum::VariantNames,
236)]
237#[serde(rename_all = "snake_case")]
238pub enum ShowDiagnostics {
239    #[default]
240    Off,
241    Errors,
242    All,
243}
244
245#[derive(
246    Copy,
247    Clone,
248    Debug,
249    PartialEq,
250    Default,
251    Serialize,
252    Deserialize,
253    JsonSchema,
254    MergeFrom,
255    strum::VariantArray,
256    strum::VariantNames,
257)]
258#[serde(rename_all = "snake_case")]
259pub enum ActivateOnClose {
260    #[default]
261    History,
262    Neighbour,
263    LeftNeighbour,
264}
265
266#[with_fallible_options]
267#[derive(Copy, Clone, PartialEq, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]
268#[serde(rename_all = "snake_case")]
269pub struct ActivePaneModifiers {
270    /// Size of the border surrounding the active pane.
271    /// When set to 0, the active pane doesn't have any border.
272    /// The border is drawn inset.
273    ///
274    /// Default: `0.0`
275    #[serde(serialize_with = "crate::serialize_optional_f32_with_two_decimal_places")]
276    pub border_size: Option<f32>,
277    /// Opacity of inactive panels.
278    /// When set to 1.0, the inactive panes have the same opacity as the active one.
279    /// If set to 0, the inactive panes content will not be visible at all.
280    /// Values are clamped to the [0.0, 1.0] range.
281    ///
282    /// Default: `1.0`
283    #[schemars(range(min = 0.0, max = 1.0))]
284    pub inactive_opacity: Option<InactiveOpacity>,
285}
286
287#[derive(
288    Copy,
289    Clone,
290    Debug,
291    Default,
292    Serialize,
293    Deserialize,
294    PartialEq,
295    JsonSchema,
296    MergeFrom,
297    strum::VariantArray,
298    strum::VariantNames,
299)]
300#[serde(rename_all = "snake_case")]
301pub enum BottomDockLayout {
302    /// Contained between the left and right docks
303    #[default]
304    Contained,
305    /// Takes up the full width of the window
306    Full,
307    /// Extends under the left dock while snapping to the right dock
308    LeftAligned,
309    /// Extends under the right dock while snapping to the left dock
310    RightAligned,
311}
312
313#[derive(
314    Copy,
315    Clone,
316    Default,
317    Debug,
318    Serialize,
319    Deserialize,
320    PartialEq,
321    JsonSchema,
322    MergeFrom,
323    strum::VariantArray,
324    strum::VariantNames,
325)]
326#[serde(rename_all = "snake_case")]
327pub enum WindowDecorations {
328    /// Zed draws its own window decorations/titlebar (client-side decoration)
329    #[default]
330    Client,
331    /// Show system's window titlebar (server-side decoration; not supported by GNOME Wayland)
332    Server,
333}
334
335#[derive(
336    Copy,
337    Clone,
338    PartialEq,
339    Default,
340    Serialize,
341    Deserialize,
342    JsonSchema,
343    MergeFrom,
344    Debug,
345    strum::VariantArray,
346    strum::VariantNames,
347)]
348#[serde(rename_all = "snake_case")]
349pub enum CloseWindowWhenNoItems {
350    /// Match platform conventions by default, so "on" on macOS and "off" everywhere else
351    #[default]
352    PlatformDefault,
353    /// Close the window when there are no tabs
354    CloseWindow,
355    /// Leave the window open when there are no tabs
356    KeepWindowOpen,
357}
358
359impl CloseWindowWhenNoItems {
360    pub fn should_close(&self) -> bool {
361        match self {
362            CloseWindowWhenNoItems::PlatformDefault => cfg!(target_os = "macos"),
363            CloseWindowWhenNoItems::CloseWindow => true,
364            CloseWindowWhenNoItems::KeepWindowOpen => false,
365        }
366    }
367}
368
369#[derive(
370    Copy,
371    Clone,
372    PartialEq,
373    Eq,
374    Default,
375    Serialize,
376    Deserialize,
377    JsonSchema,
378    MergeFrom,
379    Debug,
380    strum::VariantArray,
381    strum::VariantNames,
382)]
383#[serde(rename_all = "snake_case")]
384pub enum RestoreOnStartupBehavior {
385    /// Always start with an empty editor tab
386    #[serde(alias = "none")]
387    EmptyTab,
388    /// Restore the workspace that was closed last.
389    LastWorkspace,
390    /// Restore all workspaces that were open when quitting Zed.
391    #[default]
392    LastSession,
393    /// Show the launchpad with recent projects (no tabs).
394    Launchpad,
395}
396
397#[with_fallible_options]
398#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug, PartialEq)]
399pub struct TabBarSettingsContent {
400    /// Whether or not to show the tab bar in the editor.
401    ///
402    /// Default: true
403    pub show: Option<bool>,
404    /// Whether or not to show the navigation history buttons in the tab bar.
405    ///
406    /// Default: true
407    pub show_nav_history_buttons: Option<bool>,
408    /// Whether or not to show the tab bar buttons.
409    ///
410    /// Default: true
411    pub show_tab_bar_buttons: Option<bool>,
412}
413
414#[with_fallible_options]
415#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug, PartialEq, Eq)]
416pub struct StatusBarSettingsContent {
417    /// Whether to show the status bar.
418    ///
419    /// Default: true
420    #[serde(rename = "experimental.show")]
421    pub show: Option<bool>,
422    /// Whether to display the active language button in the status bar.
423    ///
424    /// Default: true
425    pub active_language_button: Option<bool>,
426    /// Whether to show the cursor position button in the status bar.
427    ///
428    /// Default: true
429    pub cursor_position_button: Option<bool>,
430    /// Whether to show active line endings button in the status bar.
431    ///
432    /// Default: false
433    pub line_endings_button: Option<bool>,
434}
435
436#[derive(
437    Copy,
438    Clone,
439    Debug,
440    Serialize,
441    Deserialize,
442    PartialEq,
443    Eq,
444    JsonSchema,
445    MergeFrom,
446    strum::EnumDiscriminants,
447)]
448#[strum_discriminants(derive(strum::VariantArray, strum::VariantNames, strum::FromRepr))]
449#[serde(rename_all = "snake_case")]
450pub enum AutosaveSetting {
451    /// Disable autosave.
452    Off,
453    /// Save after inactivity period of `milliseconds`.
454    AfterDelay { milliseconds: DelayMs },
455    /// Autosave when focus changes.
456    OnFocusChange,
457    /// Autosave when the active window changes.
458    OnWindowChange,
459}
460
461impl AutosaveSetting {
462    pub fn should_save_on_close(&self) -> bool {
463        matches!(
464            &self,
465            AutosaveSetting::OnFocusChange
466                | AutosaveSetting::OnWindowChange
467                | AutosaveSetting::AfterDelay { .. }
468        )
469    }
470}
471
472#[derive(
473    Copy,
474    Clone,
475    Debug,
476    Serialize,
477    Deserialize,
478    PartialEq,
479    Eq,
480    JsonSchema,
481    MergeFrom,
482    strum::VariantArray,
483    strum::VariantNames,
484)]
485#[serde(rename_all = "snake_case")]
486pub enum PaneSplitDirectionHorizontal {
487    Up,
488    Down,
489}
490
491#[derive(
492    Copy,
493    Clone,
494    Debug,
495    Serialize,
496    Deserialize,
497    PartialEq,
498    Eq,
499    JsonSchema,
500    MergeFrom,
501    strum::VariantArray,
502    strum::VariantNames,
503)]
504#[serde(rename_all = "snake_case")]
505pub enum PaneSplitDirectionVertical {
506    Left,
507    Right,
508}
509
510#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Default)]
511#[serde(rename_all = "snake_case")]
512#[with_fallible_options]
513pub struct CenteredLayoutSettings {
514    /// The relative width of the left padding of the central pane from the
515    /// workspace when the centered layout is used.
516    ///
517    /// Default: 0.2
518    pub left_padding: Option<CenteredPaddingSettings>,
519    // The relative width of the right padding of the central pane from the
520    // workspace when the centered layout is used.
521    ///
522    /// Default: 0.2
523    pub right_padding: Option<CenteredPaddingSettings>,
524}
525
526#[derive(
527    Copy,
528    Clone,
529    Default,
530    Serialize,
531    Deserialize,
532    JsonSchema,
533    MergeFrom,
534    PartialEq,
535    Debug,
536    strum::VariantArray,
537    strum::VariantNames,
538)]
539#[serde(rename_all = "snake_case")]
540pub enum OnLastWindowClosed {
541    /// Match platform conventions by default, so don't quit on macOS, and quit on other platforms
542    #[default]
543    PlatformDefault,
544    /// Quit the application the last window is closed
545    QuitApp,
546}
547
548impl OnLastWindowClosed {
549    pub fn is_quit_app(&self) -> bool {
550        match self {
551            OnLastWindowClosed::PlatformDefault => false,
552            OnLastWindowClosed::QuitApp => true,
553        }
554    }
555}
556
557#[with_fallible_options]
558#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug)]
559pub struct ProjectPanelAutoOpenSettings {
560    /// Whether to automatically open newly created files in the editor.
561    ///
562    /// Default: true
563    pub on_create: Option<bool>,
564    /// Whether to automatically open files after pasting or duplicating them.
565    ///
566    /// Default: true
567    pub on_paste: Option<bool>,
568    /// Whether to automatically open files dropped from external sources.
569    ///
570    /// Default: true
571    pub on_drop: Option<bool>,
572}
573
574#[with_fallible_options]
575#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug)]
576pub struct ProjectPanelSettingsContent {
577    /// Whether to show the project panel button in the status bar.
578    ///
579    /// Default: true
580    pub button: Option<bool>,
581    /// Whether to hide gitignore files in the project panel.
582    ///
583    /// Default: false
584    pub hide_gitignore: Option<bool>,
585    /// Customize default width (in pixels) taken by project panel
586    ///
587    /// Default: 240
588    #[serde(serialize_with = "crate::serialize_optional_f32_with_two_decimal_places")]
589    pub default_width: Option<f32>,
590    /// The position of project panel
591    ///
592    /// Default: left
593    pub dock: Option<DockSide>,
594    /// Spacing between worktree entries in the project panel.
595    ///
596    /// Default: comfortable
597    pub entry_spacing: Option<ProjectPanelEntrySpacing>,
598    /// Whether to show file icons in the project panel.
599    ///
600    /// Default: true
601    pub file_icons: Option<bool>,
602    /// Whether to show folder icons or chevrons for directories in the project panel.
603    ///
604    /// Default: true
605    pub folder_icons: Option<bool>,
606    /// Whether to show the git status in the project panel.
607    ///
608    /// Default: true
609    pub git_status: Option<bool>,
610    /// Amount of indentation (in pixels) for nested items.
611    ///
612    /// Default: 20
613    #[serde(serialize_with = "serialize_optional_f32_with_two_decimal_places")]
614    pub indent_size: Option<f32>,
615    /// Whether to reveal it in the project panel automatically,
616    /// when a corresponding project entry becomes active.
617    /// Gitignored entries are never auto revealed.
618    ///
619    /// Default: true
620    pub auto_reveal_entries: Option<bool>,
621    /// Whether to fold directories automatically
622    /// when directory has only one directory inside.
623    ///
624    /// Default: true
625    pub auto_fold_dirs: Option<bool>,
626    /// Whether the project panel should open on startup.
627    ///
628    /// Default: true
629    pub starts_open: Option<bool>,
630    /// Scrollbar-related settings
631    pub scrollbar: Option<ScrollbarSettingsContent>,
632    /// Which files containing diagnostic errors/warnings to mark in the project panel.
633    ///
634    /// Default: all
635    pub show_diagnostics: Option<ShowDiagnostics>,
636    /// Settings related to indent guides in the project panel.
637    pub indent_guides: Option<ProjectPanelIndentGuidesSettings>,
638    /// Whether to hide the root entry when only one folder is open in the window.
639    ///
640    /// Default: false
641    pub hide_root: Option<bool>,
642    /// Whether to hide the hidden entries in the project panel.
643    ///
644    /// Default: false
645    pub hide_hidden: Option<bool>,
646    /// Whether to stick parent directories at top of the project panel.
647    ///
648    /// Default: true
649    pub sticky_scroll: Option<bool>,
650    /// Whether to enable drag-and-drop operations in the project panel.
651    ///
652    /// Default: true
653    pub drag_and_drop: Option<bool>,
654    /// Settings for automatically opening files.
655    pub auto_open: Option<ProjectPanelAutoOpenSettings>,
656    /// How to order sibling entries in the project panel.
657    ///
658    /// Default: directories_first
659    pub sort_mode: Option<ProjectPanelSortMode>,
660}
661
662#[derive(
663    Copy,
664    Clone,
665    Debug,
666    Default,
667    Serialize,
668    Deserialize,
669    JsonSchema,
670    MergeFrom,
671    PartialEq,
672    Eq,
673    strum::VariantArray,
674    strum::VariantNames,
675)]
676#[serde(rename_all = "snake_case")]
677pub enum ProjectPanelEntrySpacing {
678    /// Comfortable spacing of entries.
679    #[default]
680    Comfortable,
681    /// The standard spacing of entries.
682    Standard,
683}
684
685#[derive(
686    Copy,
687    Clone,
688    Debug,
689    Default,
690    Serialize,
691    Deserialize,
692    JsonSchema,
693    MergeFrom,
694    PartialEq,
695    Eq,
696    strum::VariantArray,
697    strum::VariantNames,
698)]
699#[serde(rename_all = "snake_case")]
700pub enum ProjectPanelSortMode {
701    /// Show directories first, then files
702    #[default]
703    DirectoriesFirst,
704    /// Mix directories and files together
705    Mixed,
706    /// Show files first, then directories
707    FilesFirst,
708}
709
710#[with_fallible_options]
711#[derive(
712    Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq, Default,
713)]
714pub struct ProjectPanelIndentGuidesSettings {
715    pub show: Option<ShowIndentGuides>,
716}