use std::num::NonZeroUsize; use collections::HashMap; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use settings_macros::{MergeFrom, with_fallible_options}; use crate::{ CenteredPaddingSettings, DelayMs, DockPosition, DockSide, InactiveOpacity, ScrollbarSettingsContent, ShowIndentGuides, serialize_optional_f32_with_two_decimal_places, }; #[with_fallible_options] #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom)] pub struct WorkspaceSettingsContent { /// Active pane styling settings. pub active_pane_modifiers: Option, /// The text rendering mode to use. /// /// Default: platform_default pub text_rendering_mode: Option, /// Layout mode for the bottom dock /// /// Default: contained pub bottom_dock_layout: Option, /// Direction to split horizontally. /// /// Default: "up" pub pane_split_direction_horizontal: Option, /// Direction to split vertically. /// /// Default: "left" pub pane_split_direction_vertical: Option, /// Centered layout related settings. pub centered_layout: Option, /// Whether or not to prompt the user to confirm before closing the application. /// /// Default: false pub confirm_quit: Option, /// Whether or not to show the call status icon in the status bar. /// /// Default: true pub show_call_status_icon: Option, /// When to automatically save edited buffers. /// /// Default: off pub autosave: Option, /// Controls previous session restoration in freshly launched Zed instance. /// Values: empty_tab, last_workspace, last_session, launchpad /// Default: last_session pub restore_on_startup: Option, /// Whether to attempt to restore previous file's state when opening it again. /// The state is stored per pane. /// When disabled, defaults are applied instead of the state restoration. /// /// 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. /// When disabled, a single selection in the very beginning of the file, zero scroll position and no folds state is used as a default. /// /// Default: true pub restore_on_file_reopen: Option, /// The size of the workspace split drop targets on the outer edges. /// Given as a fraction that will be multiplied by the smaller dimension of the workspace. /// /// Default: `0.2` (20% of the smaller dimension of the workspace) #[serde(serialize_with = "serialize_optional_f32_with_two_decimal_places")] pub drop_target_size: Option, /// Whether to close the window when using 'close active item' on a workspace with no tabs /// /// Default: auto ("on" on macOS, "off" otherwise) pub when_closing_with_no_tabs: Option, /// Whether to use the system provided dialogs for Open and Save As. /// When set to false, Zed will use the built-in keyboard-first pickers. /// /// Default: true pub use_system_path_prompts: Option, /// Whether to use the system provided prompts. /// When set to false, Zed will use the built-in prompts. /// Note that this setting has no effect on Linux, where Zed will always /// use the built-in prompts. /// /// Default: true pub use_system_prompts: Option, /// Aliases for the command palette. When you type a key in this map, /// it will be assumed to equal the value. /// /// Default: true #[serde(default)] pub command_aliases: HashMap, /// Maximum open tabs in a pane. Will not close an unsaved /// tab. Set to `None` for unlimited tabs. /// /// Default: none pub max_tabs: Option, /// What to do when the last window is closed /// /// Default: auto (nothing on macOS, "app quit" otherwise) pub on_last_window_closed: Option, /// Whether to resize all the panels in a dock when resizing the dock. /// /// Default: ["left"] pub resize_all_panels_in_dock: Option>, /// Whether to automatically close files that have been deleted on disk. /// /// Default: false pub close_on_file_delete: Option, /// Whether to allow windows to tab together based on the user’s tabbing preference (macOS only). /// /// Default: false pub use_system_window_tabs: Option, /// Whether to show padding for zoomed panels. /// When enabled, zoomed bottom panels will have some top padding, /// while zoomed left/right panels will have padding to the right/left (respectively). /// /// Default: true pub zoomed_padding: Option, /// What draws window decorations/titlebar, the client application (Zed) or display server /// Default: client pub window_decorations: Option, } #[with_fallible_options] #[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)] pub struct ItemSettingsContent { /// Whether to show the Git file status on a tab item. /// /// Default: false pub git_status: Option, /// Position of the close button in a tab. /// /// Default: right pub close_position: Option, /// Whether to show the file icon for a tab. /// /// Default: false pub file_icons: Option, /// What to do after closing the current tab. /// /// Default: history pub activate_on_close: Option, /// Which files containing diagnostic errors/warnings to mark in the tabs. /// This setting can take the following three values: /// /// Default: off pub show_diagnostics: Option, /// Whether to always show the close button on tabs. /// /// Default: false pub show_close_button: Option, } #[with_fallible_options] #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)] pub struct PreviewTabsSettingsContent { /// Whether to show opened editors as preview tabs. /// 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. /// /// Default: true pub enabled: Option, /// Whether to open tabs in preview mode when opened from the project panel with a single click. /// /// Default: true pub enable_preview_from_project_panel: Option, /// Whether to open tabs in preview mode when selected from the file finder. /// /// Default: false pub enable_preview_from_file_finder: Option, /// Whether to open tabs in preview mode when opened from a multibuffer. /// /// Default: true pub enable_preview_from_multibuffer: Option, /// Whether to open tabs in preview mode when code navigation is used to open a multibuffer. /// /// Default: false pub enable_preview_multibuffer_from_code_navigation: Option, /// Whether to open tabs in preview mode when code navigation is used to open a single file. /// /// Default: true pub enable_preview_file_from_code_navigation: Option, /// Whether to keep tabs in preview mode when code navigation is used to navigate away from them. /// If `enable_preview_file_from_code_navigation` or `enable_preview_multibuffer_from_code_navigation` is also true, the new tab may replace the existing one. /// /// Default: false pub enable_keep_preview_on_code_navigation: Option, } #[derive( Copy, Clone, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom, strum::VariantArray, strum::VariantNames, )] #[serde(rename_all = "lowercase")] pub enum ClosePosition { Left, #[default] Right, } #[derive( Copy, Clone, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom, strum::VariantArray, strum::VariantNames, )] #[serde(rename_all = "lowercase")] pub enum ShowCloseButton { Always, #[default] Hover, Hidden, } #[derive( Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq, strum::VariantArray, strum::VariantNames, )] #[serde(rename_all = "snake_case")] pub enum ShowDiagnostics { #[default] Off, Errors, All, } #[derive( Copy, Clone, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom, strum::VariantArray, strum::VariantNames, )] #[serde(rename_all = "snake_case")] pub enum ActivateOnClose { #[default] History, Neighbour, LeftNeighbour, } #[with_fallible_options] #[derive(Copy, Clone, PartialEq, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom)] #[serde(rename_all = "snake_case")] pub struct ActivePaneModifiers { /// Size of the border surrounding the active pane. /// When set to 0, the active pane doesn't have any border. /// The border is drawn inset. /// /// Default: `0.0` #[serde(serialize_with = "crate::serialize_optional_f32_with_two_decimal_places")] pub border_size: Option, /// Opacity of inactive panels. /// When set to 1.0, the inactive panes have the same opacity as the active one. /// If set to 0, the inactive panes content will not be visible at all. /// Values are clamped to the [0.0, 1.0] range. /// /// Default: `1.0` #[schemars(range(min = 0.0, max = 1.0))] pub inactive_opacity: Option, } #[derive( Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq, JsonSchema, MergeFrom, strum::VariantArray, strum::VariantNames, )] #[serde(rename_all = "snake_case")] pub enum BottomDockLayout { /// Contained between the left and right docks #[default] Contained, /// Takes up the full width of the window Full, /// Extends under the left dock while snapping to the right dock LeftAligned, /// Extends under the right dock while snapping to the left dock RightAligned, } #[derive( Copy, Clone, Default, Debug, Serialize, Deserialize, PartialEq, JsonSchema, MergeFrom, strum::VariantArray, strum::VariantNames, )] #[serde(rename_all = "snake_case")] pub enum WindowDecorations { /// Zed draws its own window decorations/titlebar (client-side decoration) #[default] Client, /// Show system's window titlebar (server-side decoration; not supported by GNOME Wayland) Server, } #[derive( Copy, Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug, strum::VariantArray, strum::VariantNames, )] #[serde(rename_all = "snake_case")] pub enum CloseWindowWhenNoItems { /// Match platform conventions by default, so "on" on macOS and "off" everywhere else #[default] PlatformDefault, /// Close the window when there are no tabs CloseWindow, /// Leave the window open when there are no tabs KeepWindowOpen, } impl CloseWindowWhenNoItems { pub fn should_close(&self) -> bool { match self { CloseWindowWhenNoItems::PlatformDefault => cfg!(target_os = "macos"), CloseWindowWhenNoItems::CloseWindow => true, CloseWindowWhenNoItems::KeepWindowOpen => false, } } } #[derive( Copy, Clone, PartialEq, Eq, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug, strum::VariantArray, strum::VariantNames, )] #[serde(rename_all = "snake_case")] pub enum RestoreOnStartupBehavior { /// Always start with an empty editor tab #[serde(alias = "none")] EmptyTab, /// Restore the workspace that was closed last. LastWorkspace, /// Restore all workspaces that were open when quitting Zed. #[default] LastSession, /// Show the launchpad with recent projects (no tabs). Launchpad, } #[with_fallible_options] #[derive(Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug, PartialEq)] pub struct TabBarSettingsContent { /// Whether or not to show the tab bar in the editor. /// /// Default: true pub show: Option, /// Whether or not to show the navigation history buttons in the tab bar. /// /// Default: true pub show_nav_history_buttons: Option, /// Whether or not to show the tab bar buttons. /// /// Default: true pub show_tab_bar_buttons: Option, } #[with_fallible_options] #[derive(Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug, PartialEq, Eq)] pub struct StatusBarSettingsContent { /// Whether to show the status bar. /// /// Default: true #[serde(rename = "experimental.show")] pub show: Option, /// Whether to display the active language button in the status bar. /// /// Default: true pub active_language_button: Option, /// Whether to show the cursor position button in the status bar. /// /// Default: true pub cursor_position_button: Option, /// Whether to show active line endings button in the status bar. /// /// Default: false pub line_endings_button: Option, } #[derive( Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom, strum::EnumDiscriminants, )] #[strum_discriminants(derive(strum::VariantArray, strum::VariantNames, strum::FromRepr))] #[serde(rename_all = "snake_case")] pub enum AutosaveSetting { /// Disable autosave. Off, /// Save after inactivity period of `milliseconds`. AfterDelay { milliseconds: DelayMs }, /// Autosave when focus changes. OnFocusChange, /// Autosave when the active window changes. OnWindowChange, } impl AutosaveSetting { pub fn should_save_on_close(&self) -> bool { matches!( &self, AutosaveSetting::OnFocusChange | AutosaveSetting::OnWindowChange | AutosaveSetting::AfterDelay { .. } ) } } #[derive( Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom, strum::VariantArray, strum::VariantNames, )] #[serde(rename_all = "snake_case")] pub enum PaneSplitDirectionHorizontal { Up, Down, } #[derive( Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema, MergeFrom, strum::VariantArray, strum::VariantNames, )] #[serde(rename_all = "snake_case")] pub enum PaneSplitDirectionVertical { Left, Right, } #[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Default)] #[serde(rename_all = "snake_case")] #[with_fallible_options] pub struct CenteredLayoutSettings { /// The relative width of the left padding of the central pane from the /// workspace when the centered layout is used. /// /// Default: 0.2 pub left_padding: Option, // The relative width of the right padding of the central pane from the // workspace when the centered layout is used. /// /// Default: 0.2 pub right_padding: Option, } #[derive( Copy, Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Debug, strum::VariantArray, strum::VariantNames, )] #[serde(rename_all = "snake_case")] pub enum OnLastWindowClosed { /// Match platform conventions by default, so don't quit on macOS, and quit on other platforms #[default] PlatformDefault, /// Quit the application the last window is closed QuitApp, } #[derive( Copy, Clone, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq, Debug, strum::VariantArray, strum::VariantNames, )] #[serde(rename_all = "snake_case")] pub enum TextRenderingMode { /// Use platform default behavior. #[default] PlatformDefault, /// Use subpixel (ClearType-style) text rendering. Subpixel, /// Use grayscale text rendering. Grayscale, } impl OnLastWindowClosed { pub fn is_quit_app(&self) -> bool { match self { OnLastWindowClosed::PlatformDefault => false, OnLastWindowClosed::QuitApp => true, } } } #[with_fallible_options] #[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug)] pub struct ProjectPanelAutoOpenSettings { /// Whether to automatically open newly created files in the editor. /// /// Default: true pub on_create: Option, /// Whether to automatically open files after pasting or duplicating them. /// /// Default: true pub on_paste: Option, /// Whether to automatically open files dropped from external sources. /// /// Default: true pub on_drop: Option, } #[with_fallible_options] #[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom, Debug)] pub struct ProjectPanelSettingsContent { /// Whether to show the project panel button in the status bar. /// /// Default: true pub button: Option, /// Whether to hide gitignore files in the project panel. /// /// Default: false pub hide_gitignore: Option, /// Customize default width (in pixels) taken by project panel /// /// Default: 240 #[serde(serialize_with = "crate::serialize_optional_f32_with_two_decimal_places")] pub default_width: Option, /// The position of project panel /// /// Default: left pub dock: Option, /// Spacing between worktree entries in the project panel. /// /// Default: comfortable pub entry_spacing: Option, /// Whether to show file icons in the project panel. /// /// Default: true pub file_icons: Option, /// Whether to show folder icons or chevrons for directories in the project panel. /// /// Default: true pub folder_icons: Option, /// Whether to show the git status in the project panel. /// /// Default: true pub git_status: Option, /// Amount of indentation (in pixels) for nested items. /// /// Default: 20 #[serde(serialize_with = "serialize_optional_f32_with_two_decimal_places")] pub indent_size: Option, /// Whether to reveal it in the project panel automatically, /// when a corresponding project entry becomes active. /// Gitignored entries are never auto revealed. /// /// Default: true pub auto_reveal_entries: Option, /// Whether to fold directories automatically /// when directory has only one directory inside. /// /// Default: true pub auto_fold_dirs: Option, /// Whether the project panel should open on startup. /// /// Default: true pub starts_open: Option, /// Scrollbar-related settings pub scrollbar: Option, /// Which files containing diagnostic errors/warnings to mark in the project panel. /// /// Default: all pub show_diagnostics: Option, /// Settings related to indent guides in the project panel. pub indent_guides: Option, /// Whether to hide the root entry when only one folder is open in the window. /// /// Default: false pub hide_root: Option, /// Whether to hide the hidden entries in the project panel. /// /// Default: false pub hide_hidden: Option, /// Whether to stick parent directories at top of the project panel. /// /// Default: true pub sticky_scroll: Option, /// Whether to enable drag-and-drop operations in the project panel. /// /// Default: true pub drag_and_drop: Option, /// Settings for automatically opening files. pub auto_open: Option, /// How to order sibling entries in the project panel. /// /// Default: directories_first pub sort_mode: Option, } #[derive( Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq, strum::VariantArray, strum::VariantNames, )] #[serde(rename_all = "snake_case")] pub enum ProjectPanelEntrySpacing { /// Comfortable spacing of entries. #[default] Comfortable, /// The standard spacing of entries. Standard, } #[derive( Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq, strum::VariantArray, strum::VariantNames, )] #[serde(rename_all = "snake_case")] pub enum ProjectPanelSortMode { /// Show directories first, then files #[default] DirectoriesFirst, /// Mix directories and files together Mixed, /// Show files first, then directories FilesFirst, } #[with_fallible_options] #[derive( Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, MergeFrom, PartialEq, Eq, Default, )] pub struct ProjectPanelIndentGuidesSettings { pub show: Option, }