Visual Studio Code, rebuilt in Rust
Rust
use std::path::{Path, PathBuf};
use exthost::scan::scan_extension;
use gpui::{TestAppContext, VisualTestContext};
use serde_json::json;
use crate::editor::Position;
use crate::host_sync::HostSync;
use crate::languages::Languages;
use crate::theme::load_theme;
use crate::workbench::Workbench;
pub(in crate::workbench) fn workbench_with<'a>(name: &str, files: &[&str], cx: &'a mut TestAppContext) -> (PathBuf, gpui::Entity<Workbench>, &'a mut VisualTestContext) {
let app_root = Path::new(env!("VSCODE_SRC")).to_path_buf();
let themes = scan_extension(&app_root.join("extensions/theme-defaults"), true).unwrap();
let theme = load_theme(&[themes], "Dark Modern").unwrap();
let dir = std::env::temp_dir().join(format!("code-gpui-groups-{name}-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
let paths: Vec<PathBuf> = files.iter().map(|file| dir.join(file)).collect();
for path in &paths {
std::fs::write(path, "hello world\nsecond line").unwrap();
}
let keybindings = dir.join("keybindings.json");
let (workbench, cx) = cx.add_window_view(|window, cx| {
let mut workbench = Workbench::new(theme, app_root.clone(), None, Languages::new(&[]), crate::default_settings(), HostSync::new(std::sync::mpsc::channel().0), cx);
workbench.skip_dialogs = true;
workbench.load_keybindings(crate::keybindings::default_keybindings(&[]), keybindings);
for path in &paths {
workbench.open_file(path.clone(), true, window, cx);
}
workbench
});
cx.run_until_parked();
(dir, workbench, cx)
}
fn run(workbench: &gpui::Entity<Workbench>, command: &str, cx: &mut VisualTestContext) {
workbench.update_in(cx, |workbench, window, cx| drop(workbench.execute_command(command, vec![], window, cx)));
cx.run_until_parked();
}
/// Moves the active editor of a group without other editors into a new group to the right and activates the first
/// group again, which an untitled editor keeps open (`workbench.editor.closeEmptyGroups` closes an emptied group).
pub(in crate::workbench) fn move_active_editor_to_another_group(workbench: &gpui::Entity<Workbench>, cx: &mut VisualTestContext) {
workbench.update_in(cx, |workbench, window, cx| {
assert_eq!(workbench.editors.editors.len(), 1, "the active editor alone");
drop(workbench.execute_command("workbench.action.files.newUntitledFile", vec![], window, cx));
workbench.editors.activate(0);
drop(workbench.execute_command("workbench.action.moveEditorToNextGroup", vec![], window, cx));
drop(workbench.execute_command("workbench.action.focusPreviousGroup", vec![], window, cx));
});
cx.run_until_parked();
workbench.read_with(cx, |workbench, _| {
assert_eq!(workbench.editors.editors.len(), 1, "the moved editor is only in the other group");
assert_eq!(workbench.editors.active().unwrap().document().scheme, "untitled");
});
}
/// The groups in grid order with their tab names, and the active group's index.
fn groups(workbench: &gpui::Entity<Workbench>, cx: &mut VisualTestContext) -> (Vec<Vec<String>>, usize) {
workbench.read_with(cx, |workbench, _| {
let order = workbench.groups_in_grid_order();
let names = order.iter().map(|group| workbench.editors.group_tabs(*group).0.iter().map(|editor| editor.document().name()).collect()).collect();
(names, order.iter().position(|group| *group == workbench.editor_group_id()).unwrap())
})
}
#[gpui::test]
fn a_divider_separates_two_inactive_tabs_only(cx: &mut TestAppContext) {
let (_dir, workbench, cx) = workbench_with("divider", &["a.txt", "b.txt", "c.txt"], cx);
workbench.update(cx, |workbench, cx| {
workbench.editors.activate(0);
workbench.editors_changed(cx);
});
cx.run_until_parked();
assert!(cx.debug_bounds("tab-divider-1").is_none(), "the tab after the active one has no divider");
let divider = cx.debug_bounds("tab-divider-2").expect("a divider between two inactive tabs");
let tab = cx.debug_bounds("tab-name-2").expect("the third tab's name");
assert_eq!((divider.size.width, divider.size.height), (gpui::px(1.), gpui::px(16.)));
assert!((divider.center().y - tab.center().y).abs() < gpui::px(1.), "centered on the tab: {divider:?} {tab:?}");
}
#[gpui::test]
fn split_editor_shows_the_same_model_in_a_new_group_to_the_right(cx: &mut TestAppContext) {
let (_dir, workbench, cx) = workbench_with("split", &["a.txt"], cx);
workbench.update(cx, |workbench, _| workbench.editors.active_mut().unwrap().move_to(Position::new(1, 3), false));
cx.simulate_keystrokes(&crate::keybindings::primary_keys("secondary-\\"));
cx.run_until_parked();
assert_eq!(groups(&workbench, cx), (vec![vec!["a.txt".to_string()], vec!["a.txt".to_string()]], 1));
workbench.update(cx, |workbench, _| {
// splitEditor copies the view state: the cursor is where it was.
assert_eq!(workbench.editors.active().unwrap().selection().head, Position::new(1, 3));
let left = workbench.groups_in_grid_order()[0];
let shared = &workbench.editors.group_tabs(left).0[0].model;
assert!(std::rc::Rc::ptr_eq(shared, &workbench.editors.active().unwrap().model));
});
let context = workbench.update_in(cx, |workbench, window, _| workbench.key_context(window));
assert_eq!((context["multipleEditorGroups"].clone(), context["activeEditorGroupIndex"].clone(), context["activeEditorGroupLast"].clone()), (json!(true), json!(2), json!(true)));
}
#[gpui::test]
fn an_edit_in_one_group_moves_the_cursor_of_the_other(cx: &mut TestAppContext) {
let (_dir, workbench, cx) = workbench_with("sync", &["a.txt"], cx);
workbench.update(cx, |workbench, _| workbench.editors.active_mut().unwrap().move_to(Position::new(0, 6), false));
run(&workbench, "workbench.action.splitEditor", cx);
workbench.update(cx, |workbench, _| {
let editor = workbench.editors.active_mut().unwrap();
editor.move_to(Position::new(0, 0), false);
editor.type_text(">> ");
});
run(&workbench, "workbench.action.focusFirstEditorGroup", cx);
workbench.update(cx, |workbench, _| {
let editor = workbench.editors.active().unwrap();
assert_eq!(editor.document().lines[0], ">> hello world");
assert_eq!(editor.selection().head, Position::new(0, 9));
});
}
#[gpui::test]
fn closing_the_last_editor_of_a_group_closes_the_group(cx: &mut TestAppContext) {
let (_dir, workbench, cx) = workbench_with("close", &["a.txt", "b.txt"], cx);
run(&workbench, "workbench.action.moveEditorToNextGroup", cx);
assert_eq!(groups(&workbench, cx), (vec![vec!["a.txt".to_string()], vec!["b.txt".to_string()]], 1));
run(&workbench, "workbench.action.closeActiveEditor", cx);
assert_eq!(groups(&workbench, cx), (vec![vec!["a.txt".to_string()]], 0));
}
#[gpui::test]
fn close_group_merges_its_editors_into_the_most_recent_group(cx: &mut TestAppContext) {
let (_dir, workbench, cx) = workbench_with("merge", &["a.txt", "b.txt"], cx);
run(&workbench, "workbench.action.splitEditorDown", cx);
run(&workbench, "workbench.action.focusPreviousGroup", cx);
run(&workbench, "workbench.action.moveEditorToNextGroup", cx);
assert_eq!(groups(&workbench, cx), (vec![vec!["a.txt".to_string()], vec!["b.txt".to_string()]], 1));
run(&workbench, "workbench.action.closeGroup", cx);
assert_eq!(groups(&workbench, cx), (vec![vec!["a.txt".to_string(), "b.txt".to_string()]], 0));
}
#[gpui::test]
fn editor_layouts_add_and_merge_groups(cx: &mut TestAppContext) {
let (_dir, workbench, cx) = workbench_with("layouts", &["a.txt"], cx);
run(&workbench, "workbench.action.editorLayoutTwoByTwoGrid", cx);
assert_eq!(groups(&workbench, cx).0.len(), 4);
run(&workbench, "workbench.action.focusFourthEditorGroup", cx);
assert_eq!(groups(&workbench, cx).1, 3);
run(&workbench, "workbench.action.editorLayoutSingle", cx);
assert_eq!(groups(&workbench, cx), (vec![vec!["a.txt".to_string()]], 0));
}
#[gpui::test]
fn go_back_returns_to_the_previous_editor_and_location(cx: &mut TestAppContext) {
let (_dir, workbench, cx) = workbench_with("navigate", &["a.txt", "b.txt"], cx);
let active = |workbench: &gpui::Entity<Workbench>, cx: &mut VisualTestContext| workbench.read_with(cx, |workbench, _| workbench.editors.active().unwrap().document().name());
assert_eq!(active(&workbench, cx), "b.txt");
run(&workbench, "workbench.action.navigateBack", cx);
assert_eq!(active(&workbench, cx), "a.txt");
let context = workbench.update_in(cx, |workbench, window, _| workbench.key_context(window));
assert_eq!((context["canNavigateBack"].clone(), context["canNavigateForward"].clone()), (json!(false), json!(true)));
run(&workbench, "workbench.action.navigateForward", cx);
assert_eq!(active(&workbench, cx), "b.txt");
}
#[gpui::test]
fn reopen_closed_editor_brings_back_the_last_closed_file(cx: &mut TestAppContext) {
let (_dir, workbench, cx) = workbench_with("reopen", &["a.txt", "b.txt"], cx);
run(&workbench, "workbench.action.closeActiveEditor", cx);
assert_eq!(groups(&workbench, cx).0, vec![vec!["a.txt".to_string()]]);
run(&workbench, "workbench.action.reopenClosedEditor", cx);
assert_eq!(groups(&workbench, cx).0, vec![vec!["a.txt".to_string(), "b.txt".to_string()]]);
}
/// editorActions.ts `ClearEditorHistoryAction` confirms through `dialogService.confirm`, which
/// `window.dialogStyle: custom` shows as the workbench's custom dialog with the warning codicon.
#[gpui::test]
fn clear_editor_history_confirms_in_the_dialog_style(cx: &mut TestAppContext) {
let (dir, workbench, cx) = workbench_with("clear-history", &["a.txt", "b.txt"], cx);
std::fs::create_dir_all(dir.join("User")).unwrap();
std::fs::write(dir.join("User/settings.json"), r#"{ "window.dialogStyle": "custom" }"#).unwrap();
workbench.update(cx, |workbench, _| {
workbench.skip_dialogs = false;
workbench.settings = std::sync::Arc::new(std::sync::Mutex::new(config::service::Settings::load(config::registry::Registry::with_extensions(&[]), dir.join("User"), None)));
});
run(&workbench, "workbench.action.closeActiveEditor", cx);
run(&workbench, "workbench.action.clearEditorHistory", cx);
let shown = workbench.read_with(cx, |workbench, _| workbench.dialogs.iter().map(|shown| (shown.dialog.icon, shown.dialog.message.clone())).collect::<Vec<_>>());
assert_eq!(shown, [("warning", "Do you want to clear the history of recently opened editors?".to_owned())]);
workbench.update(cx, |workbench, cx| workbench.close_custom_dialog(0, cx));
cx.run_until_parked();
run(&workbench, "workbench.action.reopenClosedEditor", cx);
assert_eq!(groups(&workbench, cx).0, vec![vec!["a.txt".to_string()]], "Clear forgets the closed editor");
}
#[test]
fn a_drag_splits_at_the_edges_and_moves_in_the_center() {
use super::split_direction;
use crate::editor_grid::Direction;
// editorDropTarget.ts with openSideBySideDirection right: the left and right thirds split sideways.
assert_eq!(split_direction(50., 50., 100., 100., true), None);
assert_eq!(split_direction(5., 50., 100., 100., true), Some(Direction::Left));
assert_eq!(split_direction(95., 50., 100., 100., true), Some(Direction::Right));
assert_eq!(split_direction(50., 5., 100., 100., true), Some(Direction::Up));
assert_eq!(split_direction(50., 5., 100., 100., false), Some(Direction::Up));
assert_eq!(split_direction(20., 95., 100., 100., false), Some(Direction::Down));
}
#[gpui::test]
fn the_output_view_shows_in_the_panel_and_takes_the_focus_from_the_groups(cx: &mut TestAppContext) {
let (dir, workbench, cx) = workbench_with("output-panel", &["a.txt"], cx);
std::fs::write(dir.join("renderer.log"), "started\n").unwrap();
workbench.update_in(cx, |workbench, window, cx| {
workbench.output.register_window_log(dir.join("renderer.log"));
workbench.show_output_channel(crate::output::WINDOW_LOG_ID, false, window, cx);
});
cx.run_until_parked();
workbench.update_in(cx, |workbench, window, _| {
assert!(workbench.output_view_visible());
assert_eq!(workbench.editors.id, crate::editor::PANEL_GROUP);
let context = workbench.key_context(window);
assert_eq!((context["inOutput"].clone(), context["activeEditorGroupIndex"].clone()), (json!(true), json!(1)));
});
assert_eq!(groups(&workbench, cx), (vec![vec!["a.txt".to_string()]], 0));
run(&workbench, "workbench.action.splitEditor", cx);
assert_eq!(groups(&workbench, cx), (vec![vec!["a.txt".to_string()], vec!["a.txt".to_string()]], 1));
}
#[gpui::test]
fn close_editors_in_other_groups_leaves_the_active_group(cx: &mut TestAppContext) {
let (_dir, workbench, cx) = workbench_with("close-others", &["a.txt"], cx);
cx.simulate_keystrokes(&crate::keybindings::primary_keys("secondary-\\"));
cx.simulate_keystrokes(&crate::keybindings::primary_keys("secondary-\\"));
cx.run_until_parked();
assert_eq!(groups(&workbench, cx).0.len(), 3);
run(&workbench, "workbench.action.closeEditorsInOtherGroups", cx);
assert_eq!(groups(&workbench, cx), (vec![vec!["a.txt".to_string()]], 0));
// CloseAllEditorsAction empties every group; the emptied ones close.
cx.simulate_keystrokes(&crate::keybindings::primary_keys("secondary-\\"));
run(&workbench, "workbench.action.closeAllEditors", cx);
assert_eq!(groups(&workbench, cx), (vec![Vec::<String>::new()], 0));
}
#[gpui::test]
fn the_grid_and_its_editors_come_back_from_workspace_storage(cx: &mut TestAppContext) {
let (_dir, workbench, cx) = workbench_with("part-state", &["a.txt", "b.txt"], cx);
cx.simulate_keystrokes(&crate::keybindings::primary_keys("secondary-\\"));
cx.run_until_parked();
run(&workbench, "workbench.action.focusFirstEditorGroup", cx);
let saved = workbench.read_with(cx, |workbench, _| workbench.workspace_storage.lock().unwrap().get("memento/workbench.parts.editor").map(str::to_owned).unwrap());
let before = groups(&workbench, cx);
assert_eq!(before, (vec![vec!["a.txt".to_string(), "b.txt".to_string()], vec!["b.txt".to_string()]], 0));
run(&workbench, "workbench.action.closeAllEditors", cx);
assert_eq!(groups(&workbench, cx), (vec![Vec::<String>::new()], 0));
let storage = std::sync::Arc::new(std::sync::Mutex::new(storage::Storage::in_memory()));
storage.lock().unwrap().set("memento/workbench.parts.editor", saved);
workbench.update(cx, |workbench, _| workbench.restore_workspace_state(storage));
assert_eq!(groups(&workbench, cx), before);
let active = workbench.read_with(cx, |workbench, _| workbench.editors.active().unwrap().document().name());
assert_eq!(active, "b.txt");
}
/// editorCommands.ts `moveEditorToRightGroup` (the tab menu's Split & Move > Move Right): a new group when there is
/// none that way, the existing one after.
#[gpui::test]
fn move_right_moves_the_editor_into_the_group_on_the_right(cx: &mut TestAppContext) {
let (_dir, workbench, cx) = workbench_with("move-right", &["a.txt", "b.txt"], cx);
run(&workbench, "workbench.action.moveEditorToRightGroup", cx);
assert_eq!(groups(&workbench, cx), (vec![vec!["a.txt".to_string()], vec!["b.txt".to_string()]], 1));
run(&workbench, "workbench.action.focusFirstEditorGroup", cx);
run(&workbench, "workbench.action.moveEditorToRightGroup", cx);
assert_eq!(groups(&workbench, cx).0, vec![vec!["b.txt".to_string(), "a.txt".to_string()]], "into the existing group, the emptied one closes");
}
/// editorGroupModel.ts `serialize`/`deserialize`: the last sticky editor's index is stored and the sticky ones come
/// back sticky.
#[gpui::test]
fn sticky_editors_come_back_sticky_from_workspace_storage(cx: &mut TestAppContext) {
let (_dir, workbench, cx) = workbench_with("part-state-sticky", &["a.txt", "b.txt", "c.txt"], cx);
run(&workbench, "workbench.action.pinEditor", cx);
let saved = workbench.read_with(cx, |workbench, _| workbench.workspace_storage.lock().unwrap().get("memento/workbench.parts.editor").map(str::to_owned).unwrap());
let state: serde_json::Value = serde_json::from_str(&saved).unwrap();
assert_eq!(state["editorpart.state"]["serializedGrid"]["root"]["data"][0]["data"]["sticky"], json!(0));
workbench.update(cx, |workbench, _| {
for index in (0..3).rev() {
workbench.editors.close(index);
}
});
let storage = std::sync::Arc::new(std::sync::Mutex::new(storage::Storage::in_memory()));
storage.lock().unwrap().set("memento/workbench.parts.editor", saved);
workbench.update(cx, |workbench, _| workbench.restore_workspace_state(storage));
let tabs = workbench.read_with(cx, |workbench, _| workbench.editors.editors.iter().map(|editor| (editor.document().name(), editor.sticky)).collect::<Vec<_>>());
assert_eq!(tabs, [("c.txt".to_string(), true), ("a.txt".to_string(), false), ("b.txt".to_string(), false)]);
}
/// The sticky tab's Unpin Editor hover, again after the tab's context menu closes by Escape under a still pointer.
#[gpui::test]
fn the_unpin_hover_comes_back_after_the_tab_menu_closes(cx: &mut TestAppContext) {
let (_dir, workbench, cx) = workbench_with("unpin-hover", &["a.txt", "b.txt"], cx);
run(&workbench, "workbench.action.pinEditor", cx);
cx.update(|window, cx| drop(window.draw(cx)));
let pin = cx.debug_bounds("tab-action-0").expect("the sticky tab's action").center();
let shown = |cx: &mut VisualTestContext| workbench.read_with(cx, |workbench, _| workbench.hovers.shown_text().map(str::to_owned));
cx.simulate_mouse_move(pin, None, gpui::Modifiers::none());
cx.executor().advance_clock(std::time::Duration::from_millis(1500));
cx.run_until_parked();
assert_eq!(shown(cx).as_deref(), Some("Unpin Editor"));
cx.simulate_mouse_down(pin, gpui::MouseButton::Right, gpui::Modifiers::none());
cx.simulate_mouse_up(pin, gpui::MouseButton::Right, gpui::Modifiers::none());
assert!(workbench.read_with(cx, |workbench, _| workbench.context_menu.is_some()));
cx.simulate_keystrokes("escape");
for _ in 0..2 {
cx.update(|window, cx| {
window.simulate_next_frame(cx);
drop(window.draw(cx));
});
}
cx.executor().advance_clock(std::time::Duration::from_millis(1500));
cx.run_until_parked();
assert_eq!(shown(cx).as_deref(), Some("Unpin Editor"));
}
/// dnd.ts `ResourcesDropHandler`: a file dropped from Finder on a group's right half opens pinned in a new group there.
#[gpui::test]
fn files_dropped_from_outside_open_in_the_group_the_overlay_shows(cx: &mut TestAppContext) {
let (dir, workbench, cx) = workbench_with("external-drop", &["a.txt"], cx);
let dropped = dir.join("b.txt");
std::fs::write(&dropped, "dropped").unwrap();
workbench.update_in(cx, |workbench, window, cx| {
let group = workbench.editor_group_id();
workbench.editor_groups.drop_target = Some((group, Some(crate::editor_grid::Direction::Right)));
let target = workbench.drop_target_group(group).unwrap();
workbench.drop_external_paths(vec![dropped.clone()], target, window, cx);
});
cx.run_until_parked();
assert_eq!(groups(&workbench, cx), (vec![vec!["a.txt".to_owned()], vec!["b.txt".to_owned()]], 1));
assert!(workbench.read_with(cx, |workbench, _| !workbench.editors.active().unwrap().preview));
std::fs::remove_dir_all(&dir).unwrap();
}
/// dnd.ts `handleWorkspaceDrop`: two folders dropped on the editor enter one untitled workspace with both.
#[gpui::test]
fn folders_dropped_from_outside_enter_an_untitled_workspace(cx: &mut TestAppContext) {
let (dir, workbench, cx) = workbench_with("folders-drop", &[], cx);
let folders = [dir.join("a"), dir.join("b")];
for folder in &folders {
std::fs::create_dir_all(folder).unwrap();
}
let user_data = dir.join("user-data");
cx.update(|_, cx| {
let shared_storage = std::sync::Arc::new(std::sync::Mutex::new(storage::Storage::in_memory()));
cx.set_global(crate::AppState { args: Vec::new(), runtime: exthost::Runtime::Bun, user_data: user_data.clone(), app_root: dir.clone(), builtins: Vec::new(), user_extensions_folder: dir.join("extensions"), shared_storage });
});
let target = workbench.update(cx, |workbench, _| workbench.editor_group_id());
workbench.update_in(cx, |workbench, window, cx| workbench.drop_external_paths(folders.to_vec(), target, window, cx));
let untitled: Vec<PathBuf> = std::fs::read_dir(user_data.join("Workspaces")).unwrap().map(|entry| entry.unwrap().path().join("workspace.json")).collect();
assert_eq!(untitled.len(), 1);
let content = std::fs::read_to_string(&untitled[0]).unwrap();
for folder in &folders {
assert!(content.contains(&*folder.to_string_lossy()), "{content}");
}
std::fs::remove_dir_all(&dir).unwrap();
}
/// editorGroupFinder.ts: a locked group keeps its editors; others open in the most recent unlocked group, or a new
/// group beside the active one when every group is locked. The lock is stored with the group.
#[gpui::test]
fn a_locked_group_hands_opened_editors_to_an_unlocked_group(cx: &mut TestAppContext) {
let (dir, workbench, cx) = workbench_with("locked", &["a.txt", "b.txt"], cx);
run(&workbench, "workbench.action.splitEditorRight", cx);
run(&workbench, "workbench.action.lockEditorGroup", cx);
let open = |name: &str, cx: &mut VisualTestContext| {
workbench.update_in(cx, |workbench, window, cx| workbench.open_file(dir.join(name), true, window, cx));
cx.run_until_parked();
};
open("a.txt", cx);
assert_eq!(groups(&workbench, cx), (vec![vec!["a.txt".to_string(), "b.txt".to_string()], vec!["b.txt".to_string()]], 0));
// The locked group shows an editor it has open.
run(&workbench, "workbench.action.focusSecondEditorGroup", cx);
open("b.txt", cx);
assert_eq!(groups(&workbench, cx).1, 1);
run(&workbench, "workbench.action.focusFirstEditorGroup", cx);
run(&workbench, "workbench.action.toggleEditorGroupLock", cx);
run(&workbench, "workbench.action.files.newUntitledFile", cx);
let tabs = |names: &[&str]| names.iter().map(|name| name.to_string()).collect::<Vec<_>>();
assert_eq!(groups(&workbench, cx), (vec![tabs(&["a.txt", "b.txt"]), tabs(&["Untitled-1"]), tabs(&["b.txt"])], 1));
let saved = workbench.read_with(cx, |workbench, _| workbench.workspace_storage.lock().unwrap().get("memento/workbench.parts.editor").map(str::to_owned).unwrap());
let state: serde_json::Value = serde_json::from_str(&saved).unwrap();
let locked: Vec<serde_json::Value> = state["editorpart.state"]["serializedGrid"]["root"]["data"].as_array().unwrap().iter().map(|leaf| leaf["data"]["locked"].clone()).collect();
assert_eq!(locked, [json!(true), json!(null), json!(true)]);
}
/// editorGroupView.ts `openEditor`: `workbench.editor.autoLockGroups` locks a group whose first editor is listed.
#[gpui::test]
fn auto_lock_groups_locks_a_new_group_of_a_listed_editor(cx: &mut TestAppContext) {
let (dir, workbench, cx) = workbench_with("auto-lock", &["a.txt"], cx);
workbench.update(cx, |workbench, _| {
let settings = config::service::Settings::load(config::registry::Registry::with_extensions(&[]), dir.join("User"), None);
workbench.settings = std::sync::Arc::new(std::sync::Mutex::new(settings));
workbench.update_setting("workbench.editor.autoLockGroups", json!({ "default": true }));
});
run(&workbench, "workbench.action.splitEditorRight", cx);
let locked = workbench.read_with(cx, |workbench, _| workbench.groups_in_grid_order().into_iter().map(|group| workbench.editors.locked.contains(&group)).collect::<Vec<_>>());
assert_eq!(locked, [false, true]);
}
/// editorGroupView.ts: with `workbench.editor.enablePreview` off a single click opens pinned, and turning it off
/// (Toggle Keep Editors) pins the preview editor; a settings change turning it on again brings previews back.
#[gpui::test]
fn previews_off_pins_every_opened_editor(cx: &mut TestAppContext) {
let (dir, workbench, cx) = workbench_with("no-preview", &[], cx);
let open_preview = |name: &str, cx: &mut gpui::VisualTestContext| {
let path = dir.join(name);
std::fs::write(&path, "hello").unwrap();
workbench.update_in(cx, |workbench, window, cx| workbench.open_file(path, false, window, cx));
};
open_preview("a.txt", cx);
workbench.update_in(cx, |workbench, window, cx| {
let settings = config::service::Settings::load(config::registry::Registry::with_extensions(&[]), dir.join("User"), None);
workbench.settings = std::sync::Arc::new(std::sync::Mutex::new(settings));
drop(workbench.execute_command("workbench.action.toggleKeepEditors", Vec::new(), window, cx));
});
open_preview("b.txt", cx);
open_preview("c.txt", cx);
workbench.update(cx, |workbench, cx| {
let before = workbench.model_creation_options();
let change = workbench.settings.lock().unwrap().update_value("workbench.editor.enablePreview", None, config::service::Target::User, None, &[]).unwrap();
workbench.configuration_changed(&change, before, cx);
});
open_preview("d.txt", cx);
let previews = workbench.read_with(cx, |workbench, _| workbench.editors.editors.iter().map(|editor| editor.preview).collect::<Vec<_>>());
assert_eq!(previews, [false, false, false, true]);
}
/// editorGroupFinder.ts `handleGroupActivation`: SIDE_GROUP passes over a locked side group unless it has the
/// opening editor.
#[gpui::test]
fn side_group_passes_over_a_locked_group_without_the_editor(cx: &mut TestAppContext) {
let (dir, workbench, cx) = workbench_with("side-locked", &["a.txt", "b.txt"], cx);
run(&workbench, "workbench.action.splitEditorRight", cx);
run(&workbench, "workbench.action.lockEditorGroup", cx);
run(&workbench, "workbench.action.focusFirstEditorGroup", cx);
let b = dir.join("b.txt");
workbench.update(cx, |workbench, _| workbench.activate_column(&json!(-2), Some(("file", &b))));
assert_eq!(groups(&workbench, cx).1, 1);
run(&workbench, "workbench.action.focusFirstEditorGroup", cx);
let a = dir.join("a.txt");
workbench.update(cx, |workbench, _| workbench.activate_column(&json!(-2), Some(("file", &a))));
let names = |names: &[&str]| names.iter().map(|name| name.to_string()).collect::<Vec<_>>();
assert_eq!(groups(&workbench, cx), (vec![names(&["a.txt", "b.txt"]), names(&[]), names(&["b.txt"])], 1));
}
/// editorQuickAccess.ts: `edt ` lists the groups in grid order, `edt mru ` by recency, each group under its label
/// once there are several groups.
#[gpui::test]
fn edt_lists_each_groups_editors_under_its_label(cx: &mut TestAppContext) {
use crate::quick_input::Entry;
use crate::workbench::editor_quick_access::{ALL_PREFIX, MRU_PREFIX};
let (_dir, workbench, cx) = workbench_with("edt", &["a.txt", "b.txt"], cx);
run(&workbench, "workbench.action.splitEditorRight", cx);
let picks = |prefix: &str, filter: &str, cx: &mut VisualTestContext| {
workbench.read_with(cx, |workbench, _| {
let mut labels = Vec::new();
for entry in workbench.editor_picks(prefix, filter).0 {
labels.push(match entry {
Entry::Item(item) => item.label,
Entry::Separator(label) => format!("-- {}", label.unwrap_or_default()),
Entry::Header(_) => "header".into(),
});
}
labels
})
};
assert_eq!(picks(ALL_PREFIX, "", cx), ["-- Group 1", "a.txt", "b.txt", "-- Group 2", "b.txt"]);
assert_eq!(picks(MRU_PREFIX, "", cx), ["-- Group 2", "b.txt", "-- Group 1", "b.txt", "a.txt"]);
assert_eq!(picks(ALL_PREFIX, "zzz", cx), ["No matching editors"]);
}
/// editorGroupWatermark.ts: an empty window lists its entries in order, without Open Chat, which is not ported.
#[gpui::test]
fn the_empty_window_watermark_lists_its_entries(cx: &mut TestAppContext) {
let (_dir, workbench, cx) = workbench_with("watermark", &[], cx);
let labels = workbench.read_with(cx, |workbench, _| workbench.watermark_entries(1).into_iter().map(|entry| entry.0).collect::<Vec<_>>());
assert_eq!(labels, ["Show All Commands", "Open Recent", "Open File or Folder", "New Untitled Text File"]);
}
const TAB_LABELS: [&str; 6] = [".gitignore", "a.ts", "b.tsx", "d.py", "Dockerfile", "e.rs"];
struct TabLabels;
impl gpui::Render for TabLabels {
fn render(&mut self, _: &mut gpui::Window, _: &mut gpui::Context<Self>) -> impl gpui::IntoElement {
use gpui::{InteractiveElement, ParentElement, Styled, div, px};
div().flex().text_size(px(13.)).children(TAB_LABELS.map(|label| div().debug_selector(move || label.into()).child(label)))
}
}
/// Chromium lays text out in 1/64px units and snaps only at paint, so six tab labels in a row end within half a device
/// pixel of their summed shaped widths; whole-point widths pushed the sixth tab about 4pt right and a whole device px
/// per label about 1pt (port/fixtures/ui-pair/icons/seti.json).
#[gpui::test]
fn tab_labels_keep_their_fractional_widths(cx: &mut TestAppContext) {
let (_, cx) = cx.add_window_view(|_, _| TabLabels);
cx.run_until_parked();
let mut shaped_end = gpui::px(0.);
for label in TAB_LABELS {
let shaped = cx.update(|window, _| {
let style = window.text_style();
let run = gpui::TextRun { len: label.len(), font: style.font(), color: style.color, background_color: None, underline: None, strikethrough: None };
window.text_system().shape_line(label.into(), gpui::px(13.), &[run], None).width
});
shaped_end += shaped;
let bounds = cx.debug_bounds(label).unwrap();
assert!(bounds.size.width - shaped < gpui::px(0.5), "{label}: {:?} for {shaped:?}", bounds.size.width);
assert!((bounds.right() - shaped_end).abs() <= gpui::px(0.25), "{label}: ends at {:?}, shaped {shaped_end:?}", bounds.right());
}
}
/// A sticky shrink tab whose name and badge do not both fit gives the name up first: the reference (ref-dom, 80px tab
/// of bad.ts with "1, U") has the name box 0px wide, the badge 5px after it and clipped by the label 21.5px after it.
#[gpui::test]
fn a_shrink_sticky_tab_drops_its_name_before_its_badge(cx: &mut TestAppContext) {
let (dir, workbench, cx) = workbench_with("shrink-badge", &["bad.ts"], cx);
run(&workbench, "workbench.action.pinEditor", cx);
workbench.update(cx, |workbench, cx| {
let settings = config::service::Settings::load(config::registry::Registry::with_extensions(&[]), dir.join("User"), None);
workbench.settings = std::sync::Arc::new(std::sync::Mutex::new(settings));
workbench.extensions = vec![scan_extension(&workbench.app_root.join("extensions/theme-seti"), true).unwrap()];
std::fs::create_dir_all(dir.join("User")).unwrap();
std::fs::write(dir.join("User/settings.json"), r#"{ "workbench.editor.pinnedTabSizing": "shrink", "workbench.iconTheme": "vs-seti" }"#).unwrap();
workbench.reload_changed_settings_files(cx);
let mut decorations = workbench.decorations.borrow_mut();
decorations.register(1);
let letter = Some("1, U".to_owned());
decorations.set(1, &dir.join("bad.ts").to_string_lossy(), Some(crate::decorations::DecorationData { weight: 10, bubble: false, tooltip: None, letter, color: None }));
drop(decorations);
cx.notify();
});
cx.update(|window, cx| drop(window.draw(cx)));
let name = cx.debug_bounds("tab-name-0").expect("the tab's name");
let badge = cx.debug_bounds("tab-badge-0").expect("the tab's badge");
assert_eq!(name.size.width, gpui::px(0.));
assert_eq!(badge.left() - name.left(), gpui::px(5.));
let label = cx.debug_bounds("tab-label-0").expect("the tab's clipping label");
assert_eq!(label.right() - name.left(), gpui::px(21.5));
assert!(badge.right() > label.right());
std::fs::remove_dir_all(dir).unwrap();
}
/// modernUI tabs.css with `workbench.experimental.modernUIEditorTabStyle: pill` (ui-pair bugs/pill-tabs.json): the
/// strip has 2px before its first tab, each tab a 24px pill 4px below the strip's top and 2px in from the tab's sides,
/// 26px of each after its name for the close action, shown or not, and a divider before
/// every tab but the first, the active one's neighbor included.
#[gpui::test]
fn the_pill_tab_style_draws_floating_pills(cx: &mut TestAppContext) {
let (dir, workbench, cx) = workbench_with("pill", &["a.txt", "b.txt", "c.txt"], cx);
workbench.update(cx, |workbench, cx| {
let settings = config::service::Settings::load(config::registry::Registry::with_extensions(&[]), dir.join("User"), None);
workbench.settings = std::sync::Arc::new(std::sync::Mutex::new(settings));
std::fs::create_dir_all(dir.join("User")).unwrap();
std::fs::write(dir.join("User/settings.json"), r#"{ "workbench.experimental.modernUIEditorTabStyle": "pill" }"#).unwrap();
workbench.reload_changed_settings_files(cx);
workbench.editors.activate(0);
workbench.editors_changed(cx);
});
cx.run_until_parked();
let strip = cx.debug_bounds("editor-tab-strip").expect("the tab strip");
let active = cx.debug_bounds("tab-pill-0").expect("the active tab's pill");
assert_eq!((active.left() - strip.left(), active.top() - strip.top(), active.size.height), (gpui::px(4.), gpui::px(4.), gpui::px(24.)));
let name = cx.debug_bounds("tab-name-0").unwrap();
assert_eq!(active.right() - name.right(), gpui::px(26.));
let inactive = cx.debug_bounds("tab-pill-1").expect("an inactive tab's pill");
assert_eq!(inactive.right() - cx.debug_bounds("tab-name-1").unwrap().right(), gpui::px(26.));
assert_eq!(inactive.left() - active.right(), gpui::px(4.), "2px of each tab between the pills");
assert!(cx.debug_bounds("tab-divider-0").is_none());
assert!(cx.debug_bounds("tab-divider-1").is_some(), "the active tab's neighbor has a divider too");
std::fs::remove_dir_all(dir).unwrap();
}
/// tabs.css `two-tab-bars` with pills: both bars are 32px high, the pinned bar's pills 6px below its top and the
/// lower bar's 2px below its own, so 4px separate the two rows where two 32px bars would leave 8px.
#[gpui::test]
fn pills_on_separate_rows_keep_a_4px_gap(cx: &mut TestAppContext) {
let (dir, workbench, cx) = workbench_with("pill-rows", &["a.txt", "b.txt", "c.txt"], cx);
workbench.update(cx, |workbench, cx| {
let settings = config::service::Settings::load(config::registry::Registry::with_extensions(&[]), dir.join("User"), None);
workbench.settings = std::sync::Arc::new(std::sync::Mutex::new(settings));
std::fs::create_dir_all(dir.join("User")).unwrap();
std::fs::write(dir.join("User/settings.json"), r#"{ "workbench.experimental.modernUIEditorTabStyle": "pill", "workbench.editor.pinnedTabsOnSeparateRow": true }"#).unwrap();
workbench.reload_changed_settings_files(cx);
workbench.editors.activate(0);
workbench.editors_changed(cx);
});
run(&workbench, "workbench.action.pinEditor", cx);
let strip = cx.debug_bounds("editor-tab-strip").expect("the lower bar");
let pinned = cx.debug_bounds("tab-pill-0").expect("the pinned tab's pill");
let lower = cx.debug_bounds("tab-pill-1").expect("a lower tab's pill");
assert_eq!((pinned.top() - (strip.top() - gpui::px(32.)), lower.top() - strip.top()), (gpui::px(6.), gpui::px(2.)));
assert_eq!(lower.top() - pinned.bottom(), gpui::px(4.));
std::fs::remove_dir_all(dir).unwrap();
}
/// modelService.ts `_updateModelOptions` runs over `getModels()`: a changed `editor.tabSize` reaches a file whose only
/// editor is in another group.
#[gpui::test]
fn a_changed_tab_size_reaches_a_model_in_another_group(cx: &mut TestAppContext) {
let (dir, workbench, cx) = workbench_with("other-group-tab-size", &["a.txt"], cx);
move_active_editor_to_another_group(&workbench, cx);
workbench.update(cx, |workbench, cx| {
let settings = config::service::Settings::load(config::registry::Registry::with_extensions(&[]), dir.join("User"), None);
workbench.settings = std::sync::Arc::new(std::sync::Mutex::new(settings));
let before = workbench.model_creation_options();
let change = workbench.settings.lock().unwrap().update_value("editor.tabSize", Some(&json!(2)), config::service::Target::User, None, &[]).unwrap();
workbench.configuration_changed(&change, before, cx);
});
let tab_size = workbench.read_with(cx, |workbench, _| workbench.editors.model("file", &dir.join("a.txt")).unwrap().document().indentation.tab_size);
assert_eq!(tab_size, 2);
std::fs::remove_dir_all(dir).unwrap();
}
/// breakpointEditorContribution.ts sets the inline breakpoint widgets in every code editor: a column breakpoint in a
/// file shown only in another group gets its widget.
#[gpui::test]
fn a_column_breakpoint_in_another_group_gets_its_inline_widget(cx: &mut TestAppContext) {
let (dir, workbench, cx) = workbench_with("other-group-inline-breakpoint", &["a.txt"], cx);
move_active_editor_to_another_group(&workbench, cx);
let uri = crate::editor::uri_value("file", &dir.join("a.txt"));
workbench.update(cx, |workbench, cx| {
workbench.debug.model.add_breakpoints(&uri, vec![crate::debug::BreakpointData { column: Some(7), ..crate::debug::BreakpointData::at(1) }]);
cx.notify();
});
cx.run_until_parked();
cx.update(|window, cx| drop(window.draw(cx)));
let widgets = workbench.read_with(cx, |workbench, _| workbench.debug.inline_breakpoints.widgets.keys().cloned().collect::<Vec<_>>());
assert_eq!(widgets, [crate::editor::uri_string("file", &dir.join("a.txt"))]);
std::fs::remove_dir_all(dir).unwrap();
}
/// debugModel.ts `Breakpoint.verified` asks `textFileService.isDirty(uri)`, which no group limits: a breakpoint in a
/// dirty file shown only in another group sees the file dirty.
#[gpui::test]
fn a_breakpoint_in_a_dirty_file_in_another_group_sees_the_file_dirty(cx: &mut TestAppContext) {
let (dir, workbench, cx) = workbench_with("other-group-dirty-breakpoint", &["a.txt"], cx);
workbench.update_in(cx, |workbench, window, cx| drop(workbench.execute_command("type", vec![json!({ "text": "x" })], window, cx)));
move_active_editor_to_another_group(&workbench, cx);
let uri = crate::editor::uri_value("file", &dir.join("a.txt"));
let dirty = workbench.update(cx, |workbench, _| {
workbench.debug.model.add_breakpoints(&uri, vec![crate::debug::BreakpointData::at(1)]);
workbench.breakpoint_file_is_dirty(&workbench.debug.model.breakpoints[0])
});
assert!(dirty);
std::fs::remove_dir_all(dir).unwrap();
}
/// markerDecorationsService.ts `_onMarkerChanged` updates the decorations of `modelService.getModel(resource)`: a
/// marker on a file shown only in another group decorates its model.
#[gpui::test]
fn a_marker_decorates_a_model_in_another_group(cx: &mut TestAppContext) {
let (dir, workbench, cx) = workbench_with("other-group-markers", &["a.txt"], cx);
move_active_editor_to_another_group(&workbench, cx);
let uri = crate::editor::uri_value("file", &dir.join("a.txt"));
let marker = json!({ "severity": 8, "message": "problem", "startLineNumber": 1, "startColumn": 1, "endLineNumber": 1, "endColumn": 2 });
workbench.update(cx, |workbench, cx| workbench.change_many_markers("test", &json!([[uri, [marker], false]]), cx));
let decorations = workbench.read_with(cx, |workbench, _| workbench.editors.model("file", &dir.join("a.txt")).unwrap().text_model().markers.len());
assert_eq!(decorations, 1);
std::fs::remove_dir_all(dir).unwrap();
}
/// wordHighlighter.ts `_executeDocumentHighlights` and outlineModel.ts `_executeDocumentSymbolProvider` take the model
/// from `modelService.getModel(resource)`: a file shown only in another group answers instead of failing.
#[gpui::test]
fn model_commands_answer_for_a_model_in_another_group(cx: &mut TestAppContext) {
let (dir, workbench, cx) = workbench_with("other-group-model-commands", &["a.txt"], cx);
move_active_editor_to_another_group(&workbench, cx);
let uri = json!({ "scheme": "file", "path": dir.join("a.txt").to_string_lossy() });
let (highlights, symbols) = workbench.update_in(cx, |workbench, window, cx| {
let highlights = workbench.execute_command("_executeDocumentHighlights", vec![uri.clone(), json!({ "lineNumber": 1, "column": 1 })], window, cx);
let symbols = workbench.execute_command("_executeDocumentSymbolProvider", vec![uri], window, cx);
(highlights, symbols)
});
assert!(matches!(highlights, crate::commands::Outcome::Pending(_)));
assert!(matches!(symbols, crate::commands::Outcome::Pending(_)));
std::fs::remove_dir_all(dir).unwrap();
}
/// contextkeys.ts sets `dirtyWorkingCopies` from `workingCopyService.hasDirty`, which no group limits: a dirty file
/// shown only in another group keeps Save All enabled.
#[gpui::test]
fn a_dirty_file_in_another_group_sets_dirty_working_copies(cx: &mut TestAppContext) {
let (dir, workbench, cx) = workbench_with("other-group-dirty-context", &["a.txt"], cx);
workbench.update_in(cx, |workbench, window, cx| drop(workbench.execute_command("type", vec![json!({ "text": "x" })], window, cx)));
move_active_editor_to_another_group(&workbench, cx);
let dirty = workbench.update_in(cx, |workbench, window, _| workbench.key_context(window)["dirtyWorkingCopies"].clone());
assert_eq!(dirty, json!(true));
std::fs::remove_dir_all(dir).unwrap();
}
/// smartSelect.ts `_executeSelectionRangeProvider` takes the model from `modelService.getModel(resource)`: a file
/// shown only in another group answers its ranges, not an empty list.
#[gpui::test]
fn selection_ranges_answer_for_a_model_in_another_group(cx: &mut TestAppContext) {
let (dir, workbench, cx) = workbench_with("other-group-selection-ranges", &["a.txt"], cx);
move_active_editor_to_another_group(&workbench, cx);
let uri = json!({ "scheme": "file", "path": dir.join("a.txt").to_string_lossy() });
let answer = workbench.update_in(cx, |workbench, window, cx| workbench.execute_command("_executeSelectionRangeProvider", vec![uri, json!([{ "lineNumber": 1, "column": 2 }])], window, cx));
let crate::commands::Outcome::Ready(Ok(ranges)) = answer else { panic!("answered at once without providers") };
assert!(!ranges[0].as_array().unwrap().is_empty(), "{ranges}");
std::fs::remove_dir_all(dir).unwrap();
}
/// callStackEditorContribution.ts decorates every code editor with the top stack frame's column: a file shown only in
/// another group gets its column marker.
#[gpui::test]
fn a_stopped_frame_in_another_group_gets_its_column_marker(cx: &mut TestAppContext) {
let (dir, workbench, cx) = workbench_with("other-group-frame-column", &["a.txt"], cx);
move_active_editor_to_another_group(&workbench, cx);
let path = dir.join("a.txt");
workbench.update(cx, |workbench, cx| {
let mut session = crate::debug::session::Session::new("s".into(), 1, json!({ "name": "s", "type": "node", "request": "launch" }), json!({}), None, json!({}));
session.set_threads(&[json!({ "id": 1, "name": "main" })]);
let thread = session.thread_mut(1).unwrap();
thread.stopped = true;
thread.frames = vec![crate::debug::session::StackFrame { id: 9, name: "f".into(), source: json!({ "path": path.to_string_lossy() }), line: 1, column: 3, end_line: 1, end_column: 3, ..Default::default() }];
workbench.debug.sessions.push(session);
cx.notify();
});
cx.run_until_parked();
cx.update(|window, cx| drop(window.draw(cx)));
let markers = workbench.read_with(cx, |workbench, _| {
let editor = workbench.editors.model("file", &path).unwrap();
editor.injected_text.iter().filter(|injection| injection.owner == crate::editor::injected_text::InjectionOwner::StackFrameColumn).count()
});
assert_eq!(markers, 1);
std::fs::remove_dir_all(dir).unwrap();
}
/// gotoError.ts `MarkerController._cleanUp` disposes the widget, whose zone leaves the editor it lives in: a marker
/// navigation closed after its editor moved to another group leaves no empty zone behind.
#[gpui::test]
fn closing_marker_navigation_in_another_group_removes_its_zone(cx: &mut TestAppContext) {
let (dir, workbench, cx) = workbench_with("other-group-marker-navigation", &["a.txt"], cx);
let uri = crate::editor::uri_value("file", &dir.join("a.txt"));
let marker = json!({ "severity": 8, "message": "problem", "startLineNumber": 1, "startColumn": 1, "endLineNumber": 1, "endColumn": 2 });
workbench.update_in(cx, |workbench, window, cx| {
workbench.change_many_markers("test", &json!([[uri, [marker], false]]), cx);
drop(workbench.execute_command("editor.action.marker.next", vec![], window, cx));
});
cx.run_until_parked();
let zones = |workbench: &Workbench| workbench.editors.model("file", &dir.join("a.txt")).unwrap().view_zones.len();
assert_eq!(workbench.read_with(cx, |workbench, _| zones(workbench)), 1, "the widget's zone");
move_active_editor_to_another_group(&workbench, cx);
workbench.update_in(cx, |workbench, window, cx| drop(workbench.execute_command("closeMarkersNavigation", vec![], window, cx)));
cx.run_until_parked();
assert_eq!(workbench.read_with(cx, |workbench, _| zones(workbench)), 0);
std::fs::remove_dir_all(dir).unwrap();
}
/// zoneWidget.ts `ZoneWidget.dispose` removes the zone from its own editor: the exception widget (exceptionWidget.ts)
/// closed after its editor moved to another group leaves no empty zone behind.
#[gpui::test]
fn closing_the_exception_widget_in_another_group_removes_its_zone(cx: &mut TestAppContext) {
let (dir, workbench, cx) = workbench_with("other-group-exception-widget", &["a.txt"], cx);
let path = dir.join("a.txt").to_string_lossy().into_owned();
workbench.update(cx, |workbench, cx| workbench.show_exception_widget(&path, 1, json!({ "description": "boom" }), cx));
let zones = |workbench: &Workbench| workbench.editors.model("file", &dir.join("a.txt")).unwrap().view_zones.len();
assert_eq!(workbench.read_with(cx, |workbench, _| zones(workbench)), 1, "the widget's zone");
move_active_editor_to_another_group(&workbench, cx);
workbench.update(cx, |workbench, cx| workbench.close_exception_widget(cx));
assert_eq!(workbench.read_with(cx, |workbench, _| zones(workbench)), 0);
std::fs::remove_dir_all(dir).unwrap();
}
/// zoneWidget.ts `ZoneWidget.dispose`: the breakpoint widget (breakpointWidget.ts) closed after its editor moved to
/// another group leaves no empty zone behind.
#[gpui::test]
fn closing_the_breakpoint_widget_in_another_group_removes_its_zone(cx: &mut TestAppContext) {
let (dir, workbench, cx) = workbench_with("other-group-breakpoint-widget", &["a.txt"], cx);
workbench.update_in(cx, |workbench, window, cx| workbench.show_breakpoint_widget(1, None, None, crate::workbench::breakpoint_widget::WidgetContext::Condition, window, cx));
let zones = |workbench: &Workbench| workbench.editors.model("file", &dir.join("a.txt")).unwrap().view_zones.len();
assert_eq!(workbench.read_with(cx, |workbench, _| zones(workbench)), 1, "the widget's zone");
move_active_editor_to_another_group(&workbench, cx);
workbench.update_in(cx, |workbench, window, cx| workbench.close_breakpoint_widget(window, cx));
assert_eq!(workbench.read_with(cx, |workbench, _| zones(workbench)), 0);
std::fs::remove_dir_all(dir).unwrap();
}