vim_mode_setting.rs

 1//! Contains the [`VimModeSetting`] used to enable/disable Vim mode.
 2//!
 3//! This is in its own crate as we want other crates to be able to enable or
 4//! disable Vim mode without having to depend on the `vim` crate in its
 5//! entirety.
 6
 7use anyhow::Result;
 8use gpui::App;
 9use settings::{Settings, SettingsSources};
10
11/// Initializes the `vim_mode_setting` crate.
12pub fn init(cx: &mut App) {
13    VimModeSetting::register(cx);
14}
15
16/// Whether or not to enable Vim mode.
17///
18/// Default: false
19pub struct VimModeSetting(pub bool);
20
21impl Settings for VimModeSetting {
22    const KEY: Option<&'static str> = Some("vim_mode");
23
24    type FileContent = Option<bool>;
25
26    fn load(sources: SettingsSources<Self::FileContent>, _: &mut App) -> Result<Self> {
27        Ok(Self(
28            sources
29                .user
30                .or(sources.server)
31                .copied()
32                .flatten()
33                .unwrap_or(sources.default.ok_or_else(Self::missing_default)?),
34        ))
35    }
36
37    fn import_from_vscode(_vscode: &settings::VsCodeSettings, _current: &mut Self::FileContent) {
38        // TODO: could possibly check if any of the `vim.<foo>` keys are set?
39    }
40}