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
290impl AutosaveSetting {
291 pub fn should_save_on_close(&self) -> bool {
292 matches!(
293 &self,
294 AutosaveSetting::OnFocusChange
295 | AutosaveSetting::OnWindowChange
296 | AutosaveSetting::AfterDelay { .. }
297 )
298 }
299}
300
301#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
302#[serde(rename_all = "snake_case")]
303pub enum PaneSplitDirectionHorizontal {
304 Up,
305 Down,
306}
307
308#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
309#[serde(rename_all = "snake_case")]
310pub enum PaneSplitDirectionVertical {
311 Left,
312 Right,
313}
314
315#[skip_serializing_none]
316#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
317#[serde(rename_all = "snake_case")]
318pub struct CenteredLayoutSettings {
319 /// The relative width of the left padding of the central pane from the
320 /// workspace when the centered layout is used.
321 ///
322 /// Default: 0.2
323 pub left_padding: Option<f32>,
324 // The relative width of the right padding of the central pane from the
325 // workspace when the centered layout is used.
326 ///
327 /// Default: 0.2
328 pub right_padding: Option<f32>,
329}
330
331#[derive(Copy, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq, Debug)]
332#[serde(rename_all = "snake_case")]
333pub enum OnLastWindowClosed {
334 /// Match platform conventions by default, so don't quit on macOS, and quit on other platforms
335 #[default]
336 PlatformDefault,
337 /// Quit the application the last window is closed
338 QuitApp,
339}
340
341impl OnLastWindowClosed {
342 pub fn is_quit_app(&self) -> bool {
343 match self {
344 OnLastWindowClosed::PlatformDefault => false,
345 OnLastWindowClosed::QuitApp => true,
346 }
347 }
348}
349
350#[skip_serializing_none]
351#[derive(Clone, PartialEq, Default, Serialize, Deserialize, JsonSchema, Debug)]
352pub struct ProjectPanelSettingsContent {
353 /// Whether to show the project panel button in the status bar.
354 ///
355 /// Default: true
356 pub button: Option<bool>,
357 /// Whether to hide gitignore files in the project panel.
358 ///
359 /// Default: false
360 pub hide_gitignore: Option<bool>,
361 /// Customize default width (in pixels) taken by project panel
362 ///
363 /// Default: 240
364 pub default_width: Option<f32>,
365 /// The position of project panel
366 ///
367 /// Default: left
368 pub dock: Option<DockSide>,
369 /// Spacing between worktree entries in the project panel.
370 ///
371 /// Default: comfortable
372 pub entry_spacing: Option<ProjectPanelEntrySpacing>,
373 /// Whether to show file icons in the project panel.
374 ///
375 /// Default: true
376 pub file_icons: Option<bool>,
377 /// Whether to show folder icons or chevrons for directories in the project panel.
378 ///
379 /// Default: true
380 pub folder_icons: Option<bool>,
381 /// Whether to show the git status in the project panel.
382 ///
383 /// Default: true
384 pub git_status: Option<bool>,
385 /// Amount of indentation (in pixels) for nested items.
386 ///
387 /// Default: 20
388 pub indent_size: Option<f32>,
389 /// Whether to reveal it in the project panel automatically,
390 /// when a corresponding project entry becomes active.
391 /// Gitignored entries are never auto revealed.
392 ///
393 /// Default: true
394 pub auto_reveal_entries: Option<bool>,
395 /// Whether to fold directories automatically
396 /// when directory has only one directory inside.
397 ///
398 /// Default: true
399 pub auto_fold_dirs: Option<bool>,
400 /// Whether the project panel should open on startup.
401 ///
402 /// Default: true
403 pub starts_open: Option<bool>,
404 /// Scrollbar-related settings
405 pub scrollbar: Option<ScrollbarSettingsContent>,
406 /// Which files containing diagnostic errors/warnings to mark in the project panel.
407 ///
408 /// Default: all
409 pub show_diagnostics: Option<ShowDiagnostics>,
410 /// Settings related to indent guides in the project panel.
411 pub indent_guides: Option<ProjectPanelIndentGuidesSettings>,
412 /// Whether to hide the root entry when only one folder is open in the window.
413 ///
414 /// Default: false
415 pub hide_root: Option<bool>,
416 /// Whether to stick parent directories at top of the project panel.
417 ///
418 /// Default: true
419 pub sticky_scroll: Option<bool>,
420 /// Whether to enable drag-and-drop operations in the project panel.
421 ///
422 /// Default: true
423 pub drag_and_drop: Option<bool>,
424}
425
426#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
427#[serde(rename_all = "snake_case")]
428pub enum ProjectPanelEntrySpacing {
429 /// Comfortable spacing of entries.
430 #[default]
431 Comfortable,
432 /// The standard spacing of entries.
433 Standard,
434}
435
436#[skip_serializing_none]
437#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
438pub struct ProjectPanelIndentGuidesSettings {
439 pub show: Option<ShowIndentGuides>,
440}