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