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