diff --git a/crates/agent_settings/src/agent_settings.rs b/crates/agent_settings/src/agent_settings.rs index c7772a6a1b..9a02a77939 100644 --- a/crates/agent_settings/src/agent_settings.rs +++ b/crates/agent_settings/src/agent_settings.rs @@ -49,7 +49,7 @@ pub enum NotifyWhenAgentWaiting { Never, } -#[derive(Copy, Clone, Debug, PartialEq, Eq, JsonSchema, Default)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)] pub enum AgentEditorMode { EditorModeOverride(EditorMode), #[default] @@ -62,10 +62,12 @@ 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)) } } @@ -83,6 +85,31 @@ impl Serialize for AgentEditorMode { } } +impl JsonSchema for AgentEditorMode { + fn schema_name() -> Cow<'static, str> { + "AgentEditorMode".into() + } + + fn json_schema(schema_gen: &mut schemars::SchemaGenerator) -> schemars::Schema { + let editor_mode_schema = EditorMode::json_schema(schema_gen); + + // TODO: This schema is incorrect. Need to extend editor_mode_schema with `inherit` + let result = json_schema!({ + "oneOf": [ + { + "const": "inherit", + "description": "Inherit editor mode from global settings" + }, + editor_mode_schema + ], + "description": "Agent editor mode - either inherit from global settings or override with a specific mode" + }); + + dbg!(&result); + result + } +} + impl From for AgentEditorMode { fn from(b: EditorMode) -> Self { AgentEditorMode::EditorModeOverride(b) diff --git a/crates/agent_ui/src/acp/message_editor.rs b/crates/agent_ui/src/acp/message_editor.rs index 123315170b..659b6e3cf1 100644 --- a/crates/agent_ui/src/acp/message_editor.rs +++ b/crates/agent_ui/src/acp/message_editor.rs @@ -115,6 +115,7 @@ 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, @@ -128,6 +129,8 @@ 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 { diff --git a/crates/agent_ui/src/message_editor.rs b/crates/agent_ui/src/message_editor.rs index f066b75dee..3a94d31a73 100644 --- a/crates/agent_ui/src/message_editor.rs +++ b/crates/agent_ui/src/message_editor.rs @@ -136,6 +136,8 @@ 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, diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 3fd8037984..a9e6ef6dec 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -201,7 +201,7 @@ use ui::{ IconSize, Indicator, Key, Tooltip, h_flex, prelude::*, }; use util::{RangeExt, ResultExt, TryFutureExt, maybe, post_inc}; -use vim_mode_setting::EditorMode; +use vim_mode_setting::{EditorMode, EditorModeSetting}; use workspace::{ CollaboratorId, Item as WorkspaceItem, ItemId, ItemNavHistory, OpenInTerminal, OpenTerminal, RestoreOnStartupBehavior, SERIALIZATION_THROTTLE_TIME, SplitDirection, TabBarSettings, Toast, @@ -1181,38 +1181,6 @@ pub struct Editor { colors: Option, folding_newlines: Task<()>, editor_mode: vim_mode_setting::EditorMode, - // editor_mode: EditorMode, <-- while init define which editor, - - // agenty subscribe to agen settings - // - // editor <- agent - // - // settings listent to event emitted by editor, - // - - // agent will set_editor_mode(AgentPanelSettings::read("editor_mode")) on init - // vim.rs will get_editor_mode() on init / activate / register - // - // match editor_mode { - // // which setting to use - // } - // - // - - // editor_mode: EditorMode, <-- while init define which editor, - // pros -> jsut set enum - // cons -> actual setting check lives in either editor.rs or vim.rs?? - // - // set_edutr(); - // - // Fn () -> weather mode this editor is, and what;s the default value? - // pros -> all setting lives in agent, git. - // cons -> if someone wants to use agent setting in their editor, they need to copy paste code - // - // // agent.rs - // set_vim_setting_fn(|| { - // // edito seting agnet - // }); } #[derive(Copy, Clone, Debug, PartialEq, Eq, Default)] @@ -2294,7 +2262,11 @@ impl Editor { display_mode: mode, selection_drag_state: SelectionDragState::None, folding_newlines: Task::ready(()), - editor_mode: vim_mode_setting::EditorMode::default(), + editor_mode: if full_mode { + EditorModeSetting::get_global(cx).0 + } else { + vim_mode_setting::EditorMode::default() + }, }; if is_minimap { diff --git a/crates/vim/src/state.rs b/crates/vim/src/state.rs index c0d48ab142..290f0af9ee 100644 --- a/crates/vim/src/state.rs +++ b/crates/vim/src/state.rs @@ -652,7 +652,7 @@ impl VimGlobals { let mut was_enabled = None; cx.observe_global::(move |cx| { - let is_enabled = Vim::enabled(cx); + let is_enabled = Vim::global_enabled(cx); if was_enabled == Some(is_enabled) { return; } diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index cbbb5ce56e..f3d4b746f3 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -244,7 +244,7 @@ pub fn init(cx: &mut App) { cx.observe_new(|workspace: &mut Workspace, _, _| { workspace.register_action(|workspace, _: &ToggleVimMode, _, cx| { let fs = workspace.app_state().fs.clone(); - let currently_enabled = Vim::enabled(cx); + let currently_enabled = Vim::global_enabled(cx); update_settings_file::(fs, cx, move |setting, _| { *setting = Some(if currently_enabled { EditorMode::Default @@ -812,13 +812,11 @@ impl Vim { .map(|workspace| workspace.read(cx).focused_pane(window, cx)) } - pub fn enabled(cx: &mut App) -> bool { + pub fn global_enabled(cx: &mut App) -> bool { + dbg!(&EditorModeSetting::get_global(cx).0); if EditorModeSetting::get_global(cx).0 == EditorMode::Default { return false; } - - // check for agent.editor_mode - // return true; } diff --git a/crates/vim_mode_setting/src/vim_mode_setting.rs b/crates/vim_mode_setting/src/vim_mode_setting.rs index a7f7ecf127..46f67cb870 100644 --- a/crates/vim_mode_setting/src/vim_mode_setting.rs +++ b/crates/vim_mode_setting/src/vim_mode_setting.rs @@ -6,10 +6,12 @@ use anyhow::Result; use gpui::App; -use schemars::JsonSchema; +use schemars::{JsonSchema, Schema, json_schema}; + use serde::de::Error; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use settings::{Settings, SettingsSources}; +use std::borrow::Cow; use std::fmt::Display; /// Initializes the `vim_mode_setting` crate. @@ -22,7 +24,7 @@ pub fn init(cx: &mut App) { /// Default: `EditMode::Default` pub struct EditorModeSetting(pub EditorMode); -#[derive(Copy, Clone, Debug, PartialEq, Eq, JsonSchema, Default)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)] pub enum EditorMode { #[default] Default, @@ -30,6 +32,56 @@ pub enum EditorMode { Helix(ModalMode), } +impl JsonSchema for EditorMode { + fn schema_name() -> Cow<'static, str> { + "EditorMode".into() + } + + fn json_schema(_gen: &mut schemars::SchemaGenerator) -> Schema { + json_schema!({ + "oneOf": [ + { + "const": "default", + "description": "Standard editing mode" + }, + { + "const": "vim", + "description": "Vim normal mode" + }, + { + "const": "vim_normal", + "description": "Vim normal mode" + }, + { + "const": "vim_insert", + "description": "Vim insert mode" + }, + { + "const": "vim_replace", + "description": "Vim replace mode" + }, + { + "const": "vim_visual", + "description": "Vim visual mode" + }, + { + "const": "vim_visual_line", + "description": "Vim visual line mode" + }, + { + "const": "vim_visual_block", + "description": "Vim visual block mode" + }, + { + "const": "helix_experimental", + "description": "Helix mode (experimental)" + } + ], + "description": "Editor mode" + }) + } +} + impl<'de> Deserialize<'de> for EditorMode { fn deserialize(deserializer: D) -> Result where