workspace.rs

  1use std::num::NonZeroUsize;
  2
  3use collections::HashMap;
  4use schemars::JsonSchema;
  5use serde::{Deserialize, Serialize};
  6use serde_with::skip_serializing_none;
  7
  8use crate::{DockPosition, DockSide, ScrollbarSettingsContent, ShowIndentGuides};
  9
 10#[skip_serializing_none]
 11#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema)]
 12pub struct WorkspaceSettingsContent {
 13    /// Active pane styling settings.
 14    pub active_pane_modifiers: Option<ActivePanelModifiers>,
 15    /// Layout mode for the bottom dock
 16    ///
 17    /// Default: contained
 18    pub bottom_dock_layout: Option<BottomDockLayout>,
 19    /// Direction to split horizontally.
 20    ///
 21    /// Default: "up"
 22    pub pane_split_direction_horizontal: Option<PaneSplitDirectionHorizontal>,
 23    /// Direction to split vertically.
 24    ///
 25    /// Default: "left"
 26    pub pane_split_direction_vertical: Option<PaneSplitDirectionVertical>,
 27    /// Centered layout related settings.
 28    pub centered_layout: Option<CenteredLayoutSettings>,
 29    /// Whether or not to prompt the user to confirm before closing the application.
 30    ///
 31    /// Default: false
 32    pub confirm_quit: Option<bool>,
 33    /// Whether or not to show the call status icon in the status bar.
 34    ///
 35    /// Default: true
 36    pub show_call_status_icon: Option<bool>,
 37    /// When to automatically save edited buffers.
 38    ///
 39    /// Default: off
 40    pub autosave: Option<AutosaveSetting>,
 41    /// Controls previous session restoration in freshly launched Zed instance.
 42    /// Values: none, last_workspace, last_session
 43    /// Default: last_session
 44    pub restore_on_startup: Option<RestoreOnStartupBehavior>,
 45    /// Whether to attempt to restore previous file's state when opening it again.
 46    /// The state is stored per pane.
 47    /// When disabled, defaults are applied instead of the state restoration.
 48    ///
 49    /// 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.
 50    /// When disabled, a single selection in the very beginning of the file, zero scroll position and no folds state is used as a default.
 51    ///
 52    /// Default: true
 53    pub restore_on_file_reopen: Option<bool>,
 54    /// The size of the workspace split drop targets on the outer edges.
 55    /// Given as a fraction that will be multiplied by the smaller dimension of the workspace.
 56    ///
 57    /// Default: `0.2` (20% of the smaller dimension of the workspace)
 58    pub drop_target_size: Option<f32>,
 59    /// Whether to close the window when using 'close active item' on a workspace with no tabs
 60    ///
 61    /// Default: auto ("on" on macOS, "off" otherwise)
 62    pub when_closing_with_no_tabs: Option<CloseWindowWhenNoItems>,
 63    /// Whether to use the system provided dialogs for Open and Save As.
 64    /// When set to false, Zed will use the built-in keyboard-first pickers.
 65    ///
 66    /// Default: true
 67    pub use_system_path_prompts: Option<bool>,
 68    /// Whether to use the system provided prompts.
 69    /// When set to false, Zed will use the built-in prompts.
 70    /// Note that this setting has no effect on Linux, where Zed will always
 71    /// use the built-in prompts.
 72    ///
 73    /// Default: true
 74    pub use_system_prompts: Option<bool>,
 75    /// Aliases for the command palette. When you type a key in this map,
 76    /// it will be assumed to equal the value.
 77    ///
 78    /// Default: true
 79    #[serde(default)]
 80    pub command_aliases: HashMap<String, String>,
 81    /// Maximum open tabs in a pane. Will not close an unsaved
 82    /// tab. Set to `None` for unlimited tabs.
 83    ///
 84    /// Default: none
 85    pub max_tabs: Option<NonZeroUsize>,
 86    /// What to do when the last window is closed
 87    ///
 88    /// Default: auto (nothing on macOS, "app quit" otherwise)
 89    pub on_last_window_closed: Option<OnLastWindowClosed>,
 90    /// Whether to resize all the panels in a dock when resizing the dock.
 91    ///
 92    /// Default: ["left"]
 93    pub resize_all_panels_in_dock: Option<Vec<DockPosition>>,
 94    /// Whether to automatically close files that have been deleted on disk.
 95    ///
 96    /// Default: false
 97    pub close_on_file_delete: Option<bool>,
 98    /// Whether to allow windows to tab together based on the user’s tabbing preference (macOS only).
 99    ///
100    /// Default: false
101    pub use_system_window_tabs: Option<bool>,
102    /// Whether to show padding for zoomed panels.
103    /// When enabled, zoomed bottom panels will have some top padding,
104    /// while zoomed left/right panels will have padding to the right/left (respectively).
105    ///
106    /// Default: true
107    pub zoomed_padding: Option<bool>,
108}
109
110#[skip_serializing_none]
111#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
112pub struct ItemSettingsContent {
113    /// Whether to show the Git file status on a tab item.
114    ///
115    /// Default: false
116    pub git_status: Option<bool>,
117    /// Position of the close button in a tab.
118    ///
119    /// Default: right
120    pub close_position: Option<ClosePosition>,
121    /// Whether to show the file icon for a tab.
122    ///
123    /// Default: false
124    pub file_icons: Option<bool>,
125    /// What to do after closing the current tab.
126    ///
127    /// Default: history
128    pub activate_on_close: Option<ActivateOnClose>,
129    /// Which files containing diagnostic errors/warnings to mark in the tabs.
130    /// This setting can take the following three values:
131    ///
132    /// Default: off
133    pub show_diagnostics: Option<ShowDiagnostics>,
134    /// Whether to always show the close button on tabs.
135    ///
136    /// Default: false
137    pub show_close_button: Option<ShowCloseButton>,
138}
139
140#[skip_serializing_none]
141#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, JsonSchema)]
142pub struct PreviewTabsSettingsContent {
143    /// Whether to show opened editors as preview tabs.
144    /// 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.
145    ///
146    /// Default: true
147    pub enabled: Option<bool>,
148    /// Whether to open tabs in preview mode when selected from the file finder.
149    ///
150    /// Default: false
151    pub enable_preview_from_file_finder: Option<bool>,
152    /// Whether a preview tab gets replaced when code navigation is used to navigate away from the tab.
153    ///
154    /// Default: false
155    pub enable_preview_from_code_navigation: Option<bool>,
156}
157
158#[derive(Copy, Clone, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema)]
159#[serde(rename_all = "lowercase")]
160pub enum ClosePosition {
161    Left,
162    #[default]
163    Right,
164}
165
166#[derive(Copy, Clone, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema)]
167#[serde(rename_all = "lowercase")]
168pub enum ShowCloseButton {
169    Always,
170    #[default]
171    Hover,
172    Hidden,
173}
174
175#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
176#[serde(rename_all = "snake_case")]
177pub enum ShowDiagnostics {
178    #[default]
179    Off,
180    Errors,
181    All,
182}
183
184#[derive(Copy, Clone, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema)]
185#[serde(rename_all = "snake_case")]
186pub enum ActivateOnClose {
187    #[default]
188    History,
189    Neighbour,
190    LeftNeighbour,
191}
192
193#[skip_serializing_none]
194#[derive(Copy, Clone, PartialEq, Debug, Default, Serialize, Deserialize, JsonSchema)]
195#[serde(rename_all = "snake_case")]
196pub struct ActivePanelModifiers {
197    /// Size of the border surrounding the active pane.
198    /// When set to 0, the active pane doesn't have any border.
199    /// The border is drawn inset.
200    ///
201    /// Default: `0.0`
202    pub border_size: Option<f32>,
203    /// Opacity of inactive panels.
204    /// When set to 1.0, the inactive panes have the same opacity as the active one.
205    /// If set to 0, the inactive panes content will not be visible at all.
206    /// Values are clamped to the [0.0, 1.0] range.
207    ///
208    /// Default: `1.0`
209    pub inactive_opacity: Option<f32>,
210}
211
212#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq, JsonSchema)]
213#[serde(rename_all = "snake_case")]
214pub enum BottomDockLayout {
215    /// Contained between the left and right docks
216    #[default]
217    Contained,
218    /// Takes up the full width of the window
219    Full,
220    /// Extends under the left dock while snapping to the right dock
221    LeftAligned,
222    /// Extends under the right dock while snapping to the left dock
223    RightAligned,
224}
225
226#[derive(Copy, Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, Debug)]
227#[serde(rename_all = "snake_case")]
228pub enum CloseWindowWhenNoItems {
229    /// Match platform conventions by default, so "on" on macOS and "off" everywhere else
230    #[default]
231    PlatformDefault,
232    /// Close the window when there are no tabs
233    CloseWindow,
234    /// Leave the window open when there are no tabs
235    KeepWindowOpen,
236}
237
238impl CloseWindowWhenNoItems {
239    pub fn should_close(&self) -> bool {
240        match self {
241            CloseWindowWhenNoItems::PlatformDefault => cfg!(target_os = "macos"),
242            CloseWindowWhenNoItems::CloseWindow => true,
243            CloseWindowWhenNoItems::KeepWindowOpen => false,
244        }
245    }
246}
247
248#[derive(Copy, Clone, PartialEq, Eq, Default, Serialize, Deserialize, JsonSchema, Debug)]
249#[serde(rename_all = "snake_case")]
250pub enum RestoreOnStartupBehavior {
251    /// Always start with an empty editor
252    None,
253    /// Restore the workspace that was closed last.
254    LastWorkspace,
255    /// Restore all workspaces that were open when quitting Zed.
256    #[default]
257    LastSession,
258}
259
260#[skip_serializing_none]
261#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug, PartialEq)]
262pub struct TabBarSettingsContent {
263    /// Whether or not to show the tab bar in the editor.
264    ///
265    /// Default: true
266    pub show: Option<bool>,
267    /// Whether or not to show the navigation history buttons in the tab bar.
268    ///
269    /// Default: true
270    pub show_nav_history_buttons: Option<bool>,
271    /// Whether or not to show the tab bar buttons.
272    ///
273    /// Default: true
274    pub show_tab_bar_buttons: Option<bool>,
275}
276
277#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
278#[serde(rename_all = "snake_case")]
279pub enum AutosaveSetting {
280    /// Disable autosave.
281    Off,
282    /// Save after inactivity period of `milliseconds`.
283    AfterDelay { milliseconds: u64 },
284    /// Autosave when focus changes.
285    OnFocusChange,
286    /// Autosave when the active window changes.
287    OnWindowChange,
288}
289
290#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
291#[serde(rename_all = "snake_case")]
292pub enum PaneSplitDirectionHorizontal {
293    Up,
294    Down,
295}
296
297#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
298#[serde(rename_all = "snake_case")]
299pub enum PaneSplitDirectionVertical {
300    Left,
301    Right,
302}
303
304#[skip_serializing_none]
305#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
306#[serde(rename_all = "snake_case")]
307pub struct CenteredLayoutSettings {
308    /// The relative width of the left padding of the central pane from the
309    /// workspace when the centered layout is used.
310    ///
311    /// Default: 0.2
312    pub left_padding: Option<f32>,
313    // The relative width of the right padding of the central pane from the
314    // workspace when the centered layout is used.
315    ///
316    /// Default: 0.2
317    pub right_padding: Option<f32>,
318}
319
320#[derive(Copy, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq, Debug)]
321#[serde(rename_all = "snake_case")]
322pub enum OnLastWindowClosed {
323    /// Match platform conventions by default, so don't quit on macOS, and quit on other platforms
324    #[default]
325    PlatformDefault,
326    /// Quit the application the last window is closed
327    QuitApp,
328}
329
330impl OnLastWindowClosed {
331    pub fn is_quit_app(&self) -> bool {
332        match self {
333            OnLastWindowClosed::PlatformDefault => false,
334            OnLastWindowClosed::QuitApp => true,
335        }
336    }
337}
338
339#[skip_serializing_none]
340#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, Debug)]
341pub struct ProjectPanelSettingsContent {
342    /// Whether to show the project panel button in the status bar.
343    ///
344    /// Default: true
345    pub button: Option<bool>,
346    /// Whether to hide gitignore files in the project panel.
347    ///
348    /// Default: false
349    pub hide_gitignore: Option<bool>,
350    /// Customize default width (in pixels) taken by project panel
351    ///
352    /// Default: 240
353    pub default_width: Option<f32>,
354    /// The position of project panel
355    ///
356    /// Default: left
357    pub dock: Option<DockSide>,
358    /// Spacing between worktree entries in the project panel.
359    ///
360    /// Default: comfortable
361    pub entry_spacing: Option<ProjectPanelEntrySpacing>,
362    /// Whether to show file icons in the project panel.
363    ///
364    /// Default: true
365    pub file_icons: Option<bool>,
366    /// Whether to show folder icons or chevrons for directories in the project panel.
367    ///
368    /// Default: true
369    pub folder_icons: Option<bool>,
370    /// Whether to show the git status in the project panel.
371    ///
372    /// Default: true
373    pub git_status: Option<bool>,
374    /// Amount of indentation (in pixels) for nested items.
375    ///
376    /// Default: 20
377    pub indent_size: Option<f32>,
378    /// Whether to reveal it in the project panel automatically,
379    /// when a corresponding project entry becomes active.
380    /// Gitignored entries are never auto revealed.
381    ///
382    /// Default: true
383    pub auto_reveal_entries: Option<bool>,
384    /// Whether to fold directories automatically
385    /// when directory has only one directory inside.
386    ///
387    /// Default: true
388    pub auto_fold_dirs: Option<bool>,
389    /// Whether the project panel should open on startup.
390    ///
391    /// Default: true
392    pub starts_open: Option<bool>,
393    /// Scrollbar-related settings
394    pub scrollbar: Option<ScrollbarSettingsContent>,
395    /// Which files containing diagnostic errors/warnings to mark in the project panel.
396    ///
397    /// Default: all
398    pub show_diagnostics: Option<ShowDiagnostics>,
399    /// Settings related to indent guides in the project panel.
400    pub indent_guides: Option<ProjectPanelIndentGuidesSettings>,
401    /// Whether to hide the root entry when only one folder is open in the window.
402    ///
403    /// Default: false
404    pub hide_root: Option<bool>,
405    /// Whether to stick parent directories at top of the project panel.
406    ///
407    /// Default: true
408    pub sticky_scroll: Option<bool>,
409    /// Whether to enable drag-and-drop operations in the project panel.
410    ///
411    /// Default: true
412    pub drag_and_drop: Option<bool>,
413}
414
415#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
416#[serde(rename_all = "snake_case")]
417pub enum ProjectPanelEntrySpacing {
418    /// Comfortable spacing of entries.
419    #[default]
420    Comfortable,
421    /// The standard spacing of entries.
422    Standard,
423}
424
425#[skip_serializing_none]
426#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
427pub struct ProjectPanelIndentGuidesSettings {
428    pub show: Option<ShowIndentGuides>,
429}