This PR separates out the associated constant `KEY` from the `Settings` trait into a new trait `SettingsKey`. This allows for the key trait to be derived using attributes to specify the path so that the new `SettingsUi` derive macro can use the same attributes to determine top level settings paths thereby removing the need to duplicate the path in both `Settings::KEY` and `#[settings_ui(path = "...")]` Co-authored-by: Ben Kunkle <ben@zed.dev> Release Notes: - N/A --------- Co-authored-by: Ben Kunkle <ben@zed.dev>
48 lines
1.1 KiB
Rust
48 lines
1.1 KiB
Rust
//! # zlog_settings
|
|
use anyhow::Result;
|
|
use gpui::App;
|
|
use schemars::JsonSchema;
|
|
use serde::{Deserialize, Serialize};
|
|
use settings::{Settings, SettingsKey, SettingsStore, SettingsUi};
|
|
|
|
pub fn init(cx: &mut App) {
|
|
ZlogSettings::register(cx);
|
|
|
|
cx.observe_global::<SettingsStore>(|cx| {
|
|
let zlog_settings = ZlogSettings::get_global(cx);
|
|
zlog::filter::refresh_from_settings(&zlog_settings.scopes);
|
|
})
|
|
.detach();
|
|
}
|
|
|
|
#[derive(
|
|
Clone,
|
|
Debug,
|
|
Default,
|
|
Serialize,
|
|
Deserialize,
|
|
PartialEq,
|
|
Eq,
|
|
JsonSchema,
|
|
SettingsUi,
|
|
SettingsKey,
|
|
)]
|
|
#[settings_key(key = "log")]
|
|
pub struct ZlogSettings {
|
|
#[serde(default, flatten)]
|
|
pub scopes: std::collections::HashMap<String, String>,
|
|
}
|
|
|
|
impl Settings for ZlogSettings {
|
|
type FileContent = Self;
|
|
|
|
fn load(sources: settings::SettingsSources<Self::FileContent>, _: &mut App) -> Result<Self>
|
|
where
|
|
Self: Sized,
|
|
{
|
|
sources.json_merge()
|
|
}
|
|
|
|
fn import_from_vscode(_vscode: &settings::VsCodeSettings, _current: &mut Self::FileContent) {}
|
|
}
|