1use editor::ShowScrollbar;
2use gpui::Pixels;
3use schemars::JsonSchema;
4use serde_derive::{Deserialize, Serialize};
5use settings::{Settings, 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)]
96pub struct ProjectPanelSettingsContent {
97 /// Whether to show the project panel button in the status bar.
98 ///
99 /// Default: true
100 pub button: Option<bool>,
101 /// Whether to hide gitignore files in the project panel.
102 ///
103 /// Default: false
104 pub hide_gitignore: Option<bool>,
105 /// Customize default width (in pixels) taken by project panel
106 ///
107 /// Default: 240
108 pub default_width: Option<f32>,
109 /// The position of project panel
110 ///
111 /// Default: left
112 pub dock: Option<ProjectPanelDockPosition>,
113 /// Spacing between worktree entries in the project panel.
114 ///
115 /// Default: comfortable
116 pub entry_spacing: Option<EntrySpacing>,
117 /// Whether to show file icons in the project panel.
118 ///
119 /// Default: true
120 pub file_icons: Option<bool>,
121 /// Whether to show folder icons or chevrons for directories in the project panel.
122 ///
123 /// Default: true
124 pub folder_icons: Option<bool>,
125 /// Whether to show the git status in the project panel.
126 ///
127 /// Default: true
128 pub git_status: Option<bool>,
129 /// Amount of indentation (in pixels) for nested items.
130 ///
131 /// Default: 20
132 pub indent_size: Option<f32>,
133 /// Whether to reveal it in the project panel automatically,
134 /// when a corresponding project entry becomes active.
135 /// Gitignored entries are never auto revealed.
136 ///
137 /// Default: true
138 pub auto_reveal_entries: Option<bool>,
139 /// Whether to fold directories automatically
140 /// when directory has only one directory inside.
141 ///
142 /// Default: true
143 pub auto_fold_dirs: Option<bool>,
144 /// Whether the project panel should open on startup.
145 ///
146 /// Default: true
147 pub starts_open: Option<bool>,
148 /// Scrollbar-related settings
149 pub scrollbar: Option<ScrollbarSettingsContent>,
150 /// Which files containing diagnostic errors/warnings to mark in the project panel.
151 ///
152 /// Default: all
153 pub show_diagnostics: Option<ShowDiagnostics>,
154 /// Settings related to indent guides in the project panel.
155 pub indent_guides: Option<IndentGuidesSettingsContent>,
156 /// Whether to hide the root entry when only one folder is open in the window.
157 ///
158 /// Default: false
159 pub hide_root: Option<bool>,
160 /// Whether to stick parent directories at top of the project panel.
161 ///
162 /// Default: true
163 pub sticky_scroll: Option<bool>,
164 /// Whether to enable drag-and-drop operations in the project panel.
165 ///
166 /// Default: true
167 pub drag_and_drop: Option<bool>,
168}
169
170impl Settings for ProjectPanelSettings {
171 const KEY: Option<&'static str> = Some("project_panel");
172
173 type FileContent = ProjectPanelSettingsContent;
174
175 fn load(
176 sources: SettingsSources<Self::FileContent>,
177 _: &mut gpui::App,
178 ) -> anyhow::Result<Self> {
179 sources.json_merge()
180 }
181
182 fn import_from_vscode(vscode: &settings::VsCodeSettings, current: &mut Self::FileContent) {
183 vscode.bool_setting("explorer.excludeGitIgnore", &mut current.hide_gitignore);
184 vscode.bool_setting("explorer.autoReveal", &mut current.auto_reveal_entries);
185 vscode.bool_setting("explorer.compactFolders", &mut current.auto_fold_dirs);
186
187 if Some(false) == vscode.read_bool("git.decorations.enabled") {
188 current.git_status = Some(false);
189 }
190 if Some(false) == vscode.read_bool("problems.decorations.enabled") {
191 current.show_diagnostics = Some(ShowDiagnostics::Off);
192 }
193 if let (Some(false), Some(false)) = (
194 vscode.read_bool("explorer.decorations.badges"),
195 vscode.read_bool("explorer.decorations.colors"),
196 ) {
197 current.git_status = Some(false);
198 current.show_diagnostics = Some(ShowDiagnostics::Off);
199 }
200 }
201}