workspace.rs

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