mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-24 06:19:37 +00:00
Extract VimModeSetting
to its own crate (#21019)
This PR extracts the `VimModeSetting` out of the `vim` crate and into its own `vim_mode_setting` crate. A number of crates were depending on the entirety of the `vim` crate just to reference `VimModeSetting`, which was not ideal. Release Notes: - N/A
This commit is contained in:
parent
790fdcf737
commit
b102a40e04
13 changed files with 85 additions and 39 deletions
15
Cargo.lock
generated
15
Cargo.lock
generated
|
@ -4236,7 +4236,7 @@ dependencies = [
|
|||
"theme_selector",
|
||||
"ui",
|
||||
"util",
|
||||
"vim",
|
||||
"vim_mode_setting",
|
||||
"wasmtime-wasi",
|
||||
"workspace",
|
||||
"zed_actions",
|
||||
|
@ -13697,10 +13697,20 @@ dependencies = [
|
|||
"tokio",
|
||||
"ui",
|
||||
"util",
|
||||
"vim_mode_setting",
|
||||
"workspace",
|
||||
"zed_actions",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vim_mode_setting"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"gpui",
|
||||
"settings",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vscode_theme"
|
||||
version = "0.2.0"
|
||||
|
@ -14415,7 +14425,7 @@ dependencies = [
|
|||
"theme_selector",
|
||||
"ui",
|
||||
"util",
|
||||
"vim",
|
||||
"vim_mode_setting",
|
||||
"workspace",
|
||||
"zed_actions",
|
||||
]
|
||||
|
@ -15575,6 +15585,7 @@ dependencies = [
|
|||
"uuid",
|
||||
"vcs_menu",
|
||||
"vim",
|
||||
"vim_mode_setting",
|
||||
"welcome",
|
||||
"windows 0.58.0",
|
||||
"winresource",
|
||||
|
|
|
@ -129,6 +129,7 @@ members = [
|
|||
"crates/util",
|
||||
"crates/vcs_menu",
|
||||
"crates/vim",
|
||||
"crates/vim_mode_setting",
|
||||
"crates/welcome",
|
||||
"crates/workspace",
|
||||
"crates/worktree",
|
||||
|
@ -304,6 +305,7 @@ ui_macros = { path = "crates/ui_macros" }
|
|||
util = { path = "crates/util" }
|
||||
vcs_menu = { path = "crates/vcs_menu" }
|
||||
vim = { path = "crates/vim" }
|
||||
vim_mode_setting = { path = "crates/vim_mode_setting" }
|
||||
welcome = { path = "crates/welcome" }
|
||||
workspace = { path = "crates/workspace" }
|
||||
worktree = { path = "crates/worktree" }
|
||||
|
|
|
@ -41,7 +41,7 @@ theme.workspace = true
|
|||
theme_selector.workspace = true
|
||||
ui.workspace = true
|
||||
util.workspace = true
|
||||
vim.workspace = true
|
||||
vim_mode_setting.workspace = true
|
||||
wasmtime-wasi.workspace = true
|
||||
workspace.workspace = true
|
||||
zed_actions.workspace = true
|
||||
|
|
|
@ -27,7 +27,7 @@ use release_channel::ReleaseChannel;
|
|||
use settings::Settings;
|
||||
use theme::ThemeSettings;
|
||||
use ui::{prelude::*, CheckboxWithLabel, ContextMenu, PopoverMenu, ToggleButton, Tooltip};
|
||||
use vim::VimModeSetting;
|
||||
use vim_mode_setting::VimModeSetting;
|
||||
use workspace::{
|
||||
item::{Item, ItemEvent},
|
||||
Workspace, WorkspaceId,
|
||||
|
|
|
@ -39,6 +39,7 @@ settings.workspace = true
|
|||
tokio = { version = "1.15", features = ["full"], optional = true }
|
||||
ui.workspace = true
|
||||
util.workspace = true
|
||||
vim_mode_setting.workspace = true
|
||||
workspace.workspace = true
|
||||
zed_actions.workspace = true
|
||||
|
||||
|
|
|
@ -41,15 +41,11 @@ use state::{Mode, Operator, RecordedSelection, SearchState, VimGlobals};
|
|||
use std::{mem, ops::Range, sync::Arc};
|
||||
use surrounds::SurroundsType;
|
||||
use ui::{IntoElement, VisualContext};
|
||||
use vim_mode_setting::VimModeSetting;
|
||||
use workspace::{self, Pane, Workspace};
|
||||
|
||||
use crate::state::ReplayableAction;
|
||||
|
||||
/// Whether or not to enable Vim mode.
|
||||
///
|
||||
/// Default: false
|
||||
pub struct VimModeSetting(pub bool);
|
||||
|
||||
/// An Action to Switch between modes
|
||||
#[derive(Clone, Deserialize, PartialEq)]
|
||||
pub struct SwitchMode(pub Mode);
|
||||
|
@ -89,7 +85,7 @@ impl_actions!(vim, [SwitchMode, PushOperator, Number, SelectRegister]);
|
|||
|
||||
/// Initializes the `vim` crate.
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
VimModeSetting::register(cx);
|
||||
vim_mode_setting::init(cx);
|
||||
VimSettings::register(cx);
|
||||
VimGlobals::register(cx);
|
||||
|
||||
|
@ -1122,23 +1118,6 @@ impl Vim {
|
|||
}
|
||||
}
|
||||
|
||||
impl Settings for VimModeSetting {
|
||||
const KEY: Option<&'static str> = Some("vim_mode");
|
||||
|
||||
type FileContent = Option<bool>;
|
||||
|
||||
fn load(sources: SettingsSources<Self::FileContent>, _: &mut AppContext) -> Result<Self> {
|
||||
Ok(Self(
|
||||
sources
|
||||
.user
|
||||
.or(sources.server)
|
||||
.copied()
|
||||
.flatten()
|
||||
.unwrap_or(sources.default.ok_or_else(Self::missing_default)?),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
/// Controls when to use system clipboard.
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
|
|
17
crates/vim_mode_setting/Cargo.toml
Normal file
17
crates/vim_mode_setting/Cargo.toml
Normal file
|
@ -0,0 +1,17 @@
|
|||
[package]
|
||||
name = "vim_mode_setting"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
license = "GPL-3.0-or-later"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[lib]
|
||||
path = "src/vim_mode_setting.rs"
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
gpui.workspace = true
|
||||
settings.workspace = true
|
1
crates/vim_mode_setting/LICENSE-GPL
Symbolic link
1
crates/vim_mode_setting/LICENSE-GPL
Symbolic link
|
@ -0,0 +1 @@
|
|||
../../LICENSE-GPL
|
36
crates/vim_mode_setting/src/vim_mode_setting.rs
Normal file
36
crates/vim_mode_setting/src/vim_mode_setting.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
//! Contains the [`VimModeSetting`] used to enable/disable Vim mode.
|
||||
//!
|
||||
//! This is in its own crate as we want other crates to be able to enable or
|
||||
//! disable Vim mode without having to depend on the `vim` crate in its
|
||||
//! entirety.
|
||||
|
||||
use anyhow::Result;
|
||||
use gpui::AppContext;
|
||||
use settings::{Settings, SettingsSources};
|
||||
|
||||
/// Initializes the `vim_mode_setting` crate.
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
VimModeSetting::register(cx);
|
||||
}
|
||||
|
||||
/// Whether or not to enable Vim mode.
|
||||
///
|
||||
/// Default: false
|
||||
pub struct VimModeSetting(pub bool);
|
||||
|
||||
impl Settings for VimModeSetting {
|
||||
const KEY: Option<&'static str> = Some("vim_mode");
|
||||
|
||||
type FileContent = Option<bool>;
|
||||
|
||||
fn load(sources: SettingsSources<Self::FileContent>, _: &mut AppContext) -> Result<Self> {
|
||||
Ok(Self(
|
||||
sources
|
||||
.user
|
||||
.or(sources.server)
|
||||
.copied()
|
||||
.flatten()
|
||||
.unwrap_or(sources.default.ok_or_else(Self::missing_default)?),
|
||||
))
|
||||
}
|
||||
}
|
|
@ -30,7 +30,7 @@ settings.workspace = true
|
|||
theme_selector.workspace = true
|
||||
ui.workspace = true
|
||||
util.workspace = true
|
||||
vim.workspace = true
|
||||
vim_mode_setting.workspace = true
|
||||
workspace.workspace = true
|
||||
zed_actions.workspace = true
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ use gpui::{
|
|||
use settings::{Settings, SettingsStore};
|
||||
use std::sync::Arc;
|
||||
use ui::{prelude::*, CheckboxWithLabel};
|
||||
use vim::VimModeSetting;
|
||||
use vim_mode_setting::VimModeSetting;
|
||||
use workspace::{
|
||||
dock::DockPosition,
|
||||
item::{Item, ItemEvent},
|
||||
|
|
|
@ -119,6 +119,7 @@ util.workspace = true
|
|||
uuid.workspace = true
|
||||
vcs_menu.workspace = true
|
||||
vim.workspace = true
|
||||
vim_mode_setting.workspace = true
|
||||
welcome.workspace = true
|
||||
workspace.workspace = true
|
||||
zed_actions.workspace = true
|
||||
|
|
|
@ -9,7 +9,9 @@ mod open_listener;
|
|||
#[cfg(target_os = "windows")]
|
||||
pub(crate) mod windows_only_instance;
|
||||
|
||||
use anyhow::Context as _;
|
||||
pub use app_menus::*;
|
||||
use assets::Assets;
|
||||
use assistant::PromptBuilder;
|
||||
use breadcrumbs::Breadcrumbs;
|
||||
use client::{zed_urls, ZED_URL_SCHEME};
|
||||
|
@ -18,17 +20,15 @@ use command_palette_hooks::CommandPaletteFilter;
|
|||
use editor::ProposedChangesEditorToolbar;
|
||||
use editor::{scroll::Autoscroll, Editor, MultiBuffer};
|
||||
use feature_flags::FeatureFlagAppExt;
|
||||
use futures::{channel::mpsc, select_biased, StreamExt};
|
||||
use gpui::{
|
||||
actions, point, px, AppContext, AsyncAppContext, Context, FocusableView, MenuItem,
|
||||
PathPromptOptions, PromptLevel, ReadGlobal, Task, TitlebarOptions, View, ViewContext,
|
||||
VisualContext, WindowKind, WindowOptions,
|
||||
};
|
||||
pub use open_listener::*;
|
||||
|
||||
use anyhow::Context as _;
|
||||
use assets::Assets;
|
||||
use futures::{channel::mpsc, select_biased, StreamExt};
|
||||
use outline_panel::OutlinePanel;
|
||||
use paths::{local_settings_file_relative_path, local_tasks_file_relative_path};
|
||||
use project::{DirectoryLister, Item};
|
||||
use project_panel::ProjectPanel;
|
||||
use quick_action_bar::QuickActionBar;
|
||||
|
@ -43,16 +43,14 @@ use settings::{
|
|||
use std::any::TypeId;
|
||||
use std::path::PathBuf;
|
||||
use std::{borrow::Cow, ops::Deref, path::Path, sync::Arc};
|
||||
use theme::ActiveTheme;
|
||||
use workspace::notifications::NotificationId;
|
||||
use workspace::CloseIntent;
|
||||
|
||||
use paths::{local_settings_file_relative_path, local_tasks_file_relative_path};
|
||||
use terminal_view::terminal_panel::{self, TerminalPanel};
|
||||
use theme::ActiveTheme;
|
||||
use util::{asset_str, ResultExt};
|
||||
use uuid::Uuid;
|
||||
use vim::VimModeSetting;
|
||||
use vim_mode_setting::VimModeSetting;
|
||||
use welcome::{BaseKeymap, MultibufferHint};
|
||||
use workspace::notifications::NotificationId;
|
||||
use workspace::CloseIntent;
|
||||
use workspace::{
|
||||
create_and_open_local_file, notifications::simple_message_notification::MessageNotification,
|
||||
open_new, AppState, NewFile, NewWindow, OpenLog, Toast, Workspace, WorkspaceSettings,
|
||||
|
|
Loading…
Reference in a new issue