project_panel_settings.rs

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