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::{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(Copy, Clone, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]
160#[serde(rename_all = "lowercase")]
161pub enum ClosePosition {
162    Left,
163    #[default]
164    Right,
165}
166
167#[derive(Copy, Clone, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]
168#[serde(rename_all = "lowercase")]
169pub enum ShowCloseButton {
170    Always,
171    #[default]
172    Hover,
173    Hidden,
174}
175
176#[derive(
177    Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq,
178)]
179#[serde(rename_all = "snake_case")]
180pub enum ShowDiagnostics {
181    #[default]
182    Off,
183    Errors,
184    All,
185}
186
187#[derive(Copy, Clone, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]
188#[serde(rename_all = "snake_case")]
189pub enum ActivateOnClose {
190    #[default]
191    History,
192    Neighbour,
193    LeftNeighbour,
194}
195
196#[skip_serializing_none]
197#[derive(Copy, Clone, PartialEq, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]
198#[serde(rename_all = "snake_case")]
199pub struct ActivePanelModifiers {
200    /// Size of the border surrounding the active pane.
201    /// When set to 0, the active pane doesn't have any border.
202    /// The border is drawn inset.
203    ///
204    /// Default: `0.0`
205    pub border_size: Option<f32>,
206    /// Opacity of inactive panels.
207    /// When set to 1.0, the inactive panes have the same opacity as the active one.
208    /// If set to 0, the inactive panes content will not be visible at all.
209    /// Values are clamped to the [0.0, 1.0] range.
210    ///
211    /// Default: `1.0`
212    pub inactive_opacity: Option<f32>,
213}
214
215#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq, JsonSchema, MergeFrom)]
216#[serde(rename_all = "snake_case")]
217pub enum BottomDockLayout {
218    /// Contained between the left and right docks
219    #[default]
220    Contained,
221    /// Takes up the full width of the window
222    Full,
223    /// Extends under the left dock while snapping to the right dock
224    LeftAligned,
225    /// Extends under the right dock while snapping to the left dock
226    RightAligned,
227}
228
229#[derive(Copy, Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug)]
230#[serde(rename_all = "snake_case")]
231pub enum CloseWindowWhenNoItems {
232    /// Match platform conventions by default, so "on" on macOS and "off" everywhere else
233    #[default]
234    PlatformDefault,
235    /// Close the window when there are no tabs
236    CloseWindow,
237    /// Leave the window open when there are no tabs
238    KeepWindowOpen,
239}
240
241impl CloseWindowWhenNoItems {
242    pub fn should_close(&self) -> bool {
243        match self {
244            CloseWindowWhenNoItems::PlatformDefault => cfg!(target_os = "macos"),
245            CloseWindowWhenNoItems::CloseWindow => true,
246            CloseWindowWhenNoItems::KeepWindowOpen => false,
247        }
248    }
249}
250
251#[derive(
252    Copy, Clone, PartialEq, Eq, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug,
253)]
254#[serde(rename_all = "snake_case")]
255pub enum RestoreOnStartupBehavior {
256    /// Always start with an empty editor
257    None,
258    /// Restore the workspace that was closed last.
259    LastWorkspace,
260    /// Restore all workspaces that were open when quitting Zed.
261    #[default]
262    LastSession,
263}
264
265#[skip_serializing_none]
266#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug, PartialEq)]
267pub struct TabBarSettingsContent {
268    /// Whether or not to show the tab bar in the editor.
269    ///
270    /// Default: true
271    pub show: Option<bool>,
272    /// Whether or not to show the navigation history buttons in the tab bar.
273    ///
274    /// Default: true
275    pub show_nav_history_buttons: Option<bool>,
276    /// Whether or not to show the tab bar buttons.
277    ///
278    /// Default: true
279    pub show_tab_bar_buttons: Option<bool>,
280}
281
282#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom)]
283#[serde(rename_all = "snake_case")]
284pub enum AutosaveSetting {
285    /// Disable autosave.
286    Off,
287    /// Save after inactivity period of `milliseconds`.
288    AfterDelay { milliseconds: u64 },
289    /// Autosave when focus changes.
290    OnFocusChange,
291    /// Autosave when the active window changes.
292    OnWindowChange,
293}
294
295impl AutosaveSetting {
296    pub fn should_save_on_close(&self) -> bool {
297        matches!(
298            &self,
299            AutosaveSetting::OnFocusChange
300                | AutosaveSetting::OnWindowChange
301                | AutosaveSetting::AfterDelay { .. }
302        )
303    }
304}
305
306#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom)]
307#[serde(rename_all = "snake_case")]
308pub enum PaneSplitDirectionHorizontal {
309    Up,
310    Down,
311}
312
313#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom)]
314#[serde(rename_all = "snake_case")]
315pub enum PaneSplitDirectionVertical {
316    Left,
317    Right,
318}
319
320#[skip_serializing_none]
321#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq)]
322#[serde(rename_all = "snake_case")]
323pub struct CenteredLayoutSettings {
324    /// The relative width of the left padding of the central pane from the
325    /// workspace when the centered layout is used.
326    ///
327    /// Default: 0.2
328    pub left_padding: Option<f32>,
329    // The relative width of the right padding of the central pane from the
330    // workspace when the centered layout is used.
331    ///
332    /// Default: 0.2
333    pub right_padding: Option<f32>,
334}
335
336#[derive(Copy, Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Debug)]
337#[serde(rename_all = "snake_case")]
338pub enum OnLastWindowClosed {
339    /// Match platform conventions by default, so don't quit on macOS, and quit on other platforms
340    #[default]
341    PlatformDefault,
342    /// Quit the application the last window is closed
343    QuitApp,
344}
345
346impl OnLastWindowClosed {
347    pub fn is_quit_app(&self) -> bool {
348        match self {
349            OnLastWindowClosed::PlatformDefault => false,
350            OnLastWindowClosed::QuitApp => true,
351        }
352    }
353}
354
355#[skip_serializing_none]
356#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug)]
357pub struct ProjectPanelSettingsContent {
358    /// Whether to show the project panel button in the status bar.
359    ///
360    /// Default: true
361    pub button: Option<bool>,
362    /// Whether to hide gitignore files in the project panel.
363    ///
364    /// Default: false
365    pub hide_gitignore: Option<bool>,
366    /// Customize default width (in pixels) taken by project panel
367    ///
368    /// Default: 240
369    pub default_width: Option<f32>,
370    /// The position of project panel
371    ///
372    /// Default: left
373    pub dock: Option<DockSide>,
374    /// Spacing between worktree entries in the project panel.
375    ///
376    /// Default: comfortable
377    pub entry_spacing: Option<ProjectPanelEntrySpacing>,
378    /// Whether to show file icons in the project panel.
379    ///
380    /// Default: true
381    pub file_icons: Option<bool>,
382    /// Whether to show folder icons or chevrons for directories in the project panel.
383    ///
384    /// Default: true
385    pub folder_icons: Option<bool>,
386    /// Whether to show the git status in the project panel.
387    ///
388    /// Default: true
389    pub git_status: Option<bool>,
390    /// Amount of indentation (in pixels) for nested items.
391    ///
392    /// Default: 20
393    pub indent_size: Option<f32>,
394    /// Whether to reveal it in the project panel automatically,
395    /// when a corresponding project entry becomes active.
396    /// Gitignored entries are never auto revealed.
397    ///
398    /// Default: true
399    pub auto_reveal_entries: Option<bool>,
400    /// Whether to fold directories automatically
401    /// when directory has only one directory inside.
402    ///
403    /// Default: true
404    pub auto_fold_dirs: Option<bool>,
405    /// Whether the project panel should open on startup.
406    ///
407    /// Default: true
408    pub starts_open: Option<bool>,
409    /// Scrollbar-related settings
410    pub scrollbar: Option<ScrollbarSettingsContent>,
411    /// Which files containing diagnostic errors/warnings to mark in the project panel.
412    ///
413    /// Default: all
414    pub show_diagnostics: Option<ShowDiagnostics>,
415    /// Settings related to indent guides in the project panel.
416    pub indent_guides: Option<ProjectPanelIndentGuidesSettings>,
417    /// Whether to hide the root entry when only one folder is open in the window.
418    ///
419    /// Default: false
420    pub hide_root: Option<bool>,
421    /// Whether to stick parent directories at top of the project panel.
422    ///
423    /// Default: true
424    pub sticky_scroll: Option<bool>,
425    /// Whether to enable drag-and-drop operations in the project panel.
426    ///
427    /// Default: true
428    pub drag_and_drop: Option<bool>,
429}
430
431#[derive(
432    Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq,
433)]
434#[serde(rename_all = "snake_case")]
435pub enum ProjectPanelEntrySpacing {
436    /// Comfortable spacing of entries.
437    #[default]
438    Comfortable,
439    /// The standard spacing of entries.
440    Standard,
441}
442
443#[skip_serializing_none]
444#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq)]
445pub struct ProjectPanelIndentGuidesSettings {
446    pub show: Option<ShowIndentGuides>,
447}