Cargo.lock 🔗
@@ -8845,6 +8845,7 @@ dependencies = [
"serde",
"settings",
"shellexpand 2.1.2",
+ "util",
"workspace",
"workspace-hack",
]
Conrad Irwin created
Cargo.lock | 1
crates/copilot/src/copilot_completion_provider.rs | 2
crates/debugger_ui/src/debugger_panel.rs | 2
crates/file_finder/src/file_finder_settings.rs | 2
crates/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(-)
@@ -8845,6 +8845,7 @@ dependencies = [
"serde",
"settings",
"shellexpand 2.1.2",
+ "util",
"workspace",
"workspace-hack",
]
@@ -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));
});
});
}
@@ -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());
});
}
@@ -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)]
@@ -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<Self::FileContent>, _: &mut App) -> anyhow::Result<Self> {
- SettingsSources::<Self::FileContent>::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),
+ );
+ }
}
@@ -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"] }
@@ -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<settings::HourFormatContent> 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<AppState>, cx: &mut App) {
@@ -101,7 +67,7 @@ pub fn init(_: Arc<AppState>, 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<PathBuf> {
.map(|dir| Path::new(&dir.to_string()).to_path_buf().join("journal"))
}
-fn heading_entry(now: NaiveTime, hour_format: &Option<HourFormat>) -> 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);
@@ -79,6 +79,9 @@ pub struct SettingsContent {
/// Common language server settings.
pub global_lsp_settings: Option<GlobalLspSettingsContent>,
+ /// The settings for the image viewer.
+ pub image_viewer: Option<ImageViewerSettingsContent>,
+
/// 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<HourFormatContent>,
+ pub hour_format: Option<HourFormat>,
}
#[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<ImageFileSizeUnit>,
+}
+
+#[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,
+}