workspace.rs

  1use std::num::NonZeroUsize;
  2
  3use collections::HashMap;
  4use schemars::JsonSchema;
  5use serde::{Deserialize, Serialize};
  6
  7#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema)]
  8pub struct WorkspaceSettingsContent {
  9    /// Active pane styling settings.
 10    pub active_pane_modifiers: Option<ActivePanelModifiers>,
 11    /// Layout mode for the bottom dock
 12    ///
 13    /// Default: contained
 14    pub bottom_dock_layout: Option<BottomDockLayout>,
 15    /// Direction to split horizontally.
 16    ///
 17    /// Default: "up"
 18    pub pane_split_direction_horizontal: Option<PaneSplitDirectionHorizontal>,
 19    /// Direction to split vertically.
 20    ///
 21    /// Default: "left"
 22    pub pane_split_direction_vertical: Option<PaneSplitDirectionVertical>,
 23    /// Centered layout related settings.
 24    pub centered_layout: Option<CenteredLayoutSettings>,
 25    /// Whether or not to prompt the user to confirm before closing the application.
 26    ///
 27    /// Default: false
 28    pub confirm_quit: Option<bool>,
 29    /// Whether or not to show the call status icon in the status bar.
 30    ///
 31    /// Default: true
 32    pub show_call_status_icon: Option<bool>,
 33    /// When to automatically save edited buffers.
 34    ///
 35    /// Default: off
 36    pub autosave: Option<AutosaveSetting>,
 37    /// Controls previous session restoration in freshly launched Zed instance.
 38    /// Values: none, last_workspace, last_session
 39    /// Default: last_session
 40    pub restore_on_startup: Option<RestoreOnStartupBehavior>,
 41    /// Whether to attempt to restore previous file's state when opening it again.
 42    /// The state is stored per pane.
 43    /// When disabled, defaults are applied instead of the state restoration.
 44    ///
 45    /// 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.
 46    /// When disabled, a single selection in the very beginning of the file, zero scroll position and no folds state is used as a default.
 47    ///
 48    /// Default: true
 49    pub restore_on_file_reopen: Option<bool>,
 50    /// The size of the workspace split drop targets on the outer edges.
 51    /// Given as a fraction that will be multiplied by the smaller dimension of the workspace.
 52    ///
 53    /// Default: `0.2` (20% of the smaller dimension of the workspace)
 54    pub drop_target_size: Option<f32>,
 55    /// Whether to close the window when using 'close active item' on a workspace with no tabs
 56    ///
 57    /// Default: auto ("on" on macOS, "off" otherwise)
 58    pub when_closing_with_no_tabs: Option<CloseWindowWhenNoItems>,
 59    /// Whether to use the system provided dialogs for Open and Save As.
 60    /// When set to false, Zed will use the built-in keyboard-first pickers.
 61    ///
 62    /// Default: true
 63    pub use_system_path_prompts: Option<bool>,
 64    /// Whether to use the system provided prompts.
 65    /// When set to false, Zed will use the built-in prompts.
 66    /// Note that this setting has no effect on Linux, where Zed will always
 67    /// use the built-in prompts.
 68    ///
 69    /// Default: true
 70    pub use_system_prompts: Option<bool>,
 71    /// Aliases for the command palette. When you type a key in this map,
 72    /// it will be assumed to equal the value.
 73    ///
 74    /// Default: true
 75    #[serde(default)]
 76    pub command_aliases: HashMap<String, String>,
 77    /// Maximum open tabs in a pane. Will not close an unsaved
 78    /// tab. Set to `None` for unlimited tabs.
 79    ///
 80    /// Default: none
 81    pub max_tabs: Option<NonZeroUsize>,
 82    /// What to do when the last window is closed
 83    ///
 84    /// Default: auto (nothing on macOS, "app quit" otherwise)
 85    pub on_last_window_closed: Option<OnLastWindowClosed>,
 86    /// Whether to resize all the panels in a dock when resizing the dock.
 87    ///
 88    /// Default: ["left"]
 89    #[serde(default)]
 90    pub resize_all_panels_in_dock: Vec<DockPosition>,
 91    /// Whether to automatically close files that have been deleted on disk.
 92    ///
 93    /// Default: false
 94    pub close_on_file_delete: Option<bool>,
 95    /// Whether to allow windows to tab together based on the user’s tabbing preference (macOS only).
 96    ///
 97    /// Default: false
 98    pub use_system_window_tabs: Option<bool>,
 99    /// Whether to show padding for zoomed panels.
100    /// When enabled, zoomed bottom panels will have some top padding,
101    /// while zoomed left/right panels will have padding to the right/left (respectively).
102    ///
103    /// Default: true
104    pub zoomed_padding: Option<bool>,
105
106    // Settings related to the editor's tab bar.
107    pub tab_bar: Option<TabBarSettingsContent>,
108
109    pub tabs: Option<ItemSettingsContent>,
110}
111
112#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
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#[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#[derive(Copy, Clone, PartialEq, Debug, Default, Serialize, Deserialize, JsonSchema)]
194#[serde(rename_all = "snake_case")]
195pub struct ActivePanelModifiers {
196    /// Size of the border surrounding the active pane.
197    /// When set to 0, the active pane doesn't have any border.
198    /// The border is drawn inset.
199    ///
200    /// Default: `0.0`
201    pub border_size: Option<f32>,
202    /// Opacity of inactive panels.
203    /// When set to 1.0, the inactive panes have the same opacity as the active one.
204    /// If set to 0, the inactive panes content will not be visible at all.
205    /// Values are clamped to the [0.0, 1.0] range.
206    ///
207    /// Default: `1.0`
208    pub inactive_opacity: Option<f32>,
209}
210
211#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq, JsonSchema)]
212#[serde(rename_all = "snake_case")]
213pub enum BottomDockLayout {
214    /// Contained between the left and right docks
215    #[default]
216    Contained,
217    /// Takes up the full width of the window
218    Full,
219    /// Extends under the left dock while snapping to the right dock
220    LeftAligned,
221    /// Extends under the right dock while snapping to the left dock
222    RightAligned,
223}
224
225#[derive(Copy, Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, Debug)]
226#[serde(rename_all = "snake_case")]
227pub enum CloseWindowWhenNoItems {
228    /// Match platform conventions by default, so "on" on macOS and "off" everywhere else
229    #[default]
230    PlatformDefault,
231    /// Close the window when there are no tabs
232    CloseWindow,
233    /// Leave the window open when there are no tabs
234    KeepWindowOpen,
235}
236
237impl CloseWindowWhenNoItems {
238    pub fn should_close(&self) -> bool {
239        match self {
240            CloseWindowWhenNoItems::PlatformDefault => cfg!(target_os = "macos"),
241            CloseWindowWhenNoItems::CloseWindow => true,
242            CloseWindowWhenNoItems::KeepWindowOpen => false,
243        }
244    }
245}
246
247#[derive(Copy, Clone, PartialEq, Eq, Default, Serialize, Deserialize, JsonSchema, Debug)]
248#[serde(rename_all = "snake_case")]
249pub enum RestoreOnStartupBehavior {
250    /// Always start with an empty editor
251    None,
252    /// Restore the workspace that was closed last.
253    LastWorkspace,
254    /// Restore all workspaces that were open when quitting Zed.
255    #[default]
256    LastSession,
257}
258
259#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug, PartialEq)]
260pub struct TabBarSettingsContent {
261    /// Whether or not to show the tab bar in the editor.
262    ///
263    /// Default: true
264    pub show: Option<bool>,
265    /// Whether or not to show the navigation history buttons in the tab bar.
266    ///
267    /// Default: true
268    pub show_nav_history_buttons: Option<bool>,
269    /// Whether or not to show the tab bar buttons.
270    ///
271    /// Default: true
272    pub show_tab_bar_buttons: Option<bool>,
273}
274
275#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
276#[serde(rename_all = "snake_case")]
277pub enum AutosaveSetting {
278    /// Disable autosave.
279    Off,
280    /// Save after inactivity period of `milliseconds`.
281    AfterDelay { milliseconds: u64 },
282    /// Autosave when focus changes.
283    OnFocusChange,
284    /// Autosave when the active window changes.
285    OnWindowChange,
286}
287
288#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
289#[serde(rename_all = "snake_case")]
290pub enum PaneSplitDirectionHorizontal {
291    Up,
292    Down,
293}
294
295#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
296#[serde(rename_all = "snake_case")]
297pub enum PaneSplitDirectionVertical {
298    Left,
299    Right,
300}
301
302#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
303#[serde(rename_all = "snake_case")]
304pub struct CenteredLayoutSettings {
305    /// The relative width of the left padding of the central pane from the
306    /// workspace when the centered layout is used.
307    ///
308    /// Default: 0.2
309    pub left_padding: Option<f32>,
310    // The relative width of the right padding of the central pane from the
311    // workspace when the centered layout is used.
312    ///
313    /// Default: 0.2
314    pub right_padding: Option<f32>,
315}
316
317#[derive(Copy, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq, Debug)]
318#[serde(rename_all = "snake_case")]
319pub enum OnLastWindowClosed {
320    /// Match platform conventions by default, so don't quit on macOS, and quit on other platforms
321    #[default]
322    PlatformDefault,
323    /// Quit the application the last window is closed
324    QuitApp,
325}
326
327impl OnLastWindowClosed {
328    pub fn is_quit_app(&self) -> bool {
329        match self {
330            OnLastWindowClosed::PlatformDefault => false,
331            OnLastWindowClosed::QuitApp => true,
332        }
333    }
334}
335
336#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
337#[serde(rename_all = "lowercase")]
338pub enum DockPosition {
339    Left,
340    Bottom,
341    Right,
342}