Skip to content

Commit

Permalink
Extract VimModeSetting to its own crate (#21019)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
maxdeviant authored Nov 21, 2024
1 parent 790fdcf commit b102a40
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 39 deletions.
15 changes: 13 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ members = [
"crates/util",
"crates/vcs_menu",
"crates/vim",
"crates/vim_mode_setting",
"crates/welcome",
"crates/workspace",
"crates/worktree",
Expand Down Expand Up @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion crates/extensions_ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/extensions_ui/src/extensions_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions crates/vim/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 2 additions & 23 deletions crates/vim/src/vim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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")]
Expand Down
17 changes: 17 additions & 0 deletions crates/vim_mode_setting/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions crates/vim_mode_setting/LICENSE-GPL
36 changes: 36 additions & 0 deletions crates/vim_mode_setting/src/vim_mode_setting.rs
Original file line number Diff line number Diff line change
@@ -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)?),
))
}
}
2 changes: 1 addition & 1 deletion crates/welcome/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion crates/welcome/src/welcome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
1 change: 1 addition & 0 deletions crates/zed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 8 additions & 10 deletions crates/zed/src/zed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;
Expand All @@ -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,
Expand Down

0 comments on commit b102a40

Please sign in to comment.