History

vim: Fix renaming (#7714)

This was broken by #7647 Release Notes: - N/A

Conrad Irwin committed 2 years ago

Commit a1899ba1 parent 04fc0dd6 files · +68 −24Browse files

Unified · Split

6 files
  1. crates/editor/src/editor.rs +10 −1
  2. crates/feedback/src/feedback_modal.rs +1 −0
  3. crates/vim/src/editor_events.rs +1 −0
  4. crates/vim/src/test.rs +37 −0
  5. crates/vim/src/test/vim_test_context.rs +13 −20
  6. crates/vim/src/vim.rs +6 −3
crates/editor/src/editor.rs+10−1
@@ -399,6 +399,7 @@ pub struct Editor { · 398 unmodified lines
399399 workspace: Option<(WeakView<Workspace>, i64)>,
400400 keymap_context_layers: BTreeMap<TypeId, KeyContext>,
401401 input_enabled: bool,
402+ use_modal_editing: bool,
402403 read_only: bool,
403404 leader_peer_id: Option<PeerId>,
404405 remote_id: Option<ViewId>,
@@ -1482,6 +1483,7 @@ impl Editor { · 1077 unmodified lines
14821483 workspace: None,
14831484 keymap_context_layers: Default::default(),
14841485 input_enabled: true,
1486+ use_modal_editing: mode == EditorMode::Full,
14851487 read_only: false,
14861488 use_autoclose: true,
14871489 leader_peer_id: None,
@@ -1782,6 +1784,14 @@ impl Editor { · 294 unmodified lines
17821784 self.show_copilot_suggestions = show_copilot_suggestions;
17831785 }
17841786
1787+ pub fn set_use_modal_editing(&mut self, to: bool) {
1788+ self.use_modal_editing = to;
1789+ }
1790+
1791+ pub fn use_modal_editing(&self) -> bool {
1792+ self.use_modal_editing
1793+ }
1794+
17851795 fn selections_did_change(
17861796 &mut self,
17871797 local: bool,
@@ -7836,7 +7846,6 @@ impl Editor { · 6048 unmodified lines
78367846 Some(rename)
78377847 }
78387848
7839− #[cfg(any(test, feature = "test-support"))]
78407849 pub fn pending_rename(&self) -> Option<&RenameState> {
78417850 self.pending_rename.as_ref()
78427851 }
crates/feedback/src/feedback_modal.rs+1−0
@@ -187,6 +187,7 @@ impl FeedbackModal { · 186 unmodified lines
187187 editor.set_show_gutter(false, cx);
188188 editor.set_show_copilot_suggestions(false);
189189 editor.set_vertical_scroll_margin(5, cx);
190+ editor.set_use_modal_editing(false);
190191 editor
191192 });
192193
crates/vim/src/editor_events.rs+1−0
@@ -47,6 +47,7 @@ fn blurred(editor: View<Editor>, cx: &mut WindowContext) { · 46 unmodified lines
4747 .upgrade()
4848 .is_some_and(|previous| previous == editor.clone())
4949 {
50+ vim.sync_vim_settings(cx);
5051 vim.clear_operator(cx);
5152 }
5253 }
crates/vim/src/test.rs+37−0
@@ -7,6 +7,7 @@ use std::time::Duration; · 6 unmodified lines
77
88 use command_palette::CommandPalette;
99 use editor::DisplayPoint;
10+use futures::StreamExt;
1011 use gpui::KeyBinding;
1112 pub use neovim_backed_binding_test_context::*;
1213 pub use neovim_backed_test_context::*;
@@ -847,3 +848,39 @@ async fn test_comma_w(cx: &mut gpui::TestAppContext) { · 834 unmodified lines
847848 cx.assert_shared_state("hellˇo hello\nhello hello").await;
848849 cx.assert_shared_mode(Mode::Insert).await;
849850 }
851+
852+#[gpui::test]
853+async fn test_rename(cx: &mut gpui::TestAppContext) {
854+ let mut cx = VimTestContext::new_typescript(cx).await;
855+
856+ cx.set_state("const beˇfore = 2; console.log(before)", Mode::Normal);
857+ let def_range = cx.lsp_range("const «beforeˇ» = 2; console.log(before)");
858+ let tgt_range = cx.lsp_range("const before = 2; console.log(«beforeˇ»)");
859+ let mut prepare_request =
860+ cx.handle_request::<lsp::request::PrepareRenameRequest, _, _>(move |_, _, _| async move {
861+ Ok(Some(lsp::PrepareRenameResponse::Range(def_range)))
862+ });
863+ let mut rename_request =
864+ cx.handle_request::<lsp::request::Rename, _, _>(move |url, params, _| async move {
865+ Ok(Some(lsp::WorkspaceEdit {
866+ changes: Some(
867+ [(
868+ url.clone(),
869+ vec![
870+ lsp::TextEdit::new(def_range, params.new_name.clone()),
871+ lsp::TextEdit::new(tgt_range, params.new_name),
872+ ],
873+ )]
874+ .into(),
875+ ),
876+ ..Default::default()
877+ }))
878+ });
879+
880+ cx.simulate_keystrokes(["c", "d"]);
881+ prepare_request.next().await.unwrap();
882+ cx.simulate_input("after");
883+ cx.simulate_keystrokes(["enter"]);
884+ rename_request.next().await.unwrap();
885+ cx.assert_state("const afterˇ = 2; console.log(after)", Mode::Normal)
886+}
crates/vim/src/test/vim_test_context.rs+13−20
@@ -1,11 +1,7 @@
11 use std::ops::{Deref, DerefMut};
22
3−use editor::test::{
4− editor_lsp_test_context::EditorLspTestContext, editor_test_context::EditorTestContext,
5−};
6−use futures::Future;
3+use editor::test::editor_lsp_test_context::EditorLspTestContext;
74 use gpui::{Context, View, VisualContext};
8−use lsp::request;
95 use search::{project_search::ProjectSearchBar, BufferSearchBar};
106
117 use crate::{state::Operator, *};
@@ -38,7 +34,17 @@ impl VimTestContext { · 26 unmodified lines
3834 pub async fn new_typescript(cx: &mut gpui::TestAppContext) -> VimTestContext {
3935 Self::init(cx);
4036 Self::new_with_lsp(
41− EditorLspTestContext::new_typescript(Default::default(), cx).await,
37+ EditorLspTestContext::new_typescript(
38+ lsp::ServerCapabilities {
39+ rename_provider: Some(lsp::OneOf::Right(lsp::RenameOptions {
40+ prepare_provider: Some(true),
41+ work_done_progress_options: Default::default(),
42+ })),
43+ ..Default::default()
44+ },
45+ cx,
46+ )
47+ .await,
4248 true,
4349 )
4450 }
@@ -149,23 +155,10 @@ impl VimTestContext { · 104 unmodified lines
149155 assert_eq!(self.mode(), mode_after, "{}", self.assertion_context());
150156 assert_eq!(self.active_operator(), None, "{}", self.assertion_context());
151157 }
152−
153− pub fn handle_request<T, F, Fut>(
154− &self,
155− handler: F,
156− ) -> futures::channel::mpsc::UnboundedReceiver<()>
157− where
158− T: 'static + request::Request,
159− T::Params: 'static + Send,
160− F: 'static + Send + FnMut(lsp::Url, T::Params, gpui::AsyncAppContext) -> Fut,
161− Fut: 'static + Send + Future<Output = Result<T::Result>>,
162− {
163− self.cx.handle_request::<T, F, Fut>(handler)
164− }
165158 }
166159
167160 impl Deref for VimTestContext {
168− type Target = EditorTestContext;
161+ type Target = EditorLspTestContext;
169162
170163 fn deref(&self) -> &Self::Target {
171164 &self.cx
crates/vim/src/vim.rs+6−3
@@ -198,7 +198,7 @@ impl Vim { · 197 unmodified lines
198198 }
199199
200200 fn activate_editor(&mut self, editor: View<Editor>, cx: &mut WindowContext) {
201− if editor.read(cx).mode() != EditorMode::Full {
201+ if !editor.read(cx).use_modal_editing() {
202202 return;
203203 }
204204
@@ -575,8 +575,11 @@ impl Vim { · 370 unmodified lines
575575 editor.set_input_enabled(!state.vim_controlled());
576576 editor.set_autoindent(state.should_autoindent());
577577 editor.selections.line_mode = matches!(state.mode, Mode::VisualLine);
578− let context_layer = state.keymap_context_layer();
579− editor.set_keymap_context_layer::<Self>(context_layer, cx);
578+ if editor.is_focused(cx) {
579+ editor.set_keymap_context_layer::<Self>(state.keymap_context_layer(), cx);
580+ } else {
581+ editor.remove_keymap_context_layer::<Self>(cx);
582+ }
580583 });
581584 }
582585

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t