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:
Conrad Irwin
2025-09-18 16:47:23 +00:00
committed by GitHub
co-authored by Ben Kunkle Mikayla Maki Anthony
parent 0a9023bce0
commit fcdab160f9
219 changed files with 11697 additions and 11894 deletions
+2 -1
View File
@@ -139,7 +139,8 @@ impl BlameRenderer for GitBlameRenderer {
let author = blame_entry.author.as_deref().unwrap_or_default();
let summary_enabled = ProjectSettings::get_global(cx)
.git
.show_inline_commit_summary();
.inline_blame
.show_commit_summary;
let text = match blame_entry.summary.as_ref() {
Some(summary) if summary_enabled => {
-1
View File
@@ -564,7 +564,6 @@ impl PickerDelegate for BranchListDelegate {
let show_author_name = ProjectSettings::get_global(cx)
.git
.branch_picker
.unwrap_or_default()
.show_author_name;
subject.map_or("no commits found".into(), |subject| {
+7 -9
View File
@@ -2,7 +2,6 @@ use crate::askpass_modal::AskPassModal;
use crate::commit_modal::CommitModal;
use crate::commit_tooltip::CommitTooltip;
use crate::commit_view::CommitView;
use crate::git_panel_settings::StatusStyle;
use crate::project_diff::{self, Diff, ProjectDiff};
use crate::remote_output::{self, RemoteAction, SuccessMessage};
use crate::{branch_picker, picker_prompt, render_remote_button};
@@ -51,7 +50,7 @@ use project::{
git_store::{GitStoreEvent, Repository, RepositoryEvent, RepositoryId},
};
use serde::{Deserialize, Serialize};
use settings::{Settings, SettingsStore};
use settings::{Settings, SettingsStore, StatusStyle};
use std::future::Future;
use std::ops::Range;
use std::path::{Path, PathBuf};
@@ -2439,8 +2438,9 @@ impl GitPanel {
let workspace = workspace.read(cx);
let fs = workspace.app_state().fs.clone();
cx.update_global::<SettingsStore, _>(|store, _cx| {
store.update_settings_file::<GitPanelSettings>(fs, move |settings, _cx| {
settings.sort_by_path = Some(!current_setting);
store.update_settings_file(fs, move |settings, _cx| {
settings.git_panel.get_or_insert_default().sort_by_path =
Some(!current_setting);
});
});
}
@@ -4356,11 +4356,9 @@ impl Panel for GitPanel {
}
fn set_position(&mut self, position: DockPosition, _: &mut Window, cx: &mut Context<Self>) {
settings::update_settings_file::<GitPanelSettings>(
self.fs.clone(),
cx,
move |settings, _| settings.dock = Some(position),
);
settings::update_settings_file(self.fs.clone(), cx, move |settings, _| {
settings.git_panel.get_or_insert_default().dock = Some(position.into())
});
}
fn size(&self, _: &Window, cx: &App) -> Pixels {
+50 -73
View File
@@ -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());
}
}
}