debug stuff

Smit Barmase and Oleksiy Syvokon created

Co-authored-by: Oleksiy Syvokon <oleksiy.syvokon@gmail.com>

Change summary

crates/agent_settings/src/agent_settings.rs     | 29 +++++++++
crates/agent_ui/src/acp/message_editor.rs       |  3 +
crates/agent_ui/src/message_editor.rs           |  2 
crates/editor/src/editor.rs                     | 40 ++-----------
crates/vim/src/state.rs                         |  2 
crates/vim/src/vim.rs                           |  8 +-
crates/vim_mode_setting/src/vim_mode_setting.rs | 56 ++++++++++++++++++
7 files changed, 97 insertions(+), 43 deletions(-)

Detailed changes

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<EditorMode> for AgentEditorMode {
     fn from(b: EditorMode) -> Self {
         AgentEditorMode::EditorModeOverride(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 {

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,

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<LspColorData>,
     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 {

crates/vim/src/state.rs 🔗

@@ -652,7 +652,7 @@ impl VimGlobals {
         let mut was_enabled = None;
 
         cx.observe_global::<SettingsStore>(move |cx| {
-            let is_enabled = Vim::enabled(cx);
+            let is_enabled = Vim::global_enabled(cx);
             if was_enabled == Some(is_enabled) {
                 return;
             }

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::<EditorModeSetting>(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;
     }
 

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<D>(deserializer: D) -> Result<Self, D::Error>
     where