Define vim_mode setting in vim crate

This commit is contained in:
Max Brunsfeld 2023-05-10 11:06:55 -07:00
parent 926d7b356d
commit 9b06be2aa2
5 changed files with 70 additions and 21 deletions

View file

@ -43,7 +43,6 @@ pub struct Settings {
pub hover_popover_enabled: bool,
pub show_completions_on_input: bool,
pub show_call_status_icon: bool,
pub vim_mode: bool,
pub autosave: Autosave,
pub default_dock_anchor: DockAnchor,
pub editor_defaults: EditorSettings,
@ -65,6 +64,8 @@ pub struct Settings {
}
impl Setting for Settings {
const KEY: Option<&'static str> = None;
type FileContent = SettingsFileContent;
fn load(
@ -93,7 +94,6 @@ impl Setting for Settings {
hover_popover_enabled: defaults.hover_popover_enabled.unwrap(),
show_completions_on_input: defaults.show_completions_on_input.unwrap(),
show_call_status_icon: defaults.show_call_status_icon.unwrap(),
vim_mode: defaults.vim_mode.unwrap(),
autosave: defaults.autosave.unwrap(),
default_dock_anchor: defaults.default_dock_anchor.unwrap(),
editor_defaults: EditorSettings {
@ -550,8 +550,6 @@ pub struct SettingsFileContent {
#[serde(default)]
pub show_call_status_icon: Option<bool>,
#[serde(default)]
pub vim_mode: Option<bool>,
#[serde(default)]
pub autosave: Option<Autosave>,
#[serde(default)]
pub default_dock_anchor: Option<DockAnchor>,
@ -647,7 +645,6 @@ impl Settings {
hover_popover_enabled: defaults.hover_popover_enabled.unwrap(),
show_completions_on_input: defaults.show_completions_on_input.unwrap(),
show_call_status_icon: defaults.show_call_status_icon.unwrap(),
vim_mode: defaults.vim_mode.unwrap(),
autosave: defaults.autosave.unwrap(),
default_dock_anchor: defaults.default_dock_anchor.unwrap(),
editor_defaults: EditorSettings {
@ -741,7 +738,6 @@ impl Settings {
&mut self.show_completions_on_input,
data.show_completions_on_input,
);
merge(&mut self.vim_mode, data.vim_mode);
merge(&mut self.autosave, data.autosave);
merge(&mut self.default_dock_anchor, data.default_dock_anchor);
merge(&mut self.base_keymap, data.base_keymap);
@ -940,7 +936,6 @@ impl Settings {
hover_popover_enabled: true,
show_completions_on_input: true,
show_call_status_icon: true,
vim_mode: false,
autosave: Autosave::Off,
default_dock_anchor: DockAnchor::Bottom,
editor_defaults: EditorSettings {

View file

@ -23,7 +23,7 @@ pub trait Setting: 'static {
/// The name of a key within the JSON file from which this setting should
/// be deserialized. If this is `None`, then the setting will be deserialized
/// from the root object.
const KEY: Option<&'static str> = None;
const KEY: Option<&'static str>;
/// The type that is stored in an individual JSON file.
type FileContent: Clone + Serialize + DeserializeOwned + JsonSchema;
@ -165,6 +165,28 @@ impl SettingsStore {
.expect("no default value for setting type")
}
/// Get the user's settings as a raw JSON value.
///
/// This is only for debugging and reporting. For user-facing functionality,
/// use the typed setting interface.
pub fn untyped_user_settings(&self) -> &serde_json::Value {
self.user_deserialized_settings
.as_ref()
.map_or(&serde_json::Value::Null, |s| &s.untyped)
}
/// Override the global value for a particular setting.
///
/// This is only for tests. Normally, settings are only loaded from
/// JSON files.
#[cfg(any(test, feature = "test-support"))]
pub fn replace_value<T: Setting>(&mut self, value: T) {
self.setting_values
.get_mut(&TypeId::of::<T>())
.expect("unregistered setting type")
.set_global_value(Box::new(value))
}
/// Update the value of a setting.
///
/// Returns a list of edits to apply to the JSON file.
@ -1164,6 +1186,8 @@ mod tests {
}
impl Setting for MultiKeySettings {
const KEY: Option<&'static str> = None;
type FileContent = MultiKeySettingsJson;
fn load(