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