fix diagnostic

Co-authored-by: Oleksiy Syvokon <oleksiy.syvokon@gmail.com>
This commit is contained in:
Smit Barmase 2025-08-22 15:48:08 +05:30
parent 1ecb2ff30b
commit 66fac38cf8
No known key found for this signature in database
18 changed files with 60 additions and 56 deletions

2
Cargo.lock generated
View file

@ -322,6 +322,7 @@ dependencies = [
"serde_json", "serde_json",
"serde_json_lenient", "serde_json_lenient",
"settings", "settings",
"vim_mode_setting",
"workspace-hack", "workspace-hack",
] ]
@ -13980,6 +13981,7 @@ dependencies = [
"title_bar", "title_bar",
"ui", "ui",
"util", "util",
"vim_mode_setting",
"workspace", "workspace",
"workspace-hack", "workspace-hack",
"zed_actions", "zed_actions",

View file

@ -21,6 +21,7 @@ schemars.workspace = true
serde.workspace = true serde.workspace = true
settings.workspace = true settings.workspace = true
workspace-hack.workspace = true workspace-hack.workspace = true
vim_mode_setting.workspace = true
[dev-dependencies] [dev-dependencies]
fs.workspace = true fs.workspace = true

View file

@ -10,6 +10,7 @@ use schemars::{JsonSchema, json_schema};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use settings::{Settings, SettingsSources}; use settings::{Settings, SettingsSources};
use std::borrow::Cow; use std::borrow::Cow;
use vim_mode_setting::EditorMode;
pub use crate::agent_profile::*; pub use crate::agent_profile::*;

View file

@ -113,6 +113,7 @@ impl MessageEditor {
}); });
let mention_set = MentionSet::default(); let mention_set = MentionSet::default();
let settings = agent_settings::AgentSettings::get_global(cx);
let editor_mode = match settings.editor_mode { let editor_mode = match settings.editor_mode {
agent_settings::AgentEditorMode::EditorModeOverride(mode) => mode, agent_settings::AgentEditorMode::EditorModeOverride(mode) => mode,
agent_settings::AgentEditorMode::Inherit => { agent_settings::AgentEditorMode::Inherit => {
@ -128,7 +129,7 @@ impl MessageEditor {
editor.set_placeholder_text(placeholder, cx); editor.set_placeholder_text(placeholder, cx);
editor.set_show_indent_guides(false, cx); editor.set_show_indent_guides(false, cx);
editor.set_soft_wrap(); editor.set_soft_wrap();
editor.set_use_modal_editing(editor_mode); editor.set_default_editor_mode(editor_mode);
editor.set_completion_provider(Some(Rc::new(completion_provider))); editor.set_completion_provider(Some(Rc::new(completion_provider)));
editor.set_context_menu_options(ContextMenuOptions { editor.set_context_menu_options(ContextMenuOptions {
min_entries_visible: 12, min_entries_visible: 12,

View file

@ -26,7 +26,7 @@ use std::{cell::RefCell, ops::Range, rc::Rc, usize};
use theme::{Theme, ThemeSettings}; use theme::{Theme, ThemeSettings};
use ui::{ContextMenu, Divider, PopoverMenu, SplitButton, Tooltip, prelude::*}; use ui::{ContextMenu, Divider, PopoverMenu, SplitButton, Tooltip, prelude::*};
use util::ResultExt; use util::ResultExt;
use vim_mode_settings::EditorMode; use vim_mode_setting::EditorMode;
actions!( actions!(
console, console,

View file

@ -1337,7 +1337,7 @@ impl ExtensionsPage {
Label::new("Enable vim mode"), Label::new("Enable vim mode"),
{ {
let editor_mode = EditorModeSetting::get_global(cx).0; let editor_mode = EditorModeSetting::get_global(cx).0;
if matches!(editor_mode, EditorMode::Vim | EditorMode::Helix) { if editor_mode.is_modal() {
ui::ToggleState::Selected ui::ToggleState::Selected
} else { } else {
ui::ToggleState::Unselected ui::ToggleState::Unselected
@ -1350,9 +1350,9 @@ impl ExtensionsPage {
cx, cx,
|setting, value| { |setting, value| {
*setting = Some(if value { *setting = Some(if value {
EditorMode::Vim EditorMode::vim()
} else { } else {
EditorMode::Default EditorMode::default()
}); });
}, },
); );

View file

@ -332,10 +332,7 @@ fn render_base_keymap_section(tab_index: &mut isize, cx: &mut App) -> impl IntoE
fn render_vim_mode_switch(tab_index: &mut isize, cx: &mut App) -> impl IntoElement { fn render_vim_mode_switch(tab_index: &mut isize, cx: &mut App) -> impl IntoElement {
let editor_mode = EditorModeSetting::get_global(cx).0; let editor_mode = EditorModeSetting::get_global(cx).0;
let toggle_state = if matches!( let toggle_state = if editor_mode.is_modal() {
editor_mode,
EditorMode::Vim | EditorMode::Helix | EditorMode::VimInsert
) {
ui::ToggleState::Selected ui::ToggleState::Selected
} else { } else {
ui::ToggleState::Unselected ui::ToggleState::Unselected
@ -351,7 +348,7 @@ fn render_vim_mode_switch(tab_index: &mut isize, cx: &mut App) -> impl IntoEleme
move |&selection, _, cx| { move |&selection, _, cx| {
update_settings_file::<EditorModeSetting>(fs.clone(), cx, move |setting, _| { update_settings_file::<EditorModeSetting>(fs.clone(), cx, move |setting, _| {
*setting = match selection { *setting = match selection {
ToggleState::Selected => Some(EditorMode::Vim), ToggleState::Selected => Some(EditorMode::vim()),
ToggleState::Unselected => Some(EditorMode::Default), ToggleState::Unselected => Some(EditorMode::Default),
ToggleState::Indeterminate => None, ToggleState::Indeterminate => None,
} }

View file

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

View file

@ -26,6 +26,7 @@ use ui::{
SharedString, Styled, Tooltip, Window, div, prelude::*, SharedString, Styled, Tooltip, Window, div, prelude::*,
}; };
use util::{ResultExt, TryFutureExt}; use util::{ResultExt, TryFutureExt};
use vim_mode_setting::EditorMode;
use workspace::{Workspace, client_side_decorations}; use workspace::{Workspace, client_side_decorations};
use zed_actions::assistant::InlineAssist; use zed_actions::assistant::InlineAssist;

View file

@ -53,7 +53,7 @@ impl Vim {
self.update_editor(cx, |_, editor, cx| { self.update_editor(cx, |_, editor, cx| {
editor.dismiss_menus_and_popups(false, window, cx); editor.dismiss_menus_and_popups(false, window, cx);
if EditorModeSetting::get_global(cx).0 != EditorMode::Helix { if !matches!(EditorModeSetting::get_global(cx).0, EditorMode::Helix(..)) {
editor.change_selections(Default::default(), window, cx, |s| { editor.change_selections(Default::default(), window, cx, |s| {
s.move_cursors_with(|map, mut cursor, _| { s.move_cursors_with(|map, mut cursor, _| {
*cursor.column_mut() = cursor.column().saturating_sub(1); *cursor.column_mut() = cursor.column().saturating_sub(1);
@ -63,7 +63,7 @@ impl Vim {
} }
}); });
if EditorModeSetting::get_global(cx).0 == EditorMode::Helix { if matches!(EditorModeSetting::get_global(cx).0, EditorMode::Helix(..)) {
self.switch_mode(Mode::HelixNormal, false, window, cx); self.switch_mode(Mode::HelixNormal, false, window, cx);
} else { } else {
self.switch_mode(Mode::Normal, false, window, cx); self.switch_mode(Mode::Normal, false, window, cx);

View file

@ -220,7 +220,7 @@ impl Vim {
}); });
}); });
if EditorModeSetting::get_global(cx).0 == EditorMode::Helix { if matches!(EditorModeSetting::get_global(cx).0, EditorMode::Helix(_)) {
self.switch_mode(Mode::HelixNormal, true, window, cx); self.switch_mode(Mode::HelixNormal, true, window, cx);
} else { } else {
self.switch_mode(Mode::Normal, true, window, cx); self.switch_mode(Mode::Normal, true, window, cx);

View file

@ -3,8 +3,9 @@ use gpui::{Context, Window, actions};
use language::Point; use language::Point;
use crate::{ use crate::{
Mode, Vim, Vim,
motion::{Motion, MotionKind}, motion::{Motion, MotionKind},
state::Mode,
}; };
actions!( actions!(

View file

@ -19,12 +19,11 @@ use language::{Buffer, BufferEvent, BufferId, Chunk, Point};
use multi_buffer::MultiBufferRow; use multi_buffer::MultiBufferRow;
use picker::{Picker, PickerDelegate}; use picker::{Picker, PickerDelegate};
use project::{Project, ProjectItem, ProjectPath}; use project::{Project, ProjectItem, ProjectPath};
use serde::{Deserialize, Serialize};
use settings::{Settings, SettingsStore}; use settings::{Settings, SettingsStore};
use std::borrow::BorrowMut; use std::borrow::BorrowMut;
use std::collections::HashSet; use std::collections::HashSet;
use std::path::Path; use std::path::Path;
use std::{fmt::Display, ops::Range, sync::Arc}; use std::{ops::Range, sync::Arc};
use text::{Bias, ToPoint}; use text::{Bias, ToPoint};
use theme::ThemeSettings; use theme::ThemeSettings;
use ui::{ use ui::{
@ -32,7 +31,7 @@ use ui::{
StyledTypography, Window, h_flex, rems, StyledTypography, Window, h_flex, rems,
}; };
use util::ResultExt; use util::ResultExt;
use vim_mode_setting::ModalMode; pub use vim_mode_setting::ModalMode as Mode;
use workspace::searchable::Direction; use workspace::searchable::Direction;
use workspace::{Workspace, WorkspaceDb, WorkspaceId}; use workspace::{Workspace, WorkspaceDb, WorkspaceId};
@ -937,7 +936,7 @@ pub struct SearchState {
pub prior_selections: Vec<Range<Anchor>>, pub prior_selections: Vec<Range<Anchor>>,
pub prior_operator: Option<Operator>, pub prior_operator: Option<Operator>,
pub prior_mode: ModalMode, pub prior_mode: Mode,
} }
impl Operator { impl Operator {
@ -1004,7 +1003,7 @@ impl Operator {
} }
} }
pub fn is_waiting(&self, mode: ModalMode) -> bool { pub fn is_waiting(&self, mode: Mode) -> bool {
match self { match self {
Operator::AddSurrounds { target } => target.is_some() || mode.is_visual(), Operator::AddSurrounds { target } => target.is_some() || mode.is_visual(),
Operator::FindForward { .. } Operator::FindForward { .. }

View file

@ -4,7 +4,7 @@ use editor::test::editor_lsp_test_context::EditorLspTestContext;
use gpui::{Context, Entity, SemanticVersion, UpdateGlobal}; use gpui::{Context, Entity, SemanticVersion, UpdateGlobal};
use search::{BufferSearchBar, project_search::ProjectSearchBar}; use search::{BufferSearchBar, project_search::ProjectSearchBar};
use crate::{state::Operator, *}; use crate::{state::Operator, state::Mode, *};
pub struct VimTestContext { pub struct VimTestContext {
cx: EditorLspTestContext, cx: EditorLspTestContext,
@ -66,7 +66,7 @@ impl VimTestContext {
SettingsStore::update_global(cx, |store, cx| { SettingsStore::update_global(cx, |store, cx| {
store.update_user_settings::<EditorModeSetting>(cx, |s| { store.update_user_settings::<EditorModeSetting>(cx, |s| {
*s = Some(if enabled { *s = Some(if enabled {
EditorMode::Vim EditorMode::vim()
} else { } else {
EditorMode::Default EditorMode::Default
}) })
@ -136,7 +136,9 @@ impl VimTestContext {
pub fn enable_vim(&mut self) { pub fn enable_vim(&mut self) {
self.cx.update(|_, cx| { self.cx.update(|_, cx| {
SettingsStore::update_global(cx, |store, cx| { SettingsStore::update_global(cx, |store, cx| {
store.update_user_settings::<EditorModeSetting>(cx, |s| *s = Some(EditorMode::Vim)); store.update_user_settings::<EditorModeSetting>(cx, |s| {
*s = Some(EditorMode::vim())
});
}); });
}) })
} }
@ -144,7 +146,9 @@ impl VimTestContext {
pub fn disable_vim(&mut self) { pub fn disable_vim(&mut self) {
self.cx.update(|_, cx| { self.cx.update(|_, cx| {
SettingsStore::update_global(cx, |store, cx| { SettingsStore::update_global(cx, |store, cx| {
store.update_user_settings::<EditorModeSetting>(cx, |s| *s = Some(EditorMode::Vim)); store.update_user_settings::<EditorModeSetting>(cx, |s| {
*s = Some(EditorMode::vim())
});
}); });
}) })
} }
@ -153,7 +157,7 @@ impl VimTestContext {
self.cx.update(|_, cx| { self.cx.update(|_, cx| {
SettingsStore::update_global(cx, |store, cx| { SettingsStore::update_global(cx, |store, cx| {
store.update_user_settings::<vim_mode_setting::EditorModeSetting>(cx, |s| { store.update_user_settings::<vim_mode_setting::EditorModeSetting>(cx, |s| {
*s = Some(EditorMode::Helix) *s = Some(EditorMode::Helix(ModalMode::HelixNormal))
}); });
}); });
}) })

View file

@ -45,7 +45,7 @@ use std::{mem, ops::Range, sync::Arc};
use surrounds::SurroundsType; use surrounds::SurroundsType;
use theme::ThemeSettings; use theme::ThemeSettings;
use ui::{IntoElement, SharedString, px}; use ui::{IntoElement, SharedString, px};
use vim_mode_setting::{EditorMode, EditorModeSetting}; use vim_mode_setting::{EditorMode, EditorModeSetting, ModalMode};
use workspace::{self, Pane, Workspace}; use workspace::{self, Pane, Workspace};
use crate::state::ReplayableAction; use crate::state::ReplayableAction;
@ -249,7 +249,7 @@ pub fn init(cx: &mut App) {
*setting = Some(if currently_enabled { *setting = Some(if currently_enabled {
EditorMode::Default EditorMode::Default
} else { } else {
EditorMode::Vim EditorMode::vim()
}); });
}) })
}); });
@ -448,7 +448,7 @@ impl Vim {
} }
let mut was_toggle = VimSettings::get_global(cx).toggle_relative_line_numbers; let mut was_toggle = VimSettings::get_global(cx).toggle_relative_line_numbers;
cx.observe_global_in::<SettingsStore>(window, move |editor, window, cx| { cx.observe_global_in::<SettingsStore>(window, move |editor, _window, cx| {
let toggle = VimSettings::get_global(cx).toggle_relative_line_numbers; let toggle = VimSettings::get_global(cx).toggle_relative_line_numbers;
if toggle != was_toggle { if toggle != was_toggle {
if toggle { if toggle {
@ -464,10 +464,6 @@ impl Vim {
}) })
.detach(); .detach();
let mut was_enabled = true;
cx.observe::<Editor>(window, move |editor, window, cx| {})
.detach();
Self::activate(editor, window, cx) Self::activate(editor, window, cx)
} }
@ -487,12 +483,13 @@ impl Vim {
entity: vim.clone(), entity: vim.clone(),
}); });
let default_editor_mode = editor.default_editor_mode();
vim.update(cx, move |_, cx| { vim.update(cx, move |_, cx| {
Vim::action( Vim::action(
editor, editor,
cx, cx,
move |vim, _: &SwitchToNormalMode, window, cx| { move |vim, _: &SwitchToNormalMode, window, cx| {
if matches!(default_editor_mode, EditorMode::Helix) { if matches!(default_editor_mode, EditorMode::Helix(_)) {
vim.switch_mode(ModalMode::HelixNormal, false, window, cx) vim.switch_mode(ModalMode::HelixNormal, false, window, cx)
} else { } else {
vim.switch_mode(ModalMode::Normal, false, window, cx) vim.switch_mode(ModalMode::Normal, false, window, cx)
@ -918,20 +915,21 @@ impl Vim {
}); });
} }
EditorEvent::EditorModeChanged => { EditorEvent::EditorModeChanged => {
self.update_editor(cx, |vim, editor, cx| { self.update_editor(cx, |_vim, _editor, _cx| {
let enabled = editor.default_editor_mode().is_modal(); // TODO
if was_enabled == enabled { // let enabled = editor.default_editor_mode().is_modal();
return; // if was_enabled == enabled {
} // return;
if !enabled { // }
editor.set_relative_line_number(None, cx); // if !enabled {
} // editor.set_relative_line_number(None, cx);
was_enabled = enabled; // }
if enabled { // was_enabled = enabled;
Self::activate(editor, window, cx) // if enabled {
} else { // Self::activate(editor, window, cx)
Self::deactivate(editor, cx) // } else {
} // Self::deactivate(editor, cx)
// }
// //
}); });
} }

View file

@ -64,7 +64,7 @@ impl Serialize for EditorMode {
EditorMode::Vim(ModalMode::Visual) => "vim_visual", EditorMode::Vim(ModalMode::Visual) => "vim_visual",
EditorMode::Vim(ModalMode::VisualLine) => "vim_visual_line", EditorMode::Vim(ModalMode::VisualLine) => "vim_visual_line",
EditorMode::Vim(ModalMode::VisualBlock) => "vim_visual_block", EditorMode::Vim(ModalMode::VisualBlock) => "vim_visual_block",
EditorMode::Helix(ModalMode::Normal) => "helix_experimental", EditorMode::Helix(ModalMode::HelixNormal) => "helix_experimental",
_ => return Err(serde::ser::Error::custom("unsupported editor mode variant")), _ => return Err(serde::ser::Error::custom("unsupported editor mode variant")),
}; };
serializer.serialize_str(s) serializer.serialize_str(s)
@ -136,4 +136,8 @@ impl EditorMode {
pub fn is_modal(&self) -> bool { pub fn is_modal(&self) -> bool {
matches!(self, EditorMode::Vim(_) | EditorMode::Helix(_)) matches!(self, EditorMode::Vim(_) | EditorMode::Helix(_))
} }
pub fn vim() -> EditorMode {
EditorMode::Vim(ModalMode::default())
}
} }

View file

@ -1492,11 +1492,8 @@ pub fn load_default_keymap(cx: &mut App) {
if let Some(asset_path) = base_keymap.asset_path() { if let Some(asset_path) = base_keymap.asset_path() {
cx.bind_keys(KeymapFile::load_asset(asset_path, Some(KeybindSource::Base), cx).unwrap()); cx.bind_keys(KeymapFile::load_asset(asset_path, Some(KeybindSource::Base), cx).unwrap());
} }
let editor_mode = EditorModeSetting::get_global(cx).0;
if matches!( if editor_mode.is_modal() {
EditorModeSetting::get_global(cx).0,
EditorMode::Vim | EditorMode::Helix | EditorMode::VimInsert
) {
cx.bind_keys( cx.bind_keys(
KeymapFile::load_asset(VIM_KEYMAP_PATH, Some(KeybindSource::Vim), cx).unwrap(), KeymapFile::load_asset(VIM_KEYMAP_PATH, Some(KeybindSource::Vim), cx).unwrap(),
); );

View file

@ -302,10 +302,7 @@ impl Render for QuickActionBar {
let editor = editor.downgrade(); let editor = editor.downgrade();
let editor_settings_dropdown = { let editor_settings_dropdown = {
let editor_mode = EditorModeSetting::get_global(cx).0; let editor_mode = EditorModeSetting::get_global(cx).0;
let vim_mode_enabled = matches!( let vim_mode_enabled = editor_mode.is_modal();
editor_mode,
EditorMode::Vim | EditorMode::Helix | EditorMode::VimInsert
);
PopoverMenu::new("editor-settings") PopoverMenu::new("editor-settings")
.trigger_with_tooltip( .trigger_with_tooltip(