Skip to content

Visual Studio Code, rebuilt in Rust

Rust

feat(testing): add coverage actions to the editor title menu

rokarturfd4cf66530dd
diff --git a/native/crates/app/src/menus.rs b/native/crates/app/src/menus.rs
index 90592fe601a..e648b92bf0c 100644
--- a/native/crates/app/src/menus.rs
+++ b/native/crates/app/src/menus.rs
@@ -650,6 +650,9 @@ const WORKBENCH_MENUS: &[Row] = &[
(MenuId::EditorTitle, None, "workbench.action.toggleMaximizeEditorGroup", "Maximize Group", "8_group_operations", 5., Some("!editorPartMaximizedEditorGroup && editorPartMultipleEditorGroups"), None),
(MenuId::EditorTitle, None, "workbench.action.toggleMaximizeEditorGroup", "Unmaximize Group", "8_group_operations", 5., Some("editorPartMaximizedEditorGroup"), None),
(MenuId::EditorTitle, None, "workbench.action.configureEditor", "Configure Editors", "9_configure", 10., Some("!editorPartModal"), None),
+ // codeCoverageDecorations.ts: GoToNextMissedCoverageLine and GoToPreviousMissedCoverageLine.
+ (MenuId::EditorTitle, None, "testing.coverage.goToNextMissedLine", "Go to Next Uncovered Line", "coverage", 2., Some("testing.hasCoverageInFile"), Some("testing.hasCoverageInFile")),
+ (MenuId::EditorTitle, None, "testing.coverage.goToPreviousMissedLine", "Go to Previous Uncovered Line", "coverage", 3., Some("testing.hasCoverageInFile"), Some("testing.hasCoverageInFile")),
// fileActions.contribution.ts and editor.contribution.ts: the empty editor group's context menu.
(MenuId::EmptyEditorGroupContext, None, "workbench.action.files.newUntitledFile", "New Text File", "1_file", 10., None, None),
(MenuId::EmptyEditorGroupContext, None, "workbench.action.quickOpen", "Open File...", "1_file", 20., None, None),
@@ -928,6 +931,9 @@ pub fn workbench_menus() -> Vec<MenuItem> {
(MenuId::EditorTitle, "workbench.action.toggleKeepEditors", "Enable Preview Editors", "7_settings", 10., "config.workbench.editor.enablePreview", "!editorPartModal"),
(MenuId::EditorTitle, "workbench.action.toggleEditorGroupLock", "Lock Group", "8_group_operations", 10., "activeEditorGroupLocked", "!isAuxiliaryWindow && !editorPartModal"),
(MenuId::EmptyEditorGroupContext, "workbench.action.toggleEditorGroupLock", "Lock Group", "4_lock", 10., "activeEditorGroupLocked", "!isAuxiliaryWindow"),
+ // codeCoverageDecorations.ts ToggleCoverageToolbar.
+ (MenuId::EditorTitle, "testing.coverageToggleToolbar", "Show Test Coverage Toolbar", "coverage", 1., "testing.coverageToolbarEnabled", "testing.hasCoverageInFile"),
+ (MenuId::StickyScrollContext, "testing.coverageToggleToolbar", "Show Test Coverage Toolbar", "", 0., "testing.coverageToolbarEnabled", "testing.isTestCoverageOpen"),
];
for (menu, id, title, group, order, toggled, when) in toggles {
let entry = Entry::Command { id: id.into(), precondition: None, toggled: Toggled::when(Some(Expr::has(toggled))), alt: None };
diff --git a/native/crates/app/src/testing_coverage.rs b/native/crates/app/src/testing_coverage.rs
index 0f013fd7936..f6e30bcb576 100644
--- a/native/crates/app/src/testing_coverage.rs
+++ b/native/crates/app/src/testing_coverage.rs
@@ -486,8 +486,14 @@ pub struct DetailRange {
}
impl DetailRange {
- pub fn kind(&self) -> DetailType {
- if self.branch.is_some() { DetailType::Branch } else { DetailType::Statement }
+ /// codeCoverageDecorations.ts `apply`'s `CLASS_HIT` or `CLASS_MISS`: a branch's count, else a statement's. A
+ /// declaration's range has no decoration.
+ pub fn hit(&self, details: &[CoverageDetail]) -> Option<bool> {
+ let detail = &details[self.detail];
+ match self.branch {
+ Some(branch) => Some(detail.branches[branch].count.is_hit()),
+ None => (detail.kind == DetailType::Statement).then(|| detail.count.is_hit()),
+ }
}
}
diff --git a/native/crates/app/src/workbench/testing_coverage_view.rs b/native/crates/app/src/workbench/testing_coverage_view.rs
index 3ea9e76a956..e2a4e00cd91 100644
--- a/native/crates/app/src/workbench/testing_coverage_view.rs
+++ b/native/crates/app/src/workbench/testing_coverage_view.rs
@@ -102,6 +102,18 @@ impl Workbench {
cx.notify();
Outcome::done()
});
+ self.commands.register("testing.coverageToggleToolbar", |workbench, _, _, cx| {
+ let enabled = workbench.setting("testing.coverageToolbarEnabled") != false;
+ workbench.update_setting("testing.coverageToolbarEnabled", json!(!enabled));
+ cx.notify();
+ Outcome::done()
+ });
+ for (id, next) in [("testing.coverage.goToNextMissedLine", true), ("testing.coverage.goToPreviousMissedLine", false)] {
+ self.commands.register(id, move |workbench, _, _, cx| {
+ workbench.go_to_missed_line(next, cx);
+ Outcome::done()
+ });
+ }
self.commands.register("testing.coverageViewCollapseAll", |workbench, _, _, cx| {
let expanded: Vec<String> = workbench.coverage_rows().into_iter().filter(|row| row.collapsible && !row.collapsed).map(|row| row.id).collect();
for id in expanded {
@@ -476,12 +488,7 @@ impl Workbench {
let Some(file) = self.file_coverage(uri) else { return lines };
let Some(details) = self.coverage_details(&file, cx) else { return lines };
for range in detail_ranges(details) {
- let detail = &details[range.detail];
- let hit = match (range.kind(), range.branch) {
- (DetailType::Branch, Some(branch)) => detail.branches[branch].count.is_hit(),
- (DetailType::Statement, _) => detail.count.is_hit(),
- _ => continue,
- };
+ let Some(hit) = range.hit(details) else { continue };
// A report's lines are the extension's: the model's line range bounds them (`validateRange`).
let start = (range.range.start.line as usize).max(1);
let end = (range.range.end.line as usize).min(line_count);
@@ -505,6 +512,34 @@ impl Workbench {
lines
}
+ /// `navigateToMissedLine`: the cursor to the first column of the nearest missed range's start line after (`next`)
+ /// or before the cursor's line, else the first or last one, revealed in the center. Empty ranges do not count.
+ fn go_to_missed_line(&mut self, next: bool, cx: &mut Context<Self>) {
+ let Some(editor) = self.editors.active() else { return };
+ let (current, line_count) = (editor.selections[0].head.line, editor.document().lines.len());
+ let Some(file) = self.file_coverage(&editor.document().uri()) else { return };
+ let Some(details) = self.cached_coverage_details(&file) else { return };
+ let mut missed = Vec::new();
+ for range in detail_ranges(details) {
+ if range.hit(details) == Some(false) && !range.range.is_empty() {
+ missed.push((range.range.start.line as usize).clamp(1, line_count) - 1);
+ }
+ }
+ let target = match next {
+ true => missed.iter().filter(|line| **line > current).min().or(missed.iter().min()),
+ false => missed.iter().filter(|line| **line < current).max().or(missed.iter().max()),
+ };
+ let Some(&line) = target else { return };
+ let position = crate::editor::Position::new(line, 0);
+ let viewport = self.editors.viewport;
+ let editor = self.editors.active_mut().expect("checked above");
+ editor.set_selections(vec![crate::editor::Selection { anchor: position, head: position }]);
+ editor.reveal_range(position, position, crate::editor::VerticalReveal::Center, viewport);
+ self.host.send_selection(editor, "api");
+ self.editor_scrolled(cx);
+ cx.notify();
+ }
+
/// The opened coverage's details of a file for the test filter, loaded on first ask.
fn coverage_details(&self, file: &FileCoverage, cx: &mut Context<Self>) -> Option<&[CoverageDetail]> {
let (_, _, coverage) = self.selected_coverage()?;
diff --git a/native/crates/app/src/workbench/testing_coverage_view/tests.rs b/native/crates/app/src/workbench/testing_coverage_view/tests.rs
index 47a6577a897..300601a168d 100644
--- a/native/crates/app/src/workbench/testing_coverage_view/tests.rs
+++ b/native/crates/app/src/workbench/testing_coverage_view/tests.rs
@@ -206,6 +206,47 @@ fn the_minimap_marks_covered_and_missed_lines_until_the_setting_turns_off(cx: &m
assert!(off.is_empty(), "the setting turns the marks off");
}
+/// codeCoverageDecorations.ts: the editor title's `...` of a file with coverage holds Show Test Coverage Toolbar,
+/// unchecked by default, and Go to Next and Previous Uncovered Line, which move the cursor to the start of the
+/// nearest missed statement range after or before its line, wrapping around (`navigateToMissedLine`).
+#[gpui::test]
+fn the_editor_title_goes_to_the_next_and_previous_uncovered_line(cx: &mut TestAppContext) {
+ let (workbench, cx, _host) = workbench_with_tests("coverage-missed-lines", TESTS, cx);
+ workbench.update_in(cx, |workbench, window, cx| {
+ add_result(workbench);
+ let uri = workbench.editors.active().expect("the test file").document().uri();
+ let coverage = json!({ "id": "f1", "uri": uri, "statement": { "covered": 1, "total": 3 } });
+ drop(workbench.handle_testing_request(request("$appendCoverage", vec![json!("r1"), json!("t1"), coverage]), window, cx));
+ workbench.open_coverage("r1", 0, false, cx);
+ let range = |line: u32| json!({ "startLineNumber": line, "startColumn": 1, "endLineNumber": line, "endColumn": 10 });
+ let empty = json!({ "startLineNumber": 2, "startColumn": 3, "endLineNumber": 2, "endColumn": 3 });
+ let details = vec![json!({ "type": 1, "count": 0, "location": range(1) }), json!({ "type": 1, "count": 0, "location": empty }), json!({ "type": 0, "name": "f", "count": 0, "location": range(2) }), json!({ "type": 1, "count": 0, "location": range(3) })];
+ let file = workbench.selected_coverage().expect("open").2.file(&crate::testing_coverage::CoverageUri::from_value(&uri)).expect("the file").clone();
+ let details = details.iter().filter_map(crate::testing_coverage::CoverageDetail::from_value).collect();
+ workbench.testing.results[0].tasks[0].coverage.as_mut().expect("coverage").details.insert((file.uri, None), Some(details));
+ workbench.show_editor_title_menu(gpui::Bounds::default(), false, window, cx);
+ });
+ let titles = workbench.read_with(cx, |workbench, _| {
+ let menu = workbench.context_menu.as_ref().expect("the title menu");
+ let titles: Vec<_> = menu.levels[0].actions.iter().filter_map(|action| match action {
+ crate::menus::MenuAction::Command { title, checked, .. } => Some((title.clone(), *checked)),
+ _ => None,
+ }).collect();
+ titles
+ });
+ assert!(titles.ends_with(&[("Show Test Coverage Toolbar".into(), false), ("Go to Next Uncovered Line".into(), false), ("Go to Previous Uncovered Line".into(), false)]), "{titles:?}");
+ cx.simulate_keystrokes("escape");
+ let mut cursor_lines = Vec::new();
+ for command in ["testing.coverage.goToNextMissedLine", "testing.coverage.goToNextMissedLine", "testing.coverage.goToPreviousMissedLine", "testing.coverage.goToPreviousMissedLine"] {
+ let line = workbench.update_in(cx, |workbench, window, cx| {
+ drop(workbench.execute_command(command, Vec::new(), window, cx));
+ workbench.editors.active().expect("the test file").selections[0].head
+ });
+ cursor_lines.push((line.line, line.column));
+ }
+ assert_eq!(cursor_lines, vec![(2, 0), (0, 0), (2, 0), (0, 0)]);
+}
+
/// testing.css `.hc-black .coverage-deco-gutter::before`: in high contrast a covered or missed line number is outlined
/// 3px above and below and 5px on the left, without a fill.
#[gpui::test]
diff --git a/port/ledger.md b/port/ledger.md
index c169af8f028..266b27e6447 100644
--- a/port/ledger.md
+++ b/port/ledger.md
@@ -602,7 +602,7 @@ One row per upstream unit, generated by `bun port/tools/gen-ledger.ts`; mileston
| workbench/contrib/telemetry | workbench contribution | M19 | verified | | the contribution logs to the NullTelemetryService and registers Show Telemetry only when supportsTelemetry, false in the built product: nothing to port; port/tools/telemetry-source-check no endpoint in 18370 shipped files (SELF_TEST finds 9 in the inert packages) |
| workbench/contrib/terminal | workbench contribution | M15 | verified | | workbench/terminal_view.rs, workbench/terminal_decorations.rs, terminal/marks.rs, terminal/serialize_html.rs, terminal/label.rs: cargo test -p app new_with_profile a_ctrl_d_exit_shows_no_exit_alert terminal::marks serialize_html terminal_decorations hover a_recording_keeps_each_kind_of_event toggle_visibility_writes_the_decorations_setting the_cwd_setting_resolves_its_variables terminal::label terminal_view::tests paths_are_quoted call_operator a_tab_row_is_inset_and_its_label_is_one_line_of_text panel_terminals_revive_in_their_groups_after_a_restart a_terminal_editor_revives_with_its_history_after_a_restart; ui-pair OSC 99, decorations, overview ruler, Copy as HTML, Record Terminal Session, terminal tabs (port/results/terminal.md), m12/folder-terminal.json (but the reference's Ports overflow, removed), m11/task-presentation.json (port/results/manage-menu.md) |
| workbench/contrib/terminalContrib | workbench contribution | M15 | verified | | terminal/link_parsing.rs, link_computer.rs, workbench/terminal_links.rs, terminal/auto_replies.rs, terminal/search.rs, workbench/terminal_find.rs, terminal/prompt_input.rs, workbench/terminal_suggest.rs, terminal/history.rs, workbench/terminal_quick_access.rs, terminal/sticky_scroll.rs, workbench/terminal_environment.rs, terminal/osc99.rs, terminal/quick_fix.rs, terminal/accessible_buffer.rs, workbench/terminal_initial_hint.rs: cargo test -p app link_ terminal::search prompt_input auto_replies terminal_contrib terminal_links terminal::history sticky_scroll quick_access environment_collection terminal::marks osc99 quick_fix accessible; ui-pair Run Recent Command, `term `, sticky scroll, the initial hint. No counterpart: Show Terminal Texture Atlas, Restart Pty Host. Removed: Copilot CLI, chat and voice (AI), wslRecommendation (Windows) (port/notes.md milestone 15) |
-| workbench/contrib/testing | workbench contribution | M16 | ported | [3 L] testing_coverage_view.rs: no inline coverage (codeCoverageDecorations.ts `CoverageToolbarWidget`, `testing.toggleInlineCoverage`, the line hover, `testing.coverage.goToNextMissedLine` and `goToPreviousMissedLine`), no Filter Coverage by Test or coverage actions in the editor title (`MenuId.EditorTitle`) | cargo test -p app testing:: testing_filter testing_message_colorizer testing_results:: coverage the_gutter_menu_shows_the_tests_actions_before_the_line_number_items a_line_with_two_tests_shows_run_all_and_a_submenu_per_test reveal_in_test_explorer_expands_the_tests_parents the_run_group_dropdown_lists_its_profiles_and_runs_the_picked_one select_default_profile_stores_the_picked_defaults the_run_group_chevron_keeps_the_view_title_actions_in_the_side_bar runs_from_the_explorer_exclude_the_tests_the_filter_hides a_hidden_test_leaves_the_tree_and_runs_until_it_is_unhidden a_test_row_shows_the_test_item_menu_s_inline_group a_test_rows_context_menu_shows_and_runs_the_test_item_actions children_sort_by_line_then_by_file_name_order the_view_title_dropdown_starts_and_stops_one_profile_of_several continuous_run_using_picks_from_the_tests_controller_only a_continuous_run_holds_one_cancellable_request_per_profile_until_it_stops the_testing_item_spins view_as_list_shows_the_leaves_and_the_more_menu_checks_the_mode peek_error_opens_the_failed_childs_message_at_the_test a_test_run_waits_for_workspace_trust_and_completes_when_it_is_refused a_line_with_more_than_30_tests_picks_the_rest_from_a_quick_pick reveal_in_test_explorer_selects_and_scrolls_to_the_row the_run_group_chevron_is_active_while_its_menu_is_open the_workbench_context_has_the_testing_service_keys; ui-pair port/fixtures/debug-node with tests-provider (Testing tree, Run All, results tree, row menus, opened message, run glyphs and the gutter menu on math.test.js line 2, the run profile dropdown); ui-pair port/fixtures/testing-messages (diff message, markdown message output and selection copy, ANSI message, stack trace and a press in a frame); ui-pair m16/coverage.json |
+| workbench/contrib/testing | workbench contribution | M16 | ported | [3 L] testing_coverage_view.rs: no inline coverage (codeCoverageDecorations.ts `CoverageToolbarWidget`, `testing.toggleInlineCoverage`, the line hover), no Filter Coverage to Test or Toggle Inline Coverage in the editor title (`testing.coverageFilterToTestInEditor`) | cargo test -p app testing:: testing_filter testing_message_colorizer testing_results:: coverage the_gutter_menu_shows_the_tests_actions_before_the_line_number_items a_line_with_two_tests_shows_run_all_and_a_submenu_per_test reveal_in_test_explorer_expands_the_tests_parents the_run_group_dropdown_lists_its_profiles_and_runs_the_picked_one select_default_profile_stores_the_picked_defaults the_run_group_chevron_keeps_the_view_title_actions_in_the_side_bar runs_from_the_explorer_exclude_the_tests_the_filter_hides a_hidden_test_leaves_the_tree_and_runs_until_it_is_unhidden a_test_row_shows_the_test_item_menu_s_inline_group a_test_rows_context_menu_shows_and_runs_the_test_item_actions children_sort_by_line_then_by_file_name_order the_view_title_dropdown_starts_and_stops_one_profile_of_several continuous_run_using_picks_from_the_tests_controller_only a_continuous_run_holds_one_cancellable_request_per_profile_until_it_stops the_testing_item_spins view_as_list_shows_the_leaves_and_the_more_menu_checks_the_mode peek_error_opens_the_failed_childs_message_at_the_test a_test_run_waits_for_workspace_trust_and_completes_when_it_is_refused a_line_with_more_than_30_tests_picks_the_rest_from_a_quick_pick reveal_in_test_explorer_selects_and_scrolls_to_the_row the_run_group_chevron_is_active_while_its_menu_is_open the_workbench_context_has_the_testing_service_keys; ui-pair port/fixtures/debug-node with tests-provider (Testing tree, Run All, results tree, row menus, opened message, run glyphs and the gutter menu on math.test.js line 2, the run profile dropdown); ui-pair port/fixtures/testing-messages (diff message, markdown message output and selection copy, ANSI message, stack trace and a press in a frame); ui-pair m16/coverage.json |
| workbench/contrib/themes | workbench contribution | M9 | verified | | Color Theme picker (`workbench.action.selectTheme`, Cmd+K Cmd+T): rows, order and descriptions as the reference, 200ms preview, Escape restores, accept writes `workbench.colorTheme`; File Icon Theme picker (`workbench.action.selectIconTheme`, Themes submenu): None and the installed themes, preview, Escape restores, accept writes `workbench.iconTheme` (null for None) (cargo test -p app themes); Product Icon Theme picker (`workbench.action.selectProductIconTheme`, Themes submenu): Default and the installed themes, writes `workbench.productIconTheme` (cargo test -p app product_icon; product-icons-pair `picker`: the same rows, except the reference's "Test Product Icon Theme" of vscode-colorize-tests, a test extension the port does not ship); no Marketplace browsing, no `window.autoDetectColorScheme` |
| workbench/contrib/timeline | workbench contribution | M14 | verified | | Timeline view (workbench/timeline_view.rs, timeline.rs): active editor and workspace timelines, paging, follow active editor, excluded sources in profile storage, compare selected, keyboard, `timeline/item/context` and title menus: cargo test -p app timeline; the title toolbar is a tab stop between the pane header and the tree (Shift+Tab focuses its first action with its hover, Left/Right, Enter): cargo test -p app shift_tab_reaches_the_title_toolbar; ui-pair m12/timeline.json header step matches; item labels draw their `$(icon)`s (cargo test -p app an_item_label_draws_its_icons); a `null` `timeline.pageSize` follows the view height (cargo test -p app a_null_page_size_follows_the_view_height) |
| workbench/contrib/typeHierarchy | workbench contribution | M13 | verified | | Peek Type Hierarchy in workbench/hierarchy_peek.rs: supertypes/subtypes toggle, layout `typeHierarchyPeekLayout`, the focused message of an empty answer, `_executePrepareTypeHierarchy`, `_executeProvideSupertypes`, `_executeProvideSubtypes`; cargo test -p app hierarchy; ui-pair port/results/language-features.md (Type hierarchy) |