Skip to content

Visual Studio Code, rebuilt in Rust

Rust

fix(testing): resolve only controller roots at publish, as upstream

rokartur32f8b037e585
diff --git a/native/crates/app/src/testing.rs b/native/crates/app/src/testing.rs
index 03d75b00078..e3c0ed1c191 100644
--- a/native/crates/app/src/testing.rs
+++ b/native/crates/app/src/testing.rs
@@ -158,8 +158,8 @@ pub struct TestCollection {
}
impl TestCollection {
- /// `apply` of a published diff; answers the ids the explorer shows expanded at once that can expand: the
- /// roots and their children (index.ts: the top level starts expanded, and a single root shows its children there).
+ /// `apply` of a published diff; answers the controller roots that can expand, which treeProjection.ts `storeItem`
+ /// expands at once (depth 0); deeper items, a single root's children included, resolve only when expanded.
pub fn apply(&mut self, diff: &[Value]) -> Vec<String> {
let mut expandable_roots = Vec::new();
for op in diff {
@@ -172,7 +172,7 @@ impl TestCollection {
Some(parent) => self.children.entry(parent.to_owned()).or_default().push(id.clone()),
None => self.roots.push(id.clone()),
}
- if item.expand == ExpandState::Expandable && parent.is_none_or(|parent| parent_id(parent).is_none()) {
+ if item.expand == ExpandState::Expandable && parent.is_none() {
expandable_roots.push(id.clone());
}
self.items.insert(id, item);
@@ -183,7 +183,7 @@ impl TestCollection {
if !patch["expand"].is_null() {
item.expand = ExpandState::from_value(&patch["expand"]);
// `canResolveChildren` set after the add arrives as an update.
- if item.expand == ExpandState::Expandable && parent_id(&item.id).is_none_or(|parent| parent_id(parent).is_none()) {
+ if item.expand == ExpandState::Expandable && parent_id(&item.id).is_none() {
expandable_roots.push(item.id.clone());
}
}
diff --git a/native/crates/app/src/testing/tests.rs b/native/crates/app/src/testing/tests.rs
index 5fe8fd14c83..b13ba7b207e 100644
--- a/native/crates/app/src/testing/tests.rs
+++ b/native/crates/app/src/testing/tests.rs
@@ -10,10 +10,10 @@ fn add(id: &str, expand: u8) -> Value {
fn diffs_build_the_tree_and_remove_subtrees() {
let mut collection = TestCollection::default();
let roots = collection.apply(&[add("ctrl", 1), add("ctrl\0b", 0), add("ctrl\0a", 1), add("ctrl\0a\0x", 0)]);
- assert_eq!(roots, vec!["ctrl".to_owned(), "ctrl\0a".to_owned()]);
+ assert_eq!(roots, vec!["ctrl".to_owned()], "a single root's resolvable child waits for the explorer to expand it");
assert_eq!(collection.children_of("ctrl"), ["ctrl\0b".to_owned(), "ctrl\0a".to_owned()], "tests at one location keep the extension's order");
- let resolvable = collection.apply(&[json!({ "op": 1, "item": { "extId": "ctrl\0b", "expand": 1, "item": { "label": "renamed" } } })]);
- assert_eq!(resolvable, vec!["ctrl\0b".to_owned()]);
+ let resolvable = collection.apply(&[json!({ "op": 1, "item": { "extId": "ctrl", "expand": 1 } }), json!({ "op": 1, "item": { "extId": "ctrl\0b", "expand": 1, "item": { "label": "renamed" } } })]);
+ assert_eq!(resolvable, vec!["ctrl".to_owned()]);
assert_eq!(collection.items["ctrl\0b"].label(), "renamed");
collection.apply(&[json!({ "op": 3, "itemId": "ctrl\0a" })]);
assert!(!collection.items.contains_key("ctrl\0a\0x"));
diff --git a/native/crates/app/src/workbench/testing_service.rs b/native/crates/app/src/workbench/testing_service.rs
index a21cfdf1158..601da8d2112 100644
--- a/native/crates/app/src/workbench/testing_service.rs
+++ b/native/crates/app/src/workbench/testing_service.rs
@@ -169,7 +169,7 @@ impl Workbench {
"$publishDiff" => {
let diff = arg(1).as_array().cloned().unwrap_or_default();
for root in testing.collection.apply(&diff) {
- // The explorer shows the roots expanded, which resolves their children (treeProjection.ts `expandElement`).
+ // treeProjection.ts `storeItem`: a controller root expands at once, which resolves its children.
self.host.send("ExtHostTesting", "$expandTest", vec![json!(root), json!(0)]);
}
if testing.subscribed {
diff --git a/port/notes.md b/port/notes.md
index d3a24358bfc..78af3234b55 100644
--- a/port/notes.md
+++ b/port/notes.md
@@ -879,6 +879,7 @@ Scope as in the M19 Work row of port/ledger.md.
- Testing (`testing.rs`, `workbench/testing_service.rs`, `testing_view.rs`): MainThreadTesting with the test collection diffs, run profiles, live results (`$runControllerTests`, `$startedExtensionTestRun`, `$applyTestRunUpdates`, `$publishTestResults`), the Testing view (shows once a controller registers), run glyphs in the editor gutter and the Test Results editor. VSBuffer arguments of forwarded requests now reach the workbench as byte arrays (`exthost::session::arg_value`).
- Test Explorer title (testExplorerActions.ts, `testing_view.rs`): the navigation actions end with Show Output (`terminal`, disabled until a result exists); the "..." holds View as List/Tree, Sort by Status/Location/Duration (workspace storage `testing.viewMode` and `testing.viewSorting`, as testingExplorerView.ts) and Collapse All Tests, Clear All Results. Shortcut: View as List lists the tests the collection has resolved; listProjection.ts also asks the controller to resolve every level (`expandElement(root, Infinity)`), which the port does not send.
- Test Results tree (`workbench/testing_results.rs`; testResultsTree.ts `OutputPeekTree`): rows drawn as the workbench tree rows (4px inset, rounded, `list_row_selection`, indent guides, listCommands.ts keys while focused); a new run selects and focuses its first task without taking the focus (`revealItem` with `preserveFocus`). Decision: the task row always shows its twistie when it has children. The reference renders the task row while the task is still childless (`onNewTask`), and abstractTree.ts `renderTreeElement` redraws a twistie only on a collapse state change, so the reference shows no twistie until the row is toggled or rendered again; the port draws the state a fresh render gives.
+- Test resolution timing: treeProjection.ts `storeItem` expands only depth-0 items, the controller roots; a single root's children show on the explorer's top level collapsed (index.ts `getChildrenForParent`, `depth > 0`) and resolve only when the user expands them, and testService.ts `testsInFile` yields an open file's item without expanding it. The port expanded those file items at publish, so the tests-provider fixture's `resolveHandler` ran for every file and Run All ran each test, where the reference's run handler finds the unresolved file item and runs it as one test (`math.test.js` without children in the results). `TestCollection::apply` now answers only the roots.
- Continuous run (`workbench/testing_continuous.rs`): the view title's dropdown of `getContinuousRunDropdown` runs plain actions upstream; the port's context menu runs commands, so each profile item is an internal `_testing.toggleContinuousRunProfile.<controller>.<profile>` command registered when the menu shows. testingExplorerView.ts re-sorts a parent when a continuous run changes, but `TreeSorter` has no continuous run criterion in 1.147.0, so the order does not change; the port draws rows from the run state each frame and needs no re-sort. The unattended restart participant `testing.continuousRun` waits on the unattended restart service (ledger row workbench/services/lifecycle).
- Inline values (`workbench/debug_inline_values.rs`; debugEditorContribution.ts): `debug.inlineValues` `on` or `auto` with a provider shows the focused frame's values as `InjectionOwner::DebugInlineValue` text after the lines, `editor.inlineValuesForeground` on `editor.inlineValuesBackground`. Shortcuts: only the active editor shows them, where upstream decorates every editor on the frame's file; the scopes and variables are fetched again, not shared with the Variables view's cache; the text area width stands in for `layoutInfo.width` in the line length cut.
- Debug hover (`workbench/debug_hover.rs`; debugHover.ts, debugEditorContribution.ts hover handling): while stopped, the expression at the mouse in the focused frame's file (the first `EvaluatableExpressionProvider` through `$provideEvaluatableExpression`, else `getExactExpressionStartAndEnd`) is evaluated with `context: "hover"` (or looked up in the cheap scopes without `supportsEvaluateForHovers`) after the doubled `editor.hover.delay`, the editor hover off meanwhile; Alt swaps it for the editor hover; Cmd+K Cmd+I shows it at the cursor. The focused tree takes listWidget.ts's and abstractTree.ts's keys through the `list.*` commands (Up, Down, Page Up, Page Down, Home, End, Left, Right, Space, Enter, type navigation by name), Escape clears a selection before it hides the widget; `layoutTree` sizes the tree to its rows plus 10px, at most max(266px, 55% of the editor) and the hovered line's top less 22px. The visualizers are a ledger gap of workbench/contrib/debug; the context menu is under Variable menus. The glyph margin lifts the editor hover lockout; the hovered position is the nearer edge of the character under the mouse, a tab's middle included. Lazy rows (`presentationHint.lazy`) draw the `$(eye)` button after the name in the hover, Variables and Watch trees; a lazy watch, hover or REPL result is evaluated at once (debugModel.ts `evaluateExpression` without `keepLazyVars`). A click on an expandable row focuses and toggles it; with Alt the descendants whose children are loaded follow, the others stay collapsed (indexTreeModel.ts `_setNodeCollapseState` recursive, asyncDataTree.ts collapsing a stale node a deep expand reaches). `list.find` (Cmd+Alt+F, F3) on the focused tree opens abstractTree.ts's find widget over 30px of padding: highlight or filter mode and fuzzy or contiguous match by `workbench.list.defaultFindMode` and `defaultFindMatchType` and the widget's toggles, the filter keeps a collapsed parent of a loaded match, "No results found.", the focus to the first match from the focused row; it outlives each shown value like the tree, and Escape hides the hover and runs `list.closeFind` after it. ui-pair on `port/fixtures/debug-node` (Cmd+K Cmd+I on `numbers` and `greeting`) matches the reference's placement, tree indent and focus outline.