1use editor::ShowScrollbar;
2use gpui::Pixels;
3use schemars::JsonSchema;
4use serde_derive::{Deserialize, Serialize};
5use settings::{Settings, SettingsSources};
6
7#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, Copy, PartialEq)]
8#[serde(rename_all = "snake_case")]
9pub enum ProjectPanelDockPosition {
10 Left,
11 Right,
12}
13
14#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
15#[serde(rename_all = "snake_case")]
16pub enum ShowIndentGuides {
17 Always,
18 Never,
19}
20
21#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
22#[serde(rename_all = "snake_case")]
23pub enum EntrySpacing {
24 /// Comfortable spacing of entries.
25 #[default]
26 Comfortable,
27 /// The standard spacing of entries.
28 Standard,
29}
30
31#[derive(Deserialize, Debug, Clone, Copy, PartialEq)]
32pub struct ProjectPanelSettings {
33 pub button: bool,
34 pub default_width: Pixels,
35 pub dock: ProjectPanelDockPosition,
36 pub entry_spacing: EntrySpacing,
37 pub file_icons: bool,
38 pub folder_icons: bool,
39 pub git_status: bool,
40 pub indent_size: f32,
41 pub indent_guides: IndentGuidesSettings,
42 pub auto_reveal_entries: bool,
43 pub auto_fold_dirs: bool,
44 pub scrollbar: ScrollbarSettings,
45 pub show_diagnostics: ShowDiagnostics,
46}
47
48#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
49pub struct IndentGuidesSettings {
50 pub show: ShowIndentGuides,
51}
52
53#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
54pub struct IndentGuidesSettingsContent {
55 /// When to show the scrollbar in the project panel.
56 pub show: Option<ShowIndentGuides>,
57}
58
59#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
60pub struct ScrollbarSettings {
61 /// When to show the scrollbar in the project panel.
62 ///
63 /// Default: inherits editor scrollbar settings
64 pub show: Option<ShowScrollbar>,
65}
66
67#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
68pub struct ScrollbarSettingsContent {
69 /// When to show the scrollbar in the project panel.
70 ///
71 /// Default: inherits editor scrollbar settings
72 pub show: Option<Option<ShowScrollbar>>,
73}
74
75/// Whether to indicate diagnostic errors and/or warnings in project panel items.
76///
77/// Default: all
78#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
79#[serde(rename_all = "snake_case")]
80pub enum ShowDiagnostics {
81 /// Never mark the diagnostic errors/warnings in the project panel.
82 Off,
83 /// Mark files containing only diagnostic errors in the project panel.
84 Errors,
85 #[default]
86 /// Mark files containing diagnostic errors or warnings in the project panel.
87 All,
88}
89
90#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
91pub struct ProjectPanelSettingsContent {
92 /// Whether to show the project panel button in the status bar.
93 ///
94 /// Default: true
95 pub button: Option<bool>,
96 /// Customize default width (in pixels) taken by project panel
97 ///
98 /// Default: 240
99 pub default_width: Option<f32>,
100 /// The position of project panel
101 ///
102 /// Default: left
103 pub dock: Option<ProjectPanelDockPosition>,
104 /// Spacing between worktree entries in the project panel.
105 ///
106 /// Default: comfortable
107 pub entry_spacing: Option<EntrySpacing>,
108 /// Whether to show file icons in the project panel.
109 ///
110 /// Default: true
111 pub file_icons: Option<bool>,
112 /// Whether to show folder icons or chevrons for directories in the project panel.
113 ///
114 /// Default: true
115 pub folder_icons: Option<bool>,
116 /// Whether to show the git status in the project panel.
117 ///
118 /// Default: true
119 pub git_status: Option<bool>,
120 /// Amount of indentation (in pixels) for nested items.
121 ///
122 /// Default: 20
123 pub indent_size: Option<f32>,
124 /// Whether to reveal it in the project panel automatically,
125 /// when a corresponding project entry becomes active.
126 /// Gitignored entries are never auto revealed.
127 ///
128 /// Default: true
129 pub auto_reveal_entries: Option<bool>,
130 /// Whether to fold directories automatically
131 /// when directory has only one directory inside.
132 ///
133 /// Default: true
134 pub auto_fold_dirs: Option<bool>,
135 /// Scrollbar-related settings
136 pub scrollbar: Option<ScrollbarSettingsContent>,
137 /// Which files containing diagnostic errors/warnings to mark in the project panel.
138 ///
139 /// Default: all
140 pub show_diagnostics: Option<ShowDiagnostics>,
141 /// Settings related to indent guides in the project panel.
142 pub indent_guides: Option<IndentGuidesSettingsContent>,
143}
144
145impl Settings for ProjectPanelSettings {
146 const KEY: Option<&'static str> = Some("project_panel");
147
148 type FileContent = ProjectPanelSettingsContent;
149
150 fn load(
151 sources: SettingsSources<Self::FileContent>,
152 _: &mut gpui::App,
153 ) -> anyhow::Result<Self> {
154 sources.json_merge()
155 }
156}