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