1use editor::ShowScrollbar;
2use gpui::Pixels;
3use schemars::JsonSchema;
4use serde_derive::{Deserialize, Serialize};
5use settings::{Settings, SettingsKey, SettingsSources, SettingsUi};
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 hide_gitignore: bool,
35 pub default_width: Pixels,
36 pub dock: ProjectPanelDockPosition,
37 pub entry_spacing: EntrySpacing,
38 pub file_icons: bool,
39 pub folder_icons: bool,
40 pub git_status: bool,
41 pub indent_size: f32,
42 pub indent_guides: IndentGuidesSettings,
43 pub sticky_scroll: bool,
44 pub auto_reveal_entries: bool,
45 pub auto_fold_dirs: bool,
46 pub starts_open: bool,
47 pub scrollbar: ScrollbarSettings,
48 pub show_diagnostics: ShowDiagnostics,
49 pub hide_root: bool,
50 pub drag_and_drop: bool,
51}
52
53#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
54pub struct IndentGuidesSettings {
55 pub show: ShowIndentGuides,
56}
57
58#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
59pub struct IndentGuidesSettingsContent {
60 /// When to show the scrollbar in the project panel.
61 pub show: Option<ShowIndentGuides>,
62}
63
64#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
65pub struct ScrollbarSettings {
66 /// When to show the scrollbar in the project panel.
67 ///
68 /// Default: inherits editor scrollbar settings
69 pub show: Option<ShowScrollbar>,
70}
71
72#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
73pub struct ScrollbarSettingsContent {
74 /// When to show the scrollbar in the project panel.
75 ///
76 /// Default: inherits editor scrollbar settings
77 pub show: Option<Option<ShowScrollbar>>,
78}
79
80/// Whether to indicate diagnostic errors and/or warnings in project panel items.
81///
82/// Default: all
83#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
84#[serde(rename_all = "snake_case")]
85pub enum ShowDiagnostics {
86 /// Never mark the diagnostic errors/warnings in the project panel.
87 Off,
88 /// Mark files containing only diagnostic errors in the project panel.
89 Errors,
90 #[default]
91 /// Mark files containing diagnostic errors or warnings in the project panel.
92 All,
93}
94
95#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug, SettingsUi, SettingsKey)]
96#[settings_key(key = "project_panel")]
97pub struct ProjectPanelSettingsContent {
98 /// Whether to show the project panel button in the status bar.
99 ///
100 /// Default: true
101 pub button: Option<bool>,
102 /// Whether to hide gitignore files in the project panel.
103 ///
104 /// Default: false
105 pub hide_gitignore: Option<bool>,
106 /// Customize default width (in pixels) taken by project panel
107 ///
108 /// Default: 240
109 pub default_width: Option<f32>,
110 /// The position of project panel
111 ///
112 /// Default: left
113 pub dock: Option<ProjectPanelDockPosition>,
114 /// Spacing between worktree entries in the project panel.
115 ///
116 /// Default: comfortable
117 pub entry_spacing: Option<EntrySpacing>,
118 /// Whether to show file icons in the project panel.
119 ///
120 /// Default: true
121 pub file_icons: Option<bool>,
122 /// Whether to show folder icons or chevrons for directories in the project panel.
123 ///
124 /// Default: true
125 pub folder_icons: Option<bool>,
126 /// Whether to show the git status in the project panel.
127 ///
128 /// Default: true
129 pub git_status: Option<bool>,
130 /// Amount of indentation (in pixels) for nested items.
131 ///
132 /// Default: 20
133 pub indent_size: Option<f32>,
134 /// Whether to reveal it in the project panel automatically,
135 /// when a corresponding project entry becomes active.
136 /// Gitignored entries are never auto revealed.
137 ///
138 /// Default: true
139 pub auto_reveal_entries: Option<bool>,
140 /// Whether to fold directories automatically
141 /// when directory has only one directory inside.
142 ///
143 /// Default: true
144 pub auto_fold_dirs: Option<bool>,
145 /// Whether the project panel should open on startup.
146 ///
147 /// Default: true
148 pub starts_open: Option<bool>,
149 /// Scrollbar-related settings
150 pub scrollbar: Option<ScrollbarSettingsContent>,
151 /// Which files containing diagnostic errors/warnings to mark in the project panel.
152 ///
153 /// Default: all
154 pub show_diagnostics: Option<ShowDiagnostics>,
155 /// Settings related to indent guides in the project panel.
156 pub indent_guides: Option<IndentGuidesSettingsContent>,
157 /// Whether to hide the root entry when only one folder is open in the window.
158 ///
159 /// Default: false
160 pub hide_root: Option<bool>,
161 /// Whether to stick parent directories at top of the project panel.
162 ///
163 /// Default: true
164 pub sticky_scroll: Option<bool>,
165 /// Whether to enable drag-and-drop operations in the project panel.
166 ///
167 /// Default: true
168 pub drag_and_drop: Option<bool>,
169}
170
171impl Settings for ProjectPanelSettings {
172 type FileContent = ProjectPanelSettingsContent;
173
174 fn load(
175 sources: SettingsSources<Self::FileContent>,
176 _: &mut gpui::App,
177 ) -> anyhow::Result<Self> {
178 sources.json_merge()
179 }
180
181 fn import_from_vscode(vscode: &settings::VsCodeSettings, current: &mut Self::FileContent) {
182 vscode.bool_setting("explorer.excludeGitIgnore", &mut current.hide_gitignore);
183 vscode.bool_setting("explorer.autoReveal", &mut current.auto_reveal_entries);
184 vscode.bool_setting("explorer.compactFolders", &mut current.auto_fold_dirs);
185
186 if Some(false) == vscode.read_bool("git.decorations.enabled") {
187 current.git_status = Some(false);
188 }
189 if Some(false) == vscode.read_bool("problems.decorations.enabled") {
190 current.show_diagnostics = Some(ShowDiagnostics::Off);
191 }
192 if let (Some(false), Some(false)) = (
193 vscode.read_bool("explorer.decorations.badges"),
194 vscode.read_bool("explorer.decorations.colors"),
195 ) {
196 current.git_status = Some(false);
197 current.show_diagnostics = Some(ShowDiagnostics::Off);
198 }
199 }
200}