Remove 2 suffix for vim, diagnostics, go_to_line, theme_selector, command_palette, file_finder

Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
Max Brunsfeld 2024-01-03 10:42:49 -08:00
parent 37e6533b28
commit 252694390a
185 changed files with 1933 additions and 29192 deletions

View file

@ -1,4 +1,5 @@
use editor::scroll::VERTICAL_SCROLL_MARGIN;
use editor::{scroll::VERTICAL_SCROLL_MARGIN, test::editor_test_context::ContextHandle};
use gpui::{px, size, Context};
use indoc::indoc;
use settings::SettingsStore;
use std::{
@ -7,7 +8,6 @@ use std::{
};
use collections::{HashMap, HashSet};
use gpui::{geometry::vector::vec2f, ContextHandle};
use language::language_settings::{AllLanguageSettings, SoftWrap};
use util::test::marked_text_offsets;
@ -158,11 +158,28 @@ impl<'a> NeovimBackedTestContext<'a> {
.await;
// +2 to account for the vim command UI at the bottom.
self.neovim.set_option(&format!("lines={}", rows + 2)).await;
let window = self.window;
let line_height =
self.editor(|editor, cx| editor.style(cx).text.line_height(cx.font_cache()));
let (line_height, visible_line_count) = self.editor(|editor, cx| {
(
editor
.style()
.unwrap()
.text
.line_height_in_pixels(cx.rem_size()),
editor.visible_line_count().unwrap(),
)
});
window.simulate_resize(vec2f(1000., (rows as f32) * line_height), &mut self.cx);
let window = self.window;
let margin = self
.update_window(window, |_, cx| {
cx.viewport_size().height - line_height * visible_line_count
})
.unwrap();
self.simulate_window_resize(
self.window,
size(px(1000.), margin + (rows as f32) * line_height),
);
}
pub async fn set_neovim_option(&mut self, option: &str) {
@ -211,12 +228,7 @@ impl<'a> NeovimBackedTestContext<'a> {
pub async fn assert_shared_clipboard(&mut self, text: &str) {
let neovim = self.neovim.read_register('"').await;
let editor = self
.platform()
.read_from_clipboard()
.unwrap()
.text()
.clone();
let editor = self.read_from_clipboard().unwrap().text().clone();
if text == neovim && text == editor {
return;

View file

@ -10,7 +10,7 @@ use async_compat::Compat;
#[cfg(feature = "neovim")]
use async_trait::async_trait;
#[cfg(feature = "neovim")]
use gpui::keymap_matcher::Keystroke;
use gpui::Keystroke;
#[cfg(feature = "neovim")]
use language::Point;
@ -116,16 +116,24 @@ impl NeovimConnection {
keystroke.key = "lt".to_string()
}
let special = keystroke.shift
|| keystroke.ctrl
|| keystroke.alt
|| keystroke.cmd
let special = keystroke.modifiers.shift
|| keystroke.modifiers.control
|| keystroke.modifiers.alt
|| keystroke.modifiers.command
|| keystroke.key.len() > 1;
let start = if special { "<" } else { "" };
let shift = if keystroke.shift { "S-" } else { "" };
let ctrl = if keystroke.ctrl { "C-" } else { "" };
let alt = if keystroke.alt { "M-" } else { "" };
let cmd = if keystroke.cmd { "D-" } else { "" };
let shift = if keystroke.modifiers.shift { "S-" } else { "" };
let ctrl = if keystroke.modifiers.control {
"C-"
} else {
""
};
let alt = if keystroke.modifiers.alt { "M-" } else { "" };
let cmd = if keystroke.modifiers.command {
"D-"
} else {
""
};
let end = if special { ">" } else { "" };
let key = format!("{start}{shift}{ctrl}{alt}{cmd}{}{end}", keystroke.key);

View file

@ -4,9 +4,9 @@ use editor::test::{
editor_lsp_test_context::EditorLspTestContext, editor_test_context::EditorTestContext,
};
use futures::Future;
use gpui::ContextHandle;
use gpui::{Context, View, VisualContext};
use lsp::request;
use search::{BufferSearchBar, ProjectSearchBar};
use search::BufferSearchBar;
use crate::{state::Operator, *};
@ -15,12 +15,28 @@ pub struct VimTestContext<'a> {
}
impl<'a> VimTestContext<'a> {
pub fn init(cx: &mut gpui::TestAppContext) {
if cx.has_global::<Vim>() {
dbg!("OOPS");
return;
}
cx.update(|cx| {
search::init(cx);
let settings = SettingsStore::test(cx);
cx.set_global(settings);
command_palette::init(cx);
crate::init(cx);
});
}
pub async fn new(cx: &'a mut gpui::TestAppContext, enabled: bool) -> VimTestContext<'a> {
Self::init(cx);
let lsp = EditorLspTestContext::new_rust(Default::default(), cx).await;
Self::new_with_lsp(lsp, enabled)
}
pub async fn new_typescript(cx: &'a mut gpui::TestAppContext) -> VimTestContext<'a> {
Self::init(cx);
Self::new_with_lsp(
EditorLspTestContext::new_typescript(Default::default(), cx).await,
true,
@ -28,12 +44,6 @@ impl<'a> VimTestContext<'a> {
}
pub fn new_with_lsp(mut cx: EditorLspTestContext<'a>, enabled: bool) -> VimTestContext<'a> {
cx.update(|cx| {
search::init(cx);
crate::init(cx);
command_palette::init(cx);
});
cx.update(|cx| {
cx.update_global(|store: &mut SettingsStore, cx| {
store.update_user_settings::<VimModeSetting>(cx, |s| *s = Some(enabled));
@ -47,14 +57,15 @@ impl<'a> VimTestContext<'a> {
observe_keystrokes(cx);
workspace.active_pane().update(cx, |pane, cx| {
pane.toolbar().update(cx, |toolbar, cx| {
let buffer_search_bar = cx.add_view(BufferSearchBar::new);
let buffer_search_bar = cx.new_view(BufferSearchBar::new);
toolbar.add_item(buffer_search_bar, cx);
let project_search_bar = cx.add_view(|_| ProjectSearchBar::new());
toolbar.add_item(project_search_bar, cx);
// todo!();
// let project_search_bar = cx.add_view(|_| ProjectSearchBar::new());
// toolbar.add_item(project_search_bar, cx);
})
});
workspace.status_bar().update(cx, |status_bar, cx| {
let vim_mode_indicator = cx.add_view(ModeIndicator::new);
let vim_mode_indicator = cx.new_view(ModeIndicator::new);
status_bar.add_right_item(vim_mode_indicator, cx);
});
});
@ -62,11 +73,21 @@ impl<'a> VimTestContext<'a> {
Self { cx }
}
pub fn workspace<F, T>(&mut self, read: F) -> T
pub fn update_view<F, T, R>(&mut self, view: View<T>, update: F) -> R
where
F: FnOnce(&Workspace, &ViewContext<Workspace>) -> T,
T: 'static,
F: FnOnce(&mut T, &mut ViewContext<T>) -> R + 'static,
{
self.cx.workspace.read_with(self.cx.cx.cx, read)
let window = self.window.clone();
self.update_window(window, move |_, cx| view.update(cx, update))
.unwrap()
}
pub fn workspace<F, T>(&mut self, update: F) -> T
where
F: FnOnce(&mut Workspace, &mut ViewContext<Workspace>) -> T,
{
self.cx.update_workspace(update)
}
pub fn enable_vim(&mut self) {
@ -94,16 +115,16 @@ impl<'a> VimTestContext<'a> {
.read(|cx| cx.global::<Vim>().state().operator_stack.last().copied())
}
pub fn set_state(&mut self, text: &str, mode: Mode) -> ContextHandle {
pub fn set_state(&mut self, text: &str, mode: Mode) {
let window = self.window;
let context_handle = self.cx.set_state(text);
window.update(self.cx.cx.cx, |cx| {
self.cx.set_state(text);
self.update_window(window, |_, cx| {
Vim::update(cx, |vim, cx| {
vim.switch_mode(mode, true, cx);
})
});
self.cx.foreground().run_until_parked();
context_handle
})
.unwrap();
self.cx.cx.cx.run_until_parked();
}
#[track_caller]