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:
Marshall Bowers 2024-11-21 16:24:38 -05:00 committed by GitHub
parent 790fdcf737
commit b102a40e04
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 85 additions and 39 deletions

15
Cargo.lock generated
View file

@ -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",

View file

@ -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" }

View file

@ -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

View file

@ -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,

View file

@ -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

View file

@ -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")]

View 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

View file

@ -0,0 +1 @@
../../LICENSE-GPL

View 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)?),
))
}
}

View file

@ -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

View file

@ -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},

View file

@ -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

View file

@ -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,