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(Deserialize, Debug, Clone, Copy, PartialEq)]
 22pub struct ProjectPanelSettings {
 23    pub button: bool,
 24    pub default_width: Pixels,
 25    pub dock: ProjectPanelDockPosition,
 26    pub file_icons: bool,
 27    pub folder_icons: bool,
 28    pub git_status: bool,
 29    pub indent_size: f32,
 30    pub indent_guides: IndentGuidesSettings,
 31    pub auto_reveal_entries: bool,
 32    pub auto_fold_dirs: bool,
 33    pub scrollbar: ScrollbarSettings,
 34    pub show_diagnostics: ShowDiagnostics,
 35}
 36
 37#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 38pub struct IndentGuidesSettings {
 39    pub show: ShowIndentGuides,
 40}
 41
 42#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 43pub struct IndentGuidesSettingsContent {
 44    /// When to show the scrollbar in the project panel.
 45    pub show: Option<ShowIndentGuides>,
 46}
 47
 48#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 49pub struct ScrollbarSettings {
 50    /// When to show the scrollbar in the project panel.
 51    ///
 52    /// Default: inherits editor scrollbar settings
 53    pub show: Option<ShowScrollbar>,
 54}
 55
 56#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 57pub struct ScrollbarSettingsContent {
 58    /// When to show the scrollbar in the project panel.
 59    ///
 60    /// Default: inherits editor scrollbar settings
 61    pub show: Option<Option<ShowScrollbar>>,
 62}
 63
 64/// Whether to indicate diagnostic errors and/or warnings in project panel items.
 65///
 66/// Default: all
 67#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 68#[serde(rename_all = "snake_case")]
 69pub enum ShowDiagnostics {
 70    /// Never mark the diagnostic errors/warnings in the project panel.
 71    Off,
 72    /// Mark files containing only diagnostic errors in the project panel.
 73    Errors,
 74    #[default]
 75    /// Mark files containing diagnostic errors or warnings in the project panel.
 76    All,
 77}
 78
 79#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
 80pub struct ProjectPanelSettingsContent {
 81    /// Whether to show the project panel button in the status bar.
 82    ///
 83    /// Default: true
 84    pub button: Option<bool>,
 85    /// Customize default width (in pixels) taken by project panel
 86    ///
 87    /// Default: 240
 88    pub default_width: Option<f32>,
 89    /// The position of project panel
 90    ///
 91    /// Default: left
 92    pub dock: Option<ProjectPanelDockPosition>,
 93    /// Whether to show file icons in the project panel.
 94    ///
 95    /// Default: true
 96    pub file_icons: Option<bool>,
 97    /// Whether to show folder icons or chevrons for directories in the project panel.
 98    ///
 99    /// Default: true
100    pub folder_icons: Option<bool>,
101    /// Whether to show the git status in the project panel.
102    ///
103    /// Default: true
104    pub git_status: Option<bool>,
105    /// Amount of indentation (in pixels) for nested items.
106    ///
107    /// Default: 20
108    pub indent_size: Option<f32>,
109    /// Whether to reveal it in the project panel automatically,
110    /// when a corresponding project entry becomes active.
111    /// Gitignored entries are never auto revealed.
112    ///
113    /// Default: true
114    pub auto_reveal_entries: Option<bool>,
115    /// Whether to fold directories automatically
116    /// when directory has only one directory inside.
117    ///
118    /// Default: true
119    pub auto_fold_dirs: Option<bool>,
120    /// Scrollbar-related settings
121    pub scrollbar: Option<ScrollbarSettingsContent>,
122    /// Which files containing diagnostic errors/warnings to mark in the project panel.
123    ///
124    /// Default: all
125    pub show_diagnostics: Option<ShowDiagnostics>,
126    /// Settings related to indent guides in the project panel.
127    pub indent_guides: Option<IndentGuidesSettingsContent>,
128}
129
130impl Settings for ProjectPanelSettings {
131    const KEY: Option<&'static str> = Some("project_panel");
132
133    type FileContent = ProjectPanelSettingsContent;
134
135    fn load(
136        sources: SettingsSources<Self::FileContent>,
137        _: &mut gpui::AppContext,
138    ) -> anyhow::Result<Self> {
139        sources.json_merge()
140    }
141}