Skip to content

Visual Studio Code, rebuilt in Rust

Rust

feat(testing): show coverage bars on Explorer rows

rokartur02a9174f0d69
diff --git a/native/crates/app/src/testing_coverage.rs b/native/crates/app/src/testing_coverage.rs
index a73aa235c2c..0f013fd7936 100644
--- a/native/crates/app/src/testing_coverage.rs
+++ b/native/crates/app/src/testing_coverage.rs
@@ -52,7 +52,6 @@ impl CoverageUri {
CoverageUri { scheme: text("scheme"), authority: text("authority"), path: text("path") }
}
- #[cfg(test)]
pub fn file(path: &str) -> Self {
CoverageUri { scheme: "file".into(), authority: String::new(), path: path.to_owned() }
}
diff --git a/native/crates/app/src/workbench.rs b/native/crates/app/src/workbench.rs
index c94c5e88696..ec142b1963e 100644
--- a/native/crates/app/src/workbench.rs
+++ b/native/crates/app/src/workbench.rs
@@ -1896,6 +1896,11 @@ impl Workbench {
let decoration = self.file_decoration(&path, is_dir);
let decoration_color = self.decoration_color(decoration.as_ref(), self.setting("explorer.decorations.colors") != Value::Bool(false));
let badge = self.decoration_badge(decoration.as_ref(), foreground).filter(|_| self.setting("explorer.decorations.badges") != Value::Bool(false));
+ // The decoration color is the label's, not the bars' beside it.
+ let bars_color = selection_foreground.filter(|_| is_selected).unwrap_or(foreground);
+ let coverage_bars = self.explorer_coverage_bars(&path).map(|bars| bars.text_color(bars_color));
+ // testing.css `.explorer-item-with-test-coverage .monaco-icon-label::after`: 12px between the badge and the bars.
+ let badge = badge.map(|badge| if coverage_bars.is_some() { badge.mr(px(12.)) } else { badge });
let has_nests = row.has_nests;
let (twistie_path, row_expanded) = (path.clone(), row.expanded);
let twistie_element = |chevron| {
@@ -1947,6 +1952,7 @@ impl Workbench {
}
})
.children(badge)
+ .children(coverage_bars)
.when_some(decoration_color, |row, color| row.text_color(color))
// explorerviewlet.css: .explorer-item.cut is at half opacity. Its 0.3 for the other rows while a name is
// edited needs `.explorer-folders-view` twice in the ancestry, which the reference DOM never has.
diff --git a/native/crates/app/src/workbench/testing_coverage_view.rs b/native/crates/app/src/workbench/testing_coverage_view.rs
index ffab52193ef..38d5958f2d5 100644
--- a/native/crates/app/src/workbench/testing_coverage_view.rs
+++ b/native/crates/app/src/workbench/testing_coverage_view.rs
@@ -96,6 +96,12 @@ impl Workbench {
workbench.pick_coverage_sort_order(window, cx);
Outcome::done()
});
+ self.commands.register("testing.toggleCoverageInExplorer", |workbench, _, _, cx| {
+ let shown = workbench.setting("testing.showCoverageInExplorer") != false;
+ workbench.update_setting("testing.showCoverageInExplorer", json!(!shown));
+ cx.notify();
+ 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 {
@@ -402,13 +408,13 @@ impl Workbench {
true => self.icon("check", 16., 16., foreground),
false => self.icon("circle-outline", 16., 16., self.color("testing.iconUnset")),
};
- let bars = declaration.attributable.map(|(statement, branch)| self.coverage_bars(statement, Some(branch), None));
+ let bars = declaration.attributable.map(|(statement, branch)| self.coverage_bars(statement, Some(branch), None, false));
let location = declaration.detail.location;
let end = if declaration.detail.position { location.start } else { location.end };
let selection = json!({ "startLineNumber": location.start.line, "startColumn": location.start.column, "endLineNumber": end.line, "endColumn": end.column });
(Some(icon), bars, json!({ "selection": selection, "selectionRevealType": 3 }))
}
- None => (None, (file.kind != crate::testing_coverage::CoverageKind::Bypassed).then(|| self.coverage_bars(file.statement, file.branch, file.declaration)), Value::Null),
+ None => (None, (file.kind != crate::testing_coverage::CoverageKind::Bypassed).then(|| self.coverage_bars(file.statement, file.branch, file.declaration, false)), Value::Null),
};
let open = (!row.folder).then(|| file.uri.clone());
element.child(twistie).children(icon).child(label).children(bars).on_click(cx.listener(move |workbench, _: &ClickEvent, window, cx| {
@@ -423,19 +429,35 @@ impl Workbench {
}))
}
- /// testCoverageBars.ts `ManagedTestCoverageBars` without `compact`: the displayed percent at precision 2, then the
- /// statement, function and branch bars (testing.css `.test-coverage-bars`).
- fn coverage_bars(&self, statement: CoverageCount, branch: Option<CoverageCount>, declaration: Option<CoverageCount>) -> Div {
+ /// testCoverageBars.ts `ManagedTestCoverageBars`: the displayed percent at precision 2, then the statement, function
+ /// and branch bars, or `compact` at precision 0 and one bar of the percent (testing.css `.test-coverage-bars`).
+ fn coverage_bars(&self, statement: CoverageCount, branch: Option<CoverageCount>, declaration: Option<CoverageCount>, compact: bool) -> Div {
let thresholds = self.setting("testing.coverageBarThresholds");
let method = self.setting("testing.displayedCoveragePercent");
- let overall = display_percent(displayed_stat(statement, branch, declaration, method.as_str().unwrap_or("totalCoverage")), 2);
- let mut bars = div().flex().flex_none().items_center().gap(px(4.)).text_size(px(11.)).mr(px(12.)).child(overall);
+ let overall_stat = displayed_stat(statement, branch, declaration, method.as_str().unwrap_or("totalCoverage"));
+ let overall = display_percent(overall_stat, if compact { 0 } else { 2 });
+ let selector = format!("test-coverage-bars:{overall}");
+ let mut bars = div().flex().flex_none().items_center().gap(px(4.)).text_size(px(11.)).mr(px(12.)).debug_selector(move || selector).child(overall);
+ if compact {
+ return bars.child(self.coverage_bar(overall_stat, false, &thresholds));
+ }
for count in [Some(statement), declaration, branch].into_iter().flatten() {
bars = bars.child(self.coverage_bar(count.percent(), count.total == 0, &thresholds));
}
bars
}
+ /// `ExplorerTestCoverageBars`: an Explorer row's compact bars while coverage is open and
+ /// `testing.showCoverageInExplorer` is on.
+ pub(super) fn explorer_coverage_bars(&self, path: &std::path::Path) -> Option<Div> {
+ if self.setting("testing.showCoverageInExplorer") == false {
+ return None;
+ }
+ let (_, _, coverage) = self.selected_coverage()?;
+ let file = coverage.computed_for_uri(&CoverageUri::file(&path.to_string_lossy()))?;
+ Some(self.coverage_bars(file.statement, file.branch, file.declaration, true))
+ }
+
/// `renderBar`: 16px wide, filled to the floored percent, in the threshold's chart color or half the foreground
/// at a zero total.
fn coverage_bar(&self, percent: f64, zero: bool, thresholds: &Value) -> Div {
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 9f58410d1e6..e2bb320b029 100644
--- a/native/crates/app/src/workbench/testing_coverage_view/tests.rs
+++ b/native/crates/app/src/workbench/testing_coverage_view/tests.rs
@@ -259,3 +259,54 @@ fn an_expanded_file_lists_its_declarations(cx: &mut TestAppContext) {
assert_eq!(rows.2, ["a.js", "alpha", "outer", "inner"]);
assert_eq!(rows.3, ["a.js", "outer", "inner", "alpha"]);
}
+
+/// testCoverageBars.ts `ExplorerTestCoverageBars`: while coverage is open each Explorer row of a file or folder with
+/// coverage shows its compact bars, until Toggle Coverage in Explorer turns `testing.showCoverageInExplorer` off.
+#[gpui::test]
+fn explorer_rows_show_their_coverage(cx: &mut TestAppContext) {
+ let app_root = std::path::Path::new(env!("VSCODE_SRC")).to_path_buf();
+ let theme = crate::theme::load_theme(&[exthost::scan::scan_extension(&app_root.join("extensions/theme-defaults"), true).unwrap()], "Dark Modern").unwrap();
+ let dir = std::env::temp_dir().join(format!("vsrustium-explorer-coverage-{}", std::process::id()));
+ let _ = std::fs::remove_dir_all(&dir);
+ std::fs::create_dir_all(dir.join("src")).unwrap();
+ std::fs::write(dir.join("src/a.js"), "").unwrap();
+ std::fs::write(dir.join("b.js"), "").unwrap();
+ let dir = dir.canonicalize().unwrap();
+ let (sender, _host) = std::sync::mpsc::channel();
+ let folder = config::workspace::Workspace::folder(dir.clone());
+ let user = std::env::temp_dir().join(format!("vsrustium-explorer-coverage-user-{}", std::process::id()));
+ let settings = std::sync::Arc::new(std::sync::Mutex::new(config::service::Settings::load(config::registry::Registry::with_extensions(&[]), user.clone(), None)));
+ let (workbench, cx) = cx.add_window_view(|_, cx| Workbench::new(theme, app_root, Some(folder), crate::languages::Languages::new(&[]), settings, crate::host_sync::HostSync::new(sender), cx));
+ let draw = |cx: &mut gpui::VisualTestContext| {
+ cx.update(|window, cx| drop(window.draw(cx)));
+ cx.run_until_parked();
+ };
+ workbench.update_in(cx, |workbench, window, cx| {
+ drop(workbench.execute_command("workbench.view.explorer", Vec::new(), window, cx));
+ let mut result = TestResult::new("r1".into(), json!({ "group": 2, "targets": [] }));
+ result.add_task(&json!({ "id": "t1", "name": "Task A", "ctrlId": "c", "running": false }));
+ workbench.testing.results = vec![result];
+ for (id, path, covered, total) in [("f1", "src/a.js", 1, 2), ("f2", "b.js", 1, 4)] {
+ let path = dir.join(path).to_string_lossy().into_owned();
+ drop(workbench.handle_testing_request(request("$appendCoverage", vec![json!("r1"), json!("t1"), file_coverage(id, &path, covered, total)]), window, cx));
+ }
+ });
+ draw(cx);
+ assert!(cx.debug_bounds("test-coverage-bars:50%").is_none(), "nothing before coverage opens");
+ workbench.update(cx, |workbench, cx| {
+ workbench.open_coverage("r1", 0, false, cx);
+ cx.notify();
+ });
+ draw(cx);
+ assert!(cx.debug_bounds("test-coverage-bars:50%").is_some(), "the src folder's computed coverage");
+ assert!(cx.debug_bounds("test-coverage-bars:25%").is_some(), "b.js");
+ let shown = workbench.update_in(cx, |workbench, window, cx| {
+ drop(workbench.execute_command("testing.toggleCoverageInExplorer", Vec::new(), window, cx));
+ workbench.setting("testing.showCoverageInExplorer")
+ });
+ assert_eq!(shown, false);
+ draw(cx);
+ assert!(cx.debug_bounds("test-coverage-bars:25%").is_none(), "hidden by the setting");
+ std::fs::remove_dir_all(dir).unwrap();
+ std::fs::remove_dir_all(user).unwrap();
+}
diff --git a/port/ledger.md b/port/ledger.md
index cd65892275a..c38c9d53028 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`), no percent in the Explorer (`testing.showCoverageInExplorer`), no minimap or overview ruler marks (`testing.coverageMinimapEnabled`) | 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, `testing.coverage.goToNextMissedLine` and `goToPreviousMissedLine`), no Filter Coverage by Test or coverage actions in the editor title (`MenuId.EditorTitle`), no minimap or overview ruler marks (`testing.coverageMinimapEnabled`) | 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) |