Settings refactor (#38367)
Co-Authored-By: Ben K <ben@zed.dev> Co-Authored-By: Anthony <anthony@zed.dev> Co-Authored-By: Mikayla <mikayla@zed.dev> Release Notes: - settings: Major internal changes to settings. The primary user-facing effect is that some settings which did not make sense in project settings files are no-longer read from there. (For example the inline blame settings) --------- Co-authored-by: Ben Kunkle <ben@zed.dev> Co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com> Co-authored-by: Anthony <anthony@zed.dev>
This commit is contained in:
co-authored by
Ben Kunkle
Mikayla Maki
Anthony
parent
0a9023bce0
commit
fcdab160f9
@@ -2,8 +2,12 @@ use editor::EditorSettings;
|
||||
use gpui::Pixels;
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use settings::{Settings, SettingsKey, SettingsSources, SettingsUi};
|
||||
use ui::scrollbars::{ScrollbarVisibility, ShowScrollbar};
|
||||
use settings::{Settings, SettingsContent, StatusStyle};
|
||||
use ui::{
|
||||
px,
|
||||
scrollbars::{ScrollbarVisibility, ShowScrollbar},
|
||||
};
|
||||
use util::MergeFrom;
|
||||
use workspace::dock::DockPosition;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
|
||||
@@ -19,67 +23,7 @@ pub struct ScrollbarSettings {
|
||||
pub show: Option<ShowScrollbar>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
// Style of the git status indicator in the panel.
|
||||
//
|
||||
// Default: icon
|
||||
pub enum StatusStyleContent {
|
||||
Icon,
|
||||
LabelColor,
|
||||
}
|
||||
|
||||
#[derive(Default, Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum StatusStyle {
|
||||
#[default]
|
||||
Icon,
|
||||
LabelColor,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug, SettingsUi, SettingsKey)]
|
||||
#[settings_key(key = "git_panel")]
|
||||
pub struct GitPanelSettingsContent {
|
||||
/// Whether to show the panel button in the status bar.
|
||||
///
|
||||
/// Default: true
|
||||
pub button: Option<bool>,
|
||||
/// Where to dock the panel.
|
||||
///
|
||||
/// Default: left
|
||||
pub dock: Option<DockPosition>,
|
||||
/// Default width of the panel in pixels.
|
||||
///
|
||||
/// Default: 360
|
||||
pub default_width: Option<f32>,
|
||||
/// How entry statuses are displayed.
|
||||
///
|
||||
/// Default: icon
|
||||
pub status_style: Option<StatusStyle>,
|
||||
/// How and when the scrollbar should be displayed.
|
||||
///
|
||||
/// Default: inherits editor scrollbar settings
|
||||
pub scrollbar: Option<ScrollbarSettings>,
|
||||
|
||||
/// What the default branch name should be when
|
||||
/// `init.defaultBranch` is not set in git
|
||||
///
|
||||
/// Default: main
|
||||
pub fallback_branch_name: Option<String>,
|
||||
|
||||
/// Whether to sort entries in the panel by path
|
||||
/// or by status (the default).
|
||||
///
|
||||
/// Default: false
|
||||
pub sort_by_path: Option<bool>,
|
||||
|
||||
/// Whether to collapse untracked files in the diff panel.
|
||||
///
|
||||
/// Default: false
|
||||
pub collapse_untracked_diff: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct GitPanelSettings {
|
||||
pub button: bool,
|
||||
pub dock: DockPosition,
|
||||
@@ -108,17 +52,50 @@ impl ScrollbarVisibility for GitPanelSettings {
|
||||
}
|
||||
|
||||
impl Settings for GitPanelSettings {
|
||||
type FileContent = GitPanelSettingsContent;
|
||||
|
||||
fn load(
|
||||
sources: SettingsSources<Self::FileContent>,
|
||||
_: &mut gpui::App,
|
||||
) -> anyhow::Result<Self> {
|
||||
sources.json_merge()
|
||||
fn from_defaults(content: &settings::SettingsContent, _cx: &mut ui::App) -> Self {
|
||||
let git_panel = content.git_panel.clone().unwrap();
|
||||
Self {
|
||||
button: git_panel.button.unwrap(),
|
||||
dock: git_panel.dock.unwrap().into(),
|
||||
default_width: px(git_panel.default_width.unwrap()),
|
||||
status_style: git_panel.status_style.unwrap(),
|
||||
scrollbar: ScrollbarSettings {
|
||||
show: git_panel.scrollbar.unwrap().show.map(Into::into),
|
||||
},
|
||||
fallback_branch_name: git_panel.fallback_branch_name.unwrap(),
|
||||
sort_by_path: git_panel.sort_by_path.unwrap(),
|
||||
collapse_untracked_diff: git_panel.collapse_untracked_diff.unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
fn import_from_vscode(vscode: &settings::VsCodeSettings, current: &mut Self::FileContent) {
|
||||
vscode.bool_setting("git.enabled", &mut current.button);
|
||||
vscode.string_setting("git.defaultBranchName", &mut current.fallback_branch_name);
|
||||
fn refine(&mut self, content: &settings::SettingsContent, _cx: &mut ui::App) {
|
||||
let Some(git_panel) = &content.git_panel else {
|
||||
return;
|
||||
};
|
||||
self.button.merge_from(&git_panel.button);
|
||||
self.dock.merge_from(&git_panel.dock.map(Into::into));
|
||||
self.default_width
|
||||
.merge_from(&git_panel.default_width.map(px));
|
||||
self.status_style.merge_from(&git_panel.status_style);
|
||||
self.fallback_branch_name
|
||||
.merge_from(&git_panel.fallback_branch_name);
|
||||
self.sort_by_path.merge_from(&git_panel.sort_by_path);
|
||||
self.collapse_untracked_diff
|
||||
.merge_from(&git_panel.collapse_untracked_diff);
|
||||
if let Some(show) = git_panel.scrollbar.as_ref().and_then(|s| s.show) {
|
||||
self.scrollbar.show = Some(show.into())
|
||||
}
|
||||
}
|
||||
|
||||
fn import_from_vscode(vscode: &settings::VsCodeSettings, current: &mut SettingsContent) {
|
||||
if let Some(git_enabled) = vscode.read_bool("git.enabled") {
|
||||
current.git_panel.get_or_insert_default().button = Some(git_enabled);
|
||||
}
|
||||
if let Some(default_branch) = vscode.read_string("git.defaultBranchName") {
|
||||
current
|
||||
.git_panel
|
||||
.get_or_insert_default()
|
||||
.fallback_branch_name = Some(default_branch.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user