From 76d1b2291b38a061195bbfc4764df051eb46d4cf Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Wed, 17 Sep 2025 10:39:39 -0600 Subject: [PATCH] More --- Cargo.lock | 1 + .../src/copilot_completion_provider.rs | 2 +- crates/debugger_ui/src/debugger_panel.rs | 2 +- .../file_finder/src/file_finder_settings.rs | 2 - .../image_viewer/src/image_viewer_settings.rs | 42 +++++------- crates/journal/Cargo.toml | 1 + crates/journal/src/journal.rs | 64 +++++-------------- crates/settings/src/settings_content.rs | 26 +++++++- 8 files changed, 59 insertions(+), 81 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5a9ca9a409c622b5cc7b5316b92f43399946e092..de4bd5cc8342c6bfaee8cff3a473616de1cbc8ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8845,6 +8845,7 @@ dependencies = [ "serde", "settings", "shellexpand 2.1.2", + "util", "workspace", "workspace-hack", ] diff --git a/crates/copilot/src/copilot_completion_provider.rs b/crates/copilot/src/copilot_completion_provider.rs index a3f88dd5ae0a0a7279bbf6d4158558d22a5c665a..9184c1b196e316f045cb9790e4d0cd61d3aba0bc 100644 --- a/crates/copilot/src/copilot_completion_provider.rs +++ b/crates/copilot/src/copilot_completion_provider.rs @@ -1125,7 +1125,7 @@ mod tests { Project::init_settings(cx); workspace::init_settings(cx); SettingsStore::update_global(cx, |store: &mut SettingsStore, cx| { - store.update_user_settings(cx, |settings| f(settings.project.all_languages)); + store.update_user_settings(cx, |settings| f(&mut settings.project.all_languages)); }); }); } diff --git a/crates/debugger_ui/src/debugger_panel.rs b/crates/debugger_ui/src/debugger_panel.rs index 7c58e0e802c700d64c350147e1443f6cfbd5e25c..12a31a7360bb6e7fb1ff6fdcaf18f73d679693a3 100644 --- a/crates/debugger_ui/src/debugger_panel.rs +++ b/crates/debugger_ui/src/debugger_panel.rs @@ -1422,7 +1422,7 @@ impl Panel for DebugPanel { } settings::update_settings_file(self.fs.clone(), cx, move |settings, _| { - settings.debugger.get_or_insert_default().dock = position.into(); + settings.debugger.get_or_insert_default().dock = Some(position.into()); }); } diff --git a/crates/file_finder/src/file_finder_settings.rs b/crates/file_finder/src/file_finder_settings.rs index 461a9dae45f9ac3edf46518ac9c20fce20580c3d..22d60160f535b674ef7ab7a3d9d967e924b43bbb 100644 --- a/crates/file_finder/src/file_finder_settings.rs +++ b/crates/file_finder/src/file_finder_settings.rs @@ -36,8 +36,6 @@ impl Settings for FileFinderSettings { self.include_ignored .merge_from(&file_finder.include_ignored); } - - fn import_from_vscode(_vscode: &settings::VsCodeSettings, _current: &mut Self::FileContent) {} } #[derive(Debug, PartialEq, Eq, Clone, Copy, Default, Serialize, Deserialize, JsonSchema)] diff --git a/crates/image_viewer/src/image_viewer_settings.rs b/crates/image_viewer/src/image_viewer_settings.rs index 510de69b522fbb07cb8eedba43edfe3a95e4a591..e093a5fc826fa23c9894ecdb56466dcb71e03465 100644 --- a/crates/image_viewer/src/image_viewer_settings.rs +++ b/crates/image_viewer/src/image_viewer_settings.rs @@ -1,40 +1,30 @@ use gpui::App; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; -use settings::{Settings, SettingsKey, SettingsSources, SettingsUi}; +pub use settings::ImageFileSizeUnit; +use settings::Settings; +use util::MergeFrom; /// The settings for the image viewer. -#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, Default, SettingsUi, SettingsKey)] -#[settings_key(key = "image_viewer")] +#[derive(Clone, Debug, Default)] pub struct ImageViewerSettings { /// The unit to use for displaying image file sizes. /// /// Default: "binary" - #[serde(default)] pub unit: ImageFileSizeUnit, } -#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema, Default)] -#[serde(rename_all = "snake_case")] -pub enum ImageFileSizeUnit { - /// Displays file size in binary units (e.g., KiB, MiB). - #[default] - Binary, - /// Displays file size in decimal units (e.g., KB, MB). - Decimal, -} - impl Settings for ImageViewerSettings { - type FileContent = Self; - - fn load(sources: SettingsSources, _: &mut App) -> anyhow::Result { - SettingsSources::::json_merge_with( - [sources.default] - .into_iter() - .chain(sources.user) - .chain(sources.server), - ) + fn from_defaults(content: &settings::SettingsContent, _cx: &mut App) -> Self { + Self { + unit: content.image_viewer.clone().unwrap().unit.unwrap(), + } } - fn import_from_vscode(_vscode: &settings::VsCodeSettings, _current: &mut Self::FileContent) {} + fn refine(&mut self, content: &settings::SettingsContent, _cx: &mut App) { + self.unit.merge_from( + &content + .image_viewer + .as_ref() + .and_then(|image_viewer| image_viewer.unit), + ); + } } diff --git a/crates/journal/Cargo.toml b/crates/journal/Cargo.toml index 041badd10490a8ea876eb43975a911ca6811fa05..089896cc1edafa760fbe908bcf7d8f689511edca 100644 --- a/crates/journal/Cargo.toml +++ b/crates/journal/Cargo.toml @@ -24,6 +24,7 @@ settings.workspace = true shellexpand.workspace = true workspace.workspace = true workspace-hack.workspace = true +util.workspace = true [dev-dependencies] editor = { workspace = true, features = ["test-support"] } diff --git a/crates/journal/src/journal.rs b/crates/journal/src/journal.rs index 740cc2d2d8ad7149d1615995f2e3ac6b5a216f80..4d0d1a41dafbe466abf61178c6e006b7b86161dc 100644 --- a/crates/journal/src/journal.rs +++ b/crates/journal/src/journal.rs @@ -1,16 +1,15 @@ -use anyhow::Result; use chrono::{Datelike, Local, NaiveTime, Timelike}; use editor::scroll::Autoscroll; use editor::{Editor, SelectionEffects}; use gpui::{App, AppContext as _, Context, Window, actions}; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; -use settings::{Settings, SettingsKey, SettingsSources, SettingsUi}; +pub use settings::HourFormat; +use settings::Settings; use std::{ fs::OpenOptions, path::{Path, PathBuf}, sync::Arc, }; +use util::MergeFrom; use workspace::{AppState, OpenVisible, Workspace}; actions!( @@ -34,34 +33,9 @@ pub struct JournalSettings { pub hour_format: HourFormat, } -impl Default for JournalSettings { - fn default() -> Self { - Self { - path: Some("~".into()), - hour_format: Some(Default::default()), - } - } -} - -#[derive(Clone, Debug, Default)] -pub enum HourFormat { - #[default] - Hour12, - Hour24, -} - -impl From for HourFormat { - fn from(content: settings::HourFormatContent) -> Self { - match content { - settings::HourFormatContent::Hour12 => HourFormat::Hour12, - settings::HourFormatContent::Hour24 => HourFormat::Hour24, - } - } -} - impl settings::Settings for JournalSettings { - fn from_defaults(content: &settings::SettingsContent, cx: &mut App) -> Self { - let journal = content.journal.as_ref().unwrap(); + fn from_defaults(content: &settings::SettingsContent, _cx: &mut App) -> Self { + let journal = content.journal.clone().unwrap(); Self { path: journal.path.unwrap(), @@ -69,21 +43,13 @@ impl settings::Settings for JournalSettings { } } - fn refine(&mut self, content: &settings::SettingsContent, cx: &mut App) { + fn refine(&mut self, content: &settings::SettingsContent, _cx: &mut App) { let Some(journal) = content.journal.as_ref() else { return; }; - - if let Some(path) = journal.path { - self.path = path; - } - - if let Some(hour_format) = journal.hour_format { - self.hour_format = hour_format.into(); - } + self.path.merge_from(&journal.path); + self.hour_format.merge_from(&journal.hour_format); } - - fn import_from_vscode(_vscode: &settings::VsCodeSettings, _current: &mut Self::FileContent) {} } pub fn init(_: Arc, cx: &mut App) { @@ -101,7 +67,7 @@ pub fn init(_: Arc, cx: &mut App) { pub fn new_journal_entry(workspace: &Workspace, window: &mut Window, cx: &mut App) { let settings = JournalSettings::get_global(cx); - let journal_dir = match journal_dir(settings.path.as_ref().unwrap()) { + let journal_dir = match journal_dir(&settings.path) { Some(journal_dir) => journal_dir, None => { log::error!("Can't determine journal directory"); @@ -223,13 +189,13 @@ fn journal_dir(path: &str) -> Option { .map(|dir| Path::new(&dir.to_string()).to_path_buf().join("journal")) } -fn heading_entry(now: NaiveTime, hour_format: &Option) -> String { +fn heading_entry(now: NaiveTime, hour_format: &HourFormat) -> String { match hour_format { - Some(HourFormat::Hour24) => { + HourFormat::Hour24 => { let hour = now.hour(); format!("# {}:{:02}", hour, now.minute()) } - _ => { + HourFormat::Hour12 => { let (pm, hour) = now.hour12(); let am_or_pm = if pm { "PM" } else { "AM" }; format!("# {}:{:02} {}", hour, now.minute(), am_or_pm) @@ -245,7 +211,7 @@ mod tests { #[test] fn test_heading_entry_defaults_to_hour_12() { let naive_time = NaiveTime::from_hms_milli_opt(15, 0, 0, 0).unwrap(); - let actual_heading_entry = heading_entry(naive_time, &None); + let actual_heading_entry = heading_entry(naive_time, &HourFormat::Hour12); let expected_heading_entry = "# 3:00 PM"; assert_eq!(actual_heading_entry, expected_heading_entry); @@ -254,7 +220,7 @@ mod tests { #[test] fn test_heading_entry_is_hour_12() { let naive_time = NaiveTime::from_hms_milli_opt(15, 0, 0, 0).unwrap(); - let actual_heading_entry = heading_entry(naive_time, &Some(HourFormat::Hour12)); + let actual_heading_entry = heading_entry(naive_time, &HourFormat::Hour12); let expected_heading_entry = "# 3:00 PM"; assert_eq!(actual_heading_entry, expected_heading_entry); @@ -263,7 +229,7 @@ mod tests { #[test] fn test_heading_entry_is_hour_24() { let naive_time = NaiveTime::from_hms_milli_opt(15, 0, 0, 0).unwrap(); - let actual_heading_entry = heading_entry(naive_time, &Some(HourFormat::Hour24)); + let actual_heading_entry = heading_entry(naive_time, &HourFormat::Hour24); let expected_heading_entry = "# 15:00"; assert_eq!(actual_heading_entry, expected_heading_entry); diff --git a/crates/settings/src/settings_content.rs b/crates/settings/src/settings_content.rs index c9970dd1185e6eaac2de6b893c14d0e988bc2246..652506e5937688ac0d1be8be5ddf1044db7140c9 100644 --- a/crates/settings/src/settings_content.rs +++ b/crates/settings/src/settings_content.rs @@ -79,6 +79,9 @@ pub struct SettingsContent { /// Common language server settings. pub global_lsp_settings: Option, + /// The settings for the image viewer. + pub image_viewer: Option, + /// Whether or not to enable Helix mode. /// /// Default: false @@ -593,12 +596,12 @@ pub struct JournalSettingsContent { /// What format to display the hours in. /// /// Default: hour12 - pub hour_format: Option, + pub hour_format: Option, } #[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq)] #[serde(rename_all = "snake_case")] -pub enum HourFormatContent { +pub enum HourFormat { #[default] Hour12, Hour24, @@ -685,3 +688,22 @@ pub enum LineIndicatorFormat { #[default] Long, } + +/// The settings for the image viewer. +#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, Default, PartialEq)] +pub struct ImageViewerSettingsContent { + /// The unit to use for displaying image file sizes. + /// + /// Default: "binary" + pub unit: Option, +} + +#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema, Default, PartialEq)] +#[serde(rename_all = "snake_case")] +pub enum ImageFileSizeUnit { + /// Displays file size in binary units (e.g., KiB, MiB). + #[default] + Binary, + /// Displays file size in decimal units (e.g., KB, MB). + Decimal, +}