vim_mode_setting -> editor_mode_setting

This commit is contained in:
Smit Barmase 2025-08-22 17:59:37 +05:30
parent ea5425f818
commit 1e4614f9a0
No known key found for this signature in database
29 changed files with 64 additions and 70 deletions

44
Cargo.lock generated
View file

@ -313,6 +313,7 @@ dependencies = [
"anyhow",
"cloud_llm_client",
"collections",
"editor_mode_setting",
"fs",
"gpui",
"language_model",
@ -322,7 +323,6 @@ dependencies = [
"serde_json",
"serde_json_lenient",
"settings",
"vim_mode_setting",
"workspace-hack",
]
@ -355,6 +355,7 @@ dependencies = [
"context_server",
"db",
"editor",
"editor_mode_setting",
"extension",
"extension_host",
"feature_flags",
@ -416,7 +417,6 @@ dependencies = [
"urlencoding",
"util",
"uuid",
"vim_mode_setting",
"watch",
"workspace",
"workspace-hack",
@ -4549,6 +4549,7 @@ dependencies = [
"db",
"debugger_tools",
"editor",
"editor_mode_setting",
"file_icons",
"futures 0.3.31",
"fuzzy",
@ -4586,7 +4587,6 @@ dependencies = [
"ui",
"unindent",
"util",
"vim_mode_setting",
"workspace",
"workspace-hack",
"zed_actions",
@ -5064,6 +5064,7 @@ dependencies = [
"dap",
"db",
"edit_prediction",
"editor_mode_setting",
"emojis",
"file_icons",
"fs",
@ -5118,13 +5119,25 @@ dependencies = [
"url",
"util",
"uuid",
"vim_mode_setting",
"workspace",
"workspace-hack",
"zed_actions",
"zlog",
]
[[package]]
name = "editor_mode_setting"
version = "0.1.0"
dependencies = [
"anyhow",
"gpui",
"schemars",
"serde",
"serde_json",
"settings",
"workspace-hack",
]
[[package]]
name = "either"
version = "1.15.0"
@ -5616,6 +5629,7 @@ dependencies = [
"collections",
"db",
"editor",
"editor_mode_setting",
"extension",
"extension_host",
"fs",
@ -5636,7 +5650,6 @@ dependencies = [
"theme",
"ui",
"util",
"vim_mode_setting",
"workspace",
"workspace-hack",
"zed_actions",
@ -11105,6 +11118,7 @@ dependencies = [
"db",
"documented",
"editor",
"editor_mode_setting",
"fs",
"fuzzy",
"git",
@ -11123,7 +11137,6 @@ dependencies = [
"theme",
"ui",
"util",
"vim_mode_setting",
"workspace",
"workspace-hack",
"zed_actions",
@ -13966,6 +13979,7 @@ dependencies = [
"anyhow",
"collections",
"editor",
"editor_mode_setting",
"gpui",
"language",
"language_model",
@ -13981,7 +13995,6 @@ dependencies = [
"title_bar",
"ui",
"util",
"vim_mode_setting",
"workspace",
"workspace-hack",
"zed_actions",
@ -17957,6 +17970,7 @@ dependencies = [
"command_palette_hooks",
"db",
"editor",
"editor_mode_setting",
"env_logger 0.11.8",
"futures 0.3.31",
"git_ui",
@ -17986,25 +18000,11 @@ dependencies = [
"tokio",
"ui",
"util",
"vim_mode_setting",
"workspace",
"workspace-hack",
"zed_actions",
]
[[package]]
name = "vim_mode_setting"
version = "0.1.0"
dependencies = [
"anyhow",
"gpui",
"schemars",
"serde",
"serde_json",
"settings",
"workspace-hack",
]
[[package]]
name = "vscode_theme"
version = "0.2.0"
@ -20463,6 +20463,7 @@ dependencies = [
"diagnostics",
"edit_prediction_button",
"editor",
"editor_mode_setting",
"env_logger 0.11.8",
"extension",
"extension_host",
@ -20562,7 +20563,6 @@ dependencies = [
"util",
"uuid",
"vim",
"vim_mode_setting",
"watch",
"web_search",
"web_search_providers",

View file

@ -181,7 +181,7 @@ members = [
"crates/util_macros",
"crates/vercel",
"crates/vim",
"crates/vim_mode_setting",
"crates/editor_mode_setting",
"crates/watch",
"crates/web_search",
"crates/web_search_providers",
@ -406,7 +406,7 @@ util = { path = "crates/util" }
util_macros = { path = "crates/util_macros" }
vercel = { path = "crates/vercel" }
vim = { path = "crates/vim" }
vim_mode_setting = { path = "crates/vim_mode_setting" }
editor_mode_setting = { path = "crates/editor_mode_setting" }
watch = { path = "crates/watch" }
web_search = { path = "crates/web_search" }

View file

@ -22,7 +22,7 @@ serde.workspace = true
serde_json.workspace = true
settings.workspace = true
workspace-hack.workspace = true
vim_mode_setting.workspace = true
editor_mode_setting.workspace = true
[dev-dependencies]
fs.workspace = true

View file

@ -4,13 +4,13 @@ use std::sync::Arc;
use anyhow::{Result, bail};
use collections::IndexMap;
use editor_mode_setting::EditorMode;
use gpui::{App, Pixels, SharedString};
use language_model::LanguageModel;
use schemars::{JsonSchema, json_schema};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use settings::{Settings, SettingsSources};
use std::borrow::Cow;
use vim_mode_setting::EditorMode;
pub use crate::agent_profile::*;
@ -62,12 +62,10 @@ impl<'de> Deserialize<'de> for AgentEditorMode {
D: Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
dbg!(&s);
if s == "inherit" {
Ok(AgentEditorMode::Inherit)
} else {
let mode = EditorMode::deserialize(serde::de::value::StringDeserializer::new(s))?;
dbg!(&mode);
Ok(AgentEditorMode::EditorModeOverride(mode))
}
}
@ -91,7 +89,7 @@ impl JsonSchema for AgentEditorMode {
}
fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
use vim_mode_setting::EditorMode;
use editor_mode_setting::EditorMode;
let mut options = vec![serde_json::json!({
"const": "inherit",

View file

@ -100,7 +100,7 @@ watch.workspace = true
workspace-hack.workspace = true
workspace.workspace = true
zed_actions.workspace = true
vim_mode_setting.workspace = true
editor_mode_setting.workspace = true
[dev-dependencies]
acp_thread = { workspace = true, features = ["test-support"] }

View file

@ -115,10 +115,9 @@ impl MessageEditor {
let mention_set = MentionSet::default();
let settings = AgentSettings::get_global(cx);
dbg!(&settings);
let editor_mode = match settings.editor_mode {
AgentEditorMode::EditorModeOverride(mode) => mode,
AgentEditorMode::Inherit => vim_mode_setting::EditorModeSetting::get_global(cx).0,
AgentEditorMode::Inherit => editor_mode_setting::EditorModeSetting::get_global(cx).0,
};
let editor = cx.new(|cx| {
@ -129,8 +128,6 @@ impl MessageEditor {
editor.set_placeholder_text(placeholder, cx);
editor.set_show_indent_guides(false, cx);
editor.set_soft_wrap();
println!("editor mode in agent acp");
dbg!(&editor_mode);
editor.set_editor_mode(editor_mode, cx);
editor.set_completion_provider(Some(Rc::new(completion_provider)));
editor.set_context_menu_options(ContextMenuOptions {
@ -174,7 +171,9 @@ impl MessageEditor {
let settings = AgentSettings::get_global(cx);
let editor_mode = match settings.editor_mode {
AgentEditorMode::EditorModeOverride(mode) => mode,
AgentEditorMode::Inherit => vim_mode_setting::EditorModeSetting::get_global(cx).0,
AgentEditorMode::Inherit => {
editor_mode_setting::EditorModeSetting::get_global(cx).0
}
};
this.editor.update(cx, |editor, cx| {
editor.set_editor_mode(editor_mode, cx);

View file

@ -119,7 +119,7 @@ pub(crate) fn create_editor(
let editor_mode = match settings.editor_mode {
agent_settings::AgentEditorMode::EditorModeOverride(mode) => mode,
agent_settings::AgentEditorMode::Inherit => {
vim_mode_setting::EditorModeSetting::get_global(cx).0
editor_mode_setting::EditorModeSetting::get_global(cx).0
}
};
@ -136,8 +136,6 @@ pub(crate) fn create_editor(
editor.set_placeholder_text("Message the agent @ to include context", cx);
editor.set_show_indent_guides(false, cx);
editor.set_soft_wrap();
println!("editor mode in agent");
dbg!(&editor_mode);
editor.set_editor_mode(editor_mode, cx);
editor.set_context_menu_options(ContextMenuOptions {
min_entries_visible: 12,
@ -243,7 +241,7 @@ impl MessageEditor {
let editor_mode = match settings.editor_mode {
agent_settings::AgentEditorMode::EditorModeOverride(mode) => mode,
agent_settings::AgentEditorMode::Inherit => {
vim_mode_setting::EditorModeSetting::get_global(cx).0
editor_mode_setting::EditorModeSetting::get_global(cx).0
}
};
this.editor.update(cx, |editor, cx| {

View file

@ -76,7 +76,7 @@ util.workspace = true
workspace-hack.workspace = true
workspace.workspace = true
zed_actions.workspace = true
vim_mode_setting.workspace = true
editor_mode_setting.workspace = true
[dev-dependencies]
dap = { workspace = true, features = ["test-support"] }

View file

@ -7,6 +7,7 @@ use anyhow::Result;
use collections::HashMap;
use dap::{CompletionItem, CompletionItemType, OutputEvent};
use editor::{Bias, CompletionProvider, Editor, EditorElement, EditorStyle, ExcerptId};
use editor_mode_setting::EditorMode;
use fuzzy::StringMatchCandidate;
use gpui::{
Action as _, AppContext, Context, Corner, Entity, FocusHandle, Focusable, HighlightStyle, Hsla,
@ -26,7 +27,6 @@ use std::{cell::RefCell, ops::Range, rc::Rc, usize};
use theme::{Theme, ThemeSettings};
use ui::{ContextMenu, Divider, PopoverMenu, SplitButton, Tooltip, prelude::*};
use util::ResultExt;
use vim_mode_setting::EditorMode;
actions!(
console,

View file

@ -92,7 +92,7 @@ uuid.workspace = true
workspace.workspace = true
zed_actions.workspace = true
workspace-hack.workspace = true
vim_mode_setting.workspace = true
editor_mode_setting.workspace = true
[dev-dependencies]
ctor.workspace = true

View file

@ -94,6 +94,7 @@ use convert_case::{Case, Casing};
use dap::TelemetrySpawnLocation;
use display_map::*;
use edit_prediction::{EditPredictionProvider, EditPredictionProviderHandle};
use editor_mode_setting::{EditorMode, EditorModeSetting};
use editor_settings::{GoToDefinitionFallback, Minimap as MinimapSettings};
use element::{AcceptEditPredictionBinding, LineWithInvisibles, PositionMap, layout_line};
use futures::{
@ -201,7 +202,6 @@ use ui::{
IconSize, Indicator, Key, Tooltip, h_flex, prelude::*,
};
use util::{RangeExt, ResultExt, TryFutureExt, maybe, post_inc};
use vim_mode_setting::{EditorMode, EditorModeSetting};
use workspace::{
CollaboratorId, Item as WorkspaceItem, ItemId, ItemNavHistory, OpenInTerminal, OpenTerminal,
RestoreOnStartupBehavior, SERIALIZATION_THROTTLE_TIME, SplitDirection, TabBarSettings, Toast,
@ -1180,7 +1180,7 @@ pub struct Editor {
next_color_inlay_id: usize,
colors: Option<LspColorData>,
folding_newlines: Task<()>,
editor_mode: vim_mode_setting::EditorMode,
editor_mode: editor_mode_setting::EditorMode,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
@ -2265,7 +2265,7 @@ impl Editor {
editor_mode: if full_mode {
EditorModeSetting::get_global(cx).0
} else {
vim_mode_setting::EditorMode::default()
editor_mode_setting::EditorMode::default()
},
};
@ -3003,7 +3003,7 @@ impl Editor {
})
}
pub fn set_editor_mode(&mut self, to: vim_mode_setting::EditorMode, cx: &mut Context<Self>) {
pub fn set_editor_mode(&mut self, to: editor_mode_setting::EditorMode, cx: &mut Context<Self>) {
let from = self.editor_mode;
if from != to {
self.editor_mode = to;
@ -3014,7 +3014,7 @@ impl Editor {
}
}
pub fn editor_mode(&self) -> vim_mode_setting::EditorMode {
pub fn editor_mode(&self) -> editor_mode_setting::EditorMode {
self.editor_mode
}

View file

@ -1,5 +1,5 @@
[package]
name = "vim_mode_setting"
name = "editor_mode_setting"
version = "0.1.0"
edition.workspace = true
publish.workspace = true
@ -9,7 +9,7 @@ license = "GPL-3.0-or-later"
workspace = true
[lib]
path = "src/vim_mode_setting.rs"
path = "src/editor_mode_setting.rs"
[dependencies]
anyhow.workspace = true

View file

@ -14,7 +14,7 @@ use settings::{Settings, SettingsSources};
use std::borrow::Cow;
use std::fmt::Display;
/// Initializes the `vim_mode_setting` crate.
/// Initializes the `editor_mode_setting` crate.
pub fn init(cx: &mut App) {
EditorModeSetting::register(cx);
}

View file

@ -37,7 +37,7 @@ telemetry.workspace = true
theme.workspace = true
ui.workspace = true
util.workspace = true
vim_mode_setting.workspace = true
editor_mode_setting.workspace = true
workspace-hack.workspace = true
workspace.workspace = true
zed_actions.workspace = true

View file

@ -10,6 +10,7 @@ use anyhow::Context as _;
use client::{ExtensionMetadata, ExtensionProvides};
use collections::{BTreeMap, BTreeSet};
use editor::{Editor, EditorElement, EditorStyle};
use editor_mode_setting::{EditorMode, EditorModeSetting};
use extension_host::{ExtensionManifest, ExtensionOperation, ExtensionStore};
use fuzzy::{StringMatchCandidate, match_strings};
use gpui::{
@ -27,7 +28,6 @@ use ui::{
CheckboxWithLabel, Chip, ContextMenu, PopoverMenu, ScrollableHandle, Scrollbar, ScrollbarState,
ToggleButton, Tooltip, prelude::*,
};
use vim_mode_setting::{EditorMode, EditorModeSetting};
use workspace::{
Workspace, WorkspaceId,
item::{Item, ItemEvent},

View file

@ -40,7 +40,7 @@ telemetry.workspace = true
theme.workspace = true
ui.workspace = true
util.workspace = true
vim_mode_setting.workspace = true
editor_mode_setting.workspace = true
workspace-hack.workspace = true
workspace.workspace = true
zed_actions.workspace = true

View file

@ -1,6 +1,7 @@
use std::sync::Arc;
use client::TelemetrySettings;
use editor_mode_setting::{EditorMode, EditorModeSetting};
use fs::Fs;
use gpui::{App, IntoElement};
use settings::{BaseKeymap, Settings, update_settings_file};
@ -12,7 +13,6 @@ use ui::{
ParentElement as _, StatefulInteractiveElement, SwitchField, ToggleButtonGroup,
ToggleButtonSimple, ToggleButtonWithIcon, prelude::*, rems_from_px,
};
use vim_mode_setting::{EditorMode, EditorModeSetting};
use crate::theme_preview::{ThemePreviewStyle, ThemePreviewTile};

View file

@ -33,4 +33,4 @@ util.workspace = true
workspace-hack.workspace = true
workspace.workspace = true
zed_actions.workspace = true
vim_mode_setting.workspace = true
editor_mode_setting.workspace = true

View file

@ -2,6 +2,7 @@ use anyhow::Result;
use collections::{HashMap, HashSet};
use editor::{CompletionProvider, SelectionEffects};
use editor::{CurrentLineHighlight, Editor, EditorElement, EditorEvent, EditorStyle, actions::Tab};
use editor_mode_setting::EditorMode;
use gpui::{
Action, App, Bounds, Entity, EventEmitter, Focusable, PromptLevel, Subscription, Task,
TextStyle, TitlebarOptions, WindowBounds, WindowHandle, WindowOptions, actions, point, size,
@ -26,7 +27,6 @@ use ui::{
SharedString, Styled, Tooltip, Window, div, prelude::*,
};
use util::{ResultExt, TryFutureExt};
use vim_mode_setting::EditorMode;
use workspace::{Workspace, client_side_decorations};
use zed_actions::assistant::InlineAssist;

View file

@ -47,7 +47,7 @@ theme.workspace = true
tokio = { version = "1.15", features = ["full"], optional = true }
ui.workspace = true
util.workspace = true
vim_mode_setting.workspace = true
editor_mode_setting.workspace = true
workspace.workspace = true
zed_actions.workspace = true
workspace-hack.workspace = true

View file

@ -1,10 +1,10 @@
use crate::{Vim, state::Mode};
use editor::{Bias, Editor};
use editor_mode_setting::{EditorMode, EditorModeSetting};
use gpui::{Action, Context, Window, actions};
use language::SelectionGoal;
use settings::Settings;
use text::Point;
use vim_mode_setting::{EditorMode, EditorModeSetting};
use workspace::searchable::Direction;
actions!(

View file

@ -1,11 +1,11 @@
use editor::{DisplayPoint, RowExt, SelectionEffects, display_map::ToDisplayPoint, movement};
use editor_mode_setting::{EditorMode, EditorModeSetting};
use gpui::{Action, Context, Window};
use language::{Bias, SelectionGoal};
use schemars::JsonSchema;
use serde::Deserialize;
use settings::Settings;
use std::cmp;
use vim_mode_setting::{EditorMode, EditorModeSetting};
use crate::{
Vim,

View file

@ -11,6 +11,7 @@ use db::define_connection;
use db::sqlez_macros::sql;
use editor::display_map::{is_invisible, replacement};
use editor::{Anchor, ClipboardSelection, Editor, MultiBuffer, ToPoint as EditorToPoint};
pub use editor_mode_setting::ModalMode as Mode;
use gpui::{
Action, App, AppContext, BorrowAppContext, ClipboardEntry, ClipboardItem, DismissEvent, Entity,
EntityId, Global, HighlightStyle, StyledText, Subscription, Task, TextStyle, WeakEntity,
@ -31,7 +32,6 @@ use ui::{
StyledTypography, Window, h_flex, rems,
};
use util::ResultExt;
pub use vim_mode_setting::ModalMode as Mode;
use workspace::searchable::Direction;
use workspace::{Workspace, WorkspaceDb, WorkspaceId};

View file

@ -4,7 +4,7 @@ use editor::test::editor_lsp_test_context::EditorLspTestContext;
use gpui::{Context, Entity, SemanticVersion, UpdateGlobal};
use search::{BufferSearchBar, project_search::ProjectSearchBar};
use crate::{state::Operator, state::Mode, *};
use crate::{state::Mode, state::Operator, *};
pub struct VimTestContext {
cx: EditorLspTestContext,
@ -156,7 +156,7 @@ impl VimTestContext {
pub fn enable_helix(&mut self) {
self.cx.update(|_, cx| {
SettingsStore::update_global(cx, |store, cx| {
store.update_user_settings::<vim_mode_setting::EditorModeSetting>(cx, |s| {
store.update_user_settings::<editor_mode_setting::EditorModeSetting>(cx, |s| {
*s = Some(EditorMode::Helix(ModalMode::HelixNormal))
});
});

View file

@ -26,6 +26,7 @@ use editor::{
ToPoint,
movement::{self, FindRange},
};
use editor_mode_setting::{EditorMode, EditorModeSetting, ModalMode};
use gpui::{
Action, App, AppContext, Axis, Context, Entity, EventEmitter, KeyContext, KeystrokeEvent,
Render, Subscription, Task, WeakEntity, Window, actions,
@ -45,7 +46,6 @@ use std::{mem, ops::Range, sync::Arc};
use surrounds::SurroundsType;
use theme::ThemeSettings;
use ui::{IntoElement, SharedString, px};
use vim_mode_setting::{EditorMode, EditorModeSetting, ModalMode};
use workspace::{self, Pane, Workspace};
use crate::state::ReplayableAction;
@ -235,7 +235,7 @@ actions!(
/// Initializes the `vim` crate.
pub fn init(cx: &mut App) {
vim_mode_setting::init(cx);
editor_mode_setting::init(cx);
VimSettings::register(cx);
VimGlobals::register(cx);
@ -813,7 +813,6 @@ impl Vim {
}
pub fn global_enabled(cx: &mut App) -> bool {
dbg!(&EditorModeSetting::get_global(cx).0);
if EditorModeSetting::get_global(cx).0 == EditorMode::Default {
return false;
}

View file

@ -156,7 +156,7 @@ urlencoding.workspace = true
util.workspace = true
uuid.workspace = true
vim.workspace = true
vim_mode_setting.workspace = true
editor_mode_setting.workspace = true
watch.workspace = true
web_search.workspace = true
web_search_providers.workspace = true

View file

@ -19,6 +19,7 @@ use collections::VecDeque;
use debugger_ui::debugger_panel::DebugPanel;
use editor::ProposedChangesEditorToolbar;
use editor::{Editor, MultiBuffer};
use editor_mode_setting::EditorModeSetting;
use feature_flags::{FeatureFlagAppExt, PanicFeatureFlag};
use futures::future::Either;
use futures::{StreamExt, channel::mpsc, select_biased};
@ -70,7 +71,6 @@ use ui::{PopoverMenuHandle, prelude::*};
use util::markdown::MarkdownString;
use util::{ResultExt, asset_str};
use uuid::Uuid;
use vim_mode_setting::EditorModeSetting;
use workspace::notifications::{
NotificationId, SuppressEvent, dismiss_app_notification, show_app_notification,
};
@ -1282,7 +1282,7 @@ pub fn handle_keymap_file_changes(
cx: &mut App,
) {
BaseKeymap::register(cx);
vim_mode_setting::init(cx);
editor_mode_setting::init(cx);
let (base_keymap_tx, mut base_keymap_rx) = mpsc::unbounded();
let (keyboard_layout_tx, mut keyboard_layout_rx) = mpsc::unbounded();
@ -4616,7 +4616,7 @@ mod tests {
app_state.languages.add(markdown_language());
gpui_tokio::init(cx);
vim_mode_setting::init(cx);
editor_mode_setting::init(cx);
theme::init(theme::LoadThemes::JustBase, cx);
audio::init(cx);
channel::init(&app_state.client, app_state.user_store.clone(), cx);

View file

@ -10,6 +10,7 @@ use editor::actions::{
};
use editor::code_context_menus::{CodeContextMenu, ContextMenuOrigin};
use editor::{Editor, EditorSettings};
use editor_mode_setting::{EditorMode, EditorModeSetting};
use gpui::{
Action, AnchoredPositionMode, ClickEvent, Context, Corner, ElementId, Entity, EventEmitter,
FocusHandle, Focusable, InteractiveElement, ParentElement, Render, Styled, Subscription,
@ -23,7 +24,6 @@ use ui::{
ButtonStyle, ContextMenu, ContextMenuEntry, DocumentationSide, IconButton, IconName, IconSize,
PopoverMenu, PopoverMenuHandle, Tooltip, prelude::*,
};
use vim_mode_setting::{EditorMode, EditorModeSetting};
use workspace::{
ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace, item::ItemHandle,
};