Basic feature flag implementation
This commit is contained in:
parent
5019ae78c6
commit
9b6116e1e2
5 changed files with 29 additions and 18 deletions
|
@ -10,6 +10,7 @@ use schemars::{
|
|||
};
|
||||
use serde::Deserialize;
|
||||
use serde_json::{value::RawValue, Value};
|
||||
use util::ResultExt;
|
||||
|
||||
#[derive(Deserialize, Default, Clone, JsonSchema)]
|
||||
#[serde(transparent)]
|
||||
|
@ -56,26 +57,27 @@ impl KeymapFileContent {
|
|||
for KeymapBlock { context, bindings } in self.0 {
|
||||
let bindings = bindings
|
||||
.into_iter()
|
||||
.map(|(keystroke, action)| {
|
||||
.filter_map(|(keystroke, action)| {
|
||||
let action = action.0.get();
|
||||
|
||||
// This is a workaround for a limitation in serde: serde-rs/json#497
|
||||
// We want to deserialize the action data as a `RawValue` so that we can
|
||||
// deserialize the action itself dynamically directly from the JSON
|
||||
// string. But `RawValue` currently does not work inside of an untagged enum.
|
||||
let action = if action.starts_with('[') {
|
||||
let ActionWithData(name, data) = serde_json::from_str(action)?;
|
||||
if action.starts_with('[') {
|
||||
let ActionWithData(name, data) = serde_json::from_str(action).log_err()?;
|
||||
cx.deserialize_action(&name, Some(data.get()))
|
||||
} else {
|
||||
let name = serde_json::from_str(action)?;
|
||||
let name = serde_json::from_str(action).log_err()?;
|
||||
cx.deserialize_action(name, None)
|
||||
}
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"invalid binding value for keystroke {keystroke}, context {context:?}"
|
||||
)
|
||||
})?;
|
||||
Binding::load(&keystroke, action, context.as_deref())
|
||||
})
|
||||
.log_err()
|
||||
.map(|action| Binding::load(&keystroke, action, context.as_deref()))
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ pub use keymap_file::{keymap_file_json_schema, KeymapFileContent};
|
|||
|
||||
#[derive(Clone)]
|
||||
pub struct Settings {
|
||||
pub nightly: FeatureFlags,
|
||||
pub projects_online_by_default: bool,
|
||||
pub buffer_font_family: FamilyId,
|
||||
pub default_buffer_font_size: f32,
|
||||
|
@ -38,6 +39,11 @@ pub struct Settings {
|
|||
pub theme: Arc<Theme>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, Deserialize, JsonSchema)]
|
||||
pub struct FeatureFlags {
|
||||
pub modal_terminal: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, JsonSchema)]
|
||||
pub struct EditorSettings {
|
||||
pub tab_size: Option<NonZeroU32>,
|
||||
|
@ -139,6 +145,8 @@ pub enum WorkingDirectory {
|
|||
|
||||
#[derive(Clone, Debug, Default, Deserialize, JsonSchema)]
|
||||
pub struct SettingsFileContent {
|
||||
#[serde(default)]
|
||||
pub nightly: Option<FeatureFlags>,
|
||||
#[serde(default)]
|
||||
pub projects_online_by_default: Option<bool>,
|
||||
#[serde(default)]
|
||||
|
@ -189,6 +197,7 @@ impl Settings {
|
|||
.unwrap();
|
||||
|
||||
Self {
|
||||
nightly: FeatureFlags::default(),
|
||||
buffer_font_family: font_cache
|
||||
.load_family(&[defaults.buffer_font_family.as_ref().unwrap()])
|
||||
.unwrap(),
|
||||
|
@ -247,7 +256,7 @@ impl Settings {
|
|||
);
|
||||
merge(&mut self.vim_mode, data.vim_mode);
|
||||
merge(&mut self.autosave, data.autosave);
|
||||
|
||||
merge(&mut self.nightly, data.nightly);
|
||||
// Ensure terminal font is loaded, so we can request it in terminal_element layout
|
||||
if let Some(terminal_font) = &data.terminal.font_family {
|
||||
font_cache.load_family(&[terminal_font]).log_err();
|
||||
|
@ -308,6 +317,7 @@ impl Settings {
|
|||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub fn test(cx: &gpui::AppContext) -> Settings {
|
||||
Settings {
|
||||
nightly: FeatureFlags::default(),
|
||||
buffer_font_family: cx.font_cache().load_family(&["Monaco"]).unwrap(),
|
||||
buffer_font_size: 14.,
|
||||
default_buffer_font_size: 14.,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue