Skip to content

Visual Studio Code, rebuilt in Rust

Rust

fix(mergeEditor): complete merge as git's floating button, not the title

rokartur6a77009402a8
diff --git a/README.md b/README.md
index c936d457f15..5217192bf9a 100644
--- a/README.md
+++ b/README.md
@@ -11,8 +11,8 @@ Coverage of VS Code 1.147.0, from [port/ledger.md](port/ledger.md) (585 rows). V
```mermaid
pie showData
- "verified" : 408
- "ported" : 23
+ "verified" : 409
+ "ported" : 22
"removed" : 126
"n/a" : 28
```
@@ -20,7 +20,7 @@ pie showData
| area | verified | ported | removed | n/a | verified of in scope |
|---|---:|---:|---:|---:|---|
| src/vs/platform | 68 | 1 | 30 | 13 | `████████████████████ 99%` |
-| workbench contribution | 58 | 11 | 30 | 3 | `█████████████████░░░ 84%` |
+| workbench contribution | 59 | 10 | 30 | 3 | `█████████████████░░░ 86%` |
| built-in extension | 88 | 1 | 6 | 0 | `████████████████████ 99%` |
| MainThread* shape (Rust side) | 59 | 0 | 30 | 0 | `████████████████████ 100%` |
| workbench service | 59 | 6 | 23 | 7 | `██████████████████░░ 91%` |
@@ -31,7 +31,7 @@ pie showData
| src/vs/editor | 0 | 2 | 1 | 1 | `░░░░░░░░░░░░░░░░░░░░ 0%` |
| src/vs/base | 0 | 0 | 2 | 3 | `████████████████████ 100%` |
| port feature | 1 | 0 | 0 | 0 | `████████████████████ 100%` |
-| **all** | **408** | **23** | **126** | **28** | `███████████████████░ 95%` |
+| **all** | **409** | **22** | **126** | **28** | `███████████████████░ 95%` |
<!-- coverage:end -->
`removed` are parts left out by decision: AI features, Microsoft services, telemetry, remote and tunnels ([port/notes.md](port/notes.md)). `n/a` are upstream test infrastructure and the Electron process, IPC and DOM layers the native architecture replaces.
diff --git a/native/crates/app/src/workbench/editor_view/merge_editor_view.rs b/native/crates/app/src/workbench/editor_view/merge_editor_view.rs
index 89e09b80954..bab2ef4b290 100644
--- a/native/crates/app/src/workbench/editor_view/merge_editor_view.rs
+++ b/native/crates/app/src/workbench/editor_view/merge_editor_view.rs
@@ -656,7 +656,7 @@ impl Workbench {
let message = format!("Do you want to complete the merge of {}?", result.name());
let detail = Some("The file contains unhandled conflicts.".to_string());
if unhandled && !crate::workbench::explorer_actions::confirm(&workbench, cx, gpui::PromptLevel::Info, message, detail, "Complete with Conflicts").await {
- drop(sender.send(Ok(json!(false))));
+ drop(sender.send(Ok(json!({ "successful": false }))));
return;
}
let saved = workbench.update(cx, |workbench, cx| workbench.save_model(result.scheme.clone(), result.path.clone(), crate::workbench::auto_save::SaveReason::Explicit, cx));
@@ -670,7 +670,7 @@ impl Workbench {
drop(workbench.execute_command("workbench.action.closeActiveEditor", vec![json!({ "editorIndex": index })], window, cx));
}
});
- drop(sender.send(closed.map(|_| json!(saved)).map_err(|_| exthost::main_thread::serialized_error("Canceled"))));
+ drop(sender.send(closed.map(|_| json!({ "successful": saved })).map_err(|_| exthost::main_thread::serialized_error("Canceled"))));
})
.detach();
Outcome::Pending(receiver)
@@ -861,8 +861,8 @@ impl Workbench {
.children(detail.map(|detail| label(detail, dim)))
}
- /// resultCodeEditorView.ts title: "Result", the result's path, the remaining conflicts counter, and Complete
- /// Merge (the `MergeToolbar` button).
+ /// resultCodeEditorView.ts title: "Result", the result's path, the remaining conflicts counter and Reset. Complete
+ /// Merge is git's `git.acceptMerge` in the result's `editor/content` floating menu.
fn merge_result_title(&self, merge: &MergeInput, result: &OpenEditor, cx: &mut Context<Self>) -> Div {
let count = merge.model.as_ref().map_or(0, MergeModel::unhandled_count);
let counter = if count == 1 { "1 Conflict Remaining".to_string() } else { format!("{count} Conflicts Remaining") };
@@ -883,19 +883,6 @@ impl Workbench {
)
// `MergeInputResultToolbar`: Reset.
.child(self.merge_toolbar_button("mergeEditor.resetResultToBaseAndAutoMerge", "discard", "Reset Result", cx).flex_none())
- .child(
- div()
- .id("merge-complete")
- .debug_selector(|| "merge-complete".into())
- .flex_none()
- .cursor_pointer()
- .px(px(8.))
- .rounded(px(2.))
- .bg(self.color("button.background"))
- .text_color(self.color("button.foreground"))
- .child("Complete Merge")
- .on_click(cx.listener(|workbench, _, window, cx| drop(workbench.execute_command("mergeEditor.acceptMerge", Vec::new(), window, cx)))),
- )
}
/// resultCodeEditorView.ts `getUriLabel(resultUri, { relative: true })`.
diff --git a/native/crates/app/src/workbench/editor_view/merge_editor_view/tests.rs b/native/crates/app/src/workbench/editor_view/merge_editor_view/tests.rs
index ac033e8c8d4..875e463717e 100644
--- a/native/crates/app/src/workbench/editor_view/merge_editor_view/tests.rs
+++ b/native/crates/app/src/workbench/editor_view/merge_editor_view/tests.rs
@@ -101,7 +101,11 @@ fn open_merge_editor_resets_the_conflict_and_accepts_incoming(cx: &mut TestAppCo
assert_eq!((&context["isMergeEditor"], &context["mergeEditorLayout"], &context["mergeEditorShowBase"]), (&json!(true), &json!("columns"), &json!(true)));
// Complete Merge without unhandled conflicts saves the result and closes the editor.
- run(&workbench, cx, "mergeEditor.acceptMerge", Vec::new());
+ let outcome = workbench.update_in(cx, |workbench, window, cx| workbench.execute_command("mergeEditor.acceptMerge", Vec::new(), window, cx));
+ cx.run_until_parked();
+ let crate::commands::Outcome::Pending(mut receiver) = outcome else { panic!("Complete Merge waits for the save") };
+ // git's `git.acceptMerge` stages the result only on `successful`.
+ assert_eq!(receiver.try_recv().unwrap(), Some(Ok(json!({ "successful": true }))));
assert_eq!(std::fs::read_to_string(dir.join("result.txt")).unwrap(), "one\nTWO current\nthree");
assert!(workbench.read_with(cx, |workbench, _| workbench.editors.editors.is_empty()));
}
@@ -283,7 +287,7 @@ fn a_ranges_block_takes_in_its_action_row(cx: &mut TestAppContext) {
}
/// resultCodeEditorView.ts: the description is the result's workspace-relative path; mergeEditor.css
-/// `.code-view.result > .header > .description`: a long one shrinks, the counter and Complete Merge keep their place.
+/// `.code-view.result > .header > .description`: a long one shrinks, the counter keeps its place.
#[gpui::test]
fn a_long_result_path_is_cut_before_the_conflict_counter(cx: &mut TestAppContext) {
let (dir, workbench, _receiver, cx) = workbench_with_folder("merge-long-path", true, cx);
@@ -296,9 +300,8 @@ fn a_long_result_path_is_cut_before_the_conflict_counter(cx: &mut TestAppContext
let width = cx.update(|window, _| window.viewport_size().width);
let path = cx.debug_bounds("merge-result-path").unwrap();
let counter = cx.debug_bounds("merge-counter").unwrap();
- let complete = cx.debug_bounds("merge-complete").unwrap();
assert!(path.right() <= counter.left(), "the path {path:?} ends before the counter {counter:?}");
- assert!(complete.right() <= width, "Complete Merge {complete:?} stays in the window {width:?}");
+ assert!(counter.right() <= width, "the counter {counter:?} stays in the window {width:?}");
let shown = workbench.read_with(cx, |workbench, _| workbench.merge_result_path(workbench.merge_result().unwrap()));
assert_eq!(shown, format!("{}/result.txt", "a".repeat(200)), "the path is relative to the folder");
std::fs::remove_dir_all(dir).unwrap();
@@ -313,6 +316,35 @@ fn the_merge_editor_shows_the_results_breadcrumbs(cx: &mut TestAppContext) {
std::fs::remove_dir_all(dir).unwrap();
}
+/// extensions/git/package.json `editor/content`: Complete Merge is git's floating button over the result, shown only
+/// while git lists the result in `git.mergeChanges`.
+#[gpui::test]
+fn complete_merge_is_gits_floating_button_over_a_conflicted_result(cx: &mut TestAppContext) {
+ let (dir, workbench, _receiver, cx) = workbench_in("merge-complete", cx);
+ open_with_keybindings(&workbench, &dir, cx);
+ let git = exthost::scan::ScannedExtension {
+ id: "vscode.git".into(),
+ location: dir.clone(),
+ description: json!({ "enabledApiProposals": ["contribEditorContentMenu"], "contributes": {
+ "commands": [{ "command": "git.acceptMerge", "title": "Complete Merge" }],
+ "menus": { "editor/content": [{ "command": "git.acceptMerge", "when": "isMergeResultEditor && mergeEditorBaseUri =~ /^(git|file):/ && mergeEditorResultUri in git.mergeChanges" }] }
+ } }),
+ };
+ workbench.update(cx, |workbench, _| workbench.menus.extend(crate::menus::extension_menus(&[git])));
+ let actions = |cx: &mut VisualTestContext| {
+ workbench.update_in(cx, |workbench, window, _| workbench.floating_menu_actions(workbench.merge_result().unwrap(), window).into_iter().map(|action| action.command).collect::<Vec<_>>())
+ };
+ assert!(actions(cx).is_empty(), "no Complete Merge outside a git merge");
+ assert!(cx.debug_bounds("merge-complete").is_none(), "the result title has no Complete Merge of its own");
+ // git passes `Uri[]`, which reach the workbench marshalled.
+ let mut result = workbench.read_with(cx, |workbench, _| workbench.merge_result().unwrap().document().uri());
+ result["$mid"] = json!(1);
+ run(&workbench, cx, "_setContext", vec![json!("git.mergeChanges"), json!([result])]);
+ assert_eq!(actions(cx), ["git.acceptMerge"]);
+ assert!(cx.debug_bounds("floating-menu").is_some(), "the button draws over the focused result");
+ std::fs::remove_dir_all(dir).unwrap();
+}
+
/// resultCodeEditorView.ts and baseCodeEditorView.ts `decorations`: the result marks its base-to-result diff of the
/// conflicting range; base marks what the last focused input changes and names it in "Comparing with".
#[gpui::test]
diff --git a/native/crates/app/src/workbench/floating_menu.rs b/native/crates/app/src/workbench/floating_menu.rs
index 30ab24defb1..14a257398be 100644
--- a/native/crates/app/src/workbench/floating_menu.rs
+++ b/native/crates/app/src/workbench/floating_menu.rs
@@ -36,6 +36,7 @@ impl Workbench {
let context = self.key_context(window);
let mut widget = div()
.id("floating-menu")
+ .debug_selector(|| "floating-menu".into())
.absolute()
.right(px(2. * VERTICAL_SCROLLBAR_WIDTH + minimap_width))
.top(px(height - widget_height - 2. * HORIZONTAL_SCROLLBAR_HEIGHT))
diff --git a/native/crates/app/src/workbench/keyboard.rs b/native/crates/app/src/workbench/keyboard.rs
index 3abc8e2d053..e64b1950d0f 100644
--- a/native/crates/app/src/workbench/keyboard.rs
+++ b/native/crates/app/src/workbench/keyboard.rs
@@ -659,14 +659,16 @@ impl Workbench {
workbench.open_untitled_with_contents(&crate::keyboard_layout::dump_debug_info_json(), window, cx);
Outcome::done()
});
- self.commands.register("_setContext", |workbench, args, _, _| {
+ self.commands.register("_setContext", |workbench, args, _, cx| {
let mut args = args.into_iter();
let key = match args.next() {
Some(Value::String(key)) => key,
Some(key) => key.to_string(),
None => return Outcome::error("setContext needs a key"),
};
- workbench.context_keys.insert(key, args.next().unwrap_or(Value::Null));
+ workbench.context_keys.insert(key, stringify_uris(args.next().unwrap_or(Value::Null)));
+ // contextKeyService.ts fires `onDidChangeContext`: menus with `when` clauses update.
+ cx.notify();
Outcome::done()
});
// contextKeyService.ts `getContextKeyInfo`: the reference's RawContextKey.all() (port/tools/ref-commands).
@@ -682,6 +684,16 @@ impl Workbench {
}
}
+/// contextKeyService.ts `stringifyURIs`: a context value's URIs become their `toString()`, which `in` compares.
+fn stringify_uris(value: Value) -> Value {
+ match value {
+ Value::Object(uri) if uri.get("$mid") == Some(&json!(1)) => Value::String(crate::debug::uri_string(&Value::Object(uri))),
+ Value::Object(map) => Value::Object(map.into_iter().map(|(key, value)| (key, stringify_uris(value))).collect()),
+ Value::Array(items) => Value::Array(items.into_iter().map(stringify_uris).collect()),
+ other => other,
+ }
+}
+
/// `notificationService.warn(err)` of a failed keybinding command; the caller holds the workbench, so the warning waits a tick.
pub(super) fn report_failure(outcome: Outcome, cx: &mut Context<Workbench>) {
cx.spawn(async move |workbench, cx| {
diff --git a/port/ledger.md b/port/ledger.md
index 034927a899e..f7592ecab1c 100644
--- a/port/ledger.md
+++ b/port/ledger.md
@@ -509,7 +509,7 @@ One row per upstream unit, generated by `bun port/tools/gen-ledger.ts`; mileston
| workbench/contrib/markers | workbench contribution | M13 | verified | | markersTreeViewer.ts `MarkerViewModel`: each marker keeps its quick fixes, asked once, until its resource's markers change (cargo test -p app each_problems_marker_keeps_its_quick_fixes). Indent guides and the focused row's outline apart from the selection (cargo test -p app the_focus_outline_follows). status bar problems entry and tooltip from markers (workbench/diagnostics.rs), its click toggles the Problems view; the Problems panel view (workbench/problems_view.rs: resources by worst severity then path, markers by severity then position, count badges, the tab badge, open on click, Collapse All, `workbench.actions.view.problems` and `toggleProblems`): cargo test -p app problems_view the_debug_console_and_test_results_are_panel_views, ui-pair port/results/problems.md; MarkersFileDecorations (count letter, error/warning color, bubbling, weight over other providers, `problems.decorations.enabled`) on Explorer rows and tabs (workbench/file_decorations.rs): cargo test -p app problems_decorate_the_file; filter box (workbench/view_filter.rs in the panel title at the panel's filter width, markers_filter.rs: markersFilterOptions.test.ts cases; text, `!`, globs, `@source:`, severity, active file and excluded files toggles, filter history, memento), filters menu, related information and multi-line rows, View as Table with column sashes (workbench/problems_table.rs), quick fixes on hovered rows (workbench/problems_quick_fix.rs): cargo test -p app markers_filter problems_view problems_table; ui-pair port/fixtures/problems/steps-filter.json and steps-table.json (port/results/problems.md); the selected row (first marker on focus, Up/Down, Enter and Cmd+Down open, `problems.action.copy`/`copyMessage`/`copyRelatedInformationMessage`, Cmd+. on the selected marker, `problemFocus`/`relatedInformationFocus`): cargo test -p app problems; ui-pair .vscode/settings.json and e.ts quick fix (port/results/language-features.md JSON settings, Problems quick fix). Multi-selection in the tree (`multipleSelectionSupport`: Shift+Up/Down, Cmd+click toggles, Shift+click ranges from the anchor, Copy over `getFocusedSelectedElements`) and open to the side (`problems.action.openToSide` on Ctrl+Enter, Ctrl/Cmd/Alt+click as listService.ts `sideBySide`, into `SIDE_GROUP`): cargo test -p app markers_select_together_and_open_to_the_side. Resource row: name 30px in, count badge 19px round 10px after the label at the line's bottom (cargo test -p app the_resource_name_sits_after_the_twistie_at_its_exact_line_height; ui-pair problems: chevron, icon x, name, description and badge box at the reference's device pixels, the file icon and the badge digit 1 device px low); a hovered marker without a model gets its quick fixes once its file opens (markersTreeViewer.ts `getModel(waitForModel)`; cargo test -p app a_problems_marker_gets_its_quick_fixes_once_its_file_opens) |
| workbench/contrib/mcp | workbench contribution | | removed | | no sign-in/AI by decision (port/notes.md); not ported |
| workbench/contrib/mediaPreview | workbench contribution | M17 | ported | [3 M] media_preview.rs:101, :156: non-file resources; mediaCodecs.ts | An image or media file previewed in another group gets a preview of its own in the active group (mediaPreview.contribution.ts registers without `singlePerResource`: cargo test -p app an_image_previewed_in_another_group_gets_a_preview_in_the_active_one); image, video and audio previews as built-in editors (workbench/media_preview.rs, pages in media_preview/*.html), resolver priority builtin, zoom commands and Select Zoom Level picker, zoom, dimensions and file size status entries, Reopen as Source Text / Image Preview, the file's tab icon and Explorer reveal; `FIXTURE=media-preview-tests port/tools/webview-check` 6/6 on both apps; cargo test -p app media_preview; ui-pair image, video and audio, the breadcrumbs bar with the editor type control and its Reopen/Set Default menu (editor-type-reopen.json; port/results/webviews.md); cargo test -p app lists_the_editor_types; the focus outline at open (ui-pair media-preview-focus.json, background and foreground); cargo test -p app opens_a_startup_image. Not done: codec probing (mediaCodecs.ts), Copy image, legacy `media-preview` editor migration |
-| workbench/contrib/mergeEditor | workbench contribution | M14 | ported | [3 M] merge_editor_view.rs:896: the result title always draws a Complete Merge button; the reference has none there, git's `git.acceptMerge` shows it in the result's `editor/content` floating menu only while `mergeEditorResultUri in git.mergeChanges` | merge_editor.rs model (mapping, conflict states, accept/combine) and workbench/editor_view/merge_editor_view.rs (input 1/2, result, base view, layouts, gutter checkboxes behind `mergeEditor.showCheckboxes`, base-to-result diff backgrounds, "Comparing with" in base, the result's breadcrumbs, `_open.mergeEditor`, dev commands, the inputs as read-only code editors of the group, Toggle Between Inputs, the active range in the last focused input or the result, scroll synchronization): cargo test -p app merge |
+| workbench/contrib/mergeEditor | workbench contribution | M14 | verified | | merge_editor.rs model (mapping, conflict states, accept/combine) and workbench/editor_view/merge_editor_view.rs (input 1/2, result, base view, layouts, gutter checkboxes behind `mergeEditor.showCheckboxes`, base-to-result diff backgrounds, "Comparing with" in base, the result's breadcrumbs, git's Complete Merge in the result's floating menu, `_open.mergeEditor`, dev commands, the inputs as read-only code editors of the group, Toggle Between Inputs, the active range in the last focused input or the result, scroll synchronization): cargo test -p app merge |
| workbench/contrib/meteredConnection | workbench contribution | M19 | verified | | the metered warning status entry and Configure Metered Connection (workbench/power.rs); port/tools/shell-check (port/fixtures/extensions/shell-tests, 6/6); cargo test -p app metered_connection |
| workbench/contrib/modernUI | workbench contribution | M11 | verified | | the modern layout only: the classic layout (`workbench.experimental.modernUI: false`) is removed by Artur's decision (port/notes.md Modern UI); `window.density.layout` compact and the Manage menu's Layout Density (cargo test -p app -- compact_density layout_density; ui-pair m11/layout-density.json in both densities with SETTINGS `{"window.density.layout": "compact"}`, port/results/layout-density.md) |
| workbench/contrib/multiDiffEditor | workbench contribution | M14 | verified | | multi_diff_editor.rs and workbench/editor_view/multi_diff_editor_view.rs: `_workbench.openMultiDiffEditor`, SCM group (following the group's splices, each kept file with its state) and history item sources, Open File with the history item's `goToFileEditorTitle`, file toolbar, change navigation, collapse, binary placeholder, unchanged bars that click or drag with the line below kept in place and the hidden range's outline breadcrumbs (cargo test -p app unchanged_bars_drag), the layout debug log in the side group with a JSON patch line per change, the file list's Files View & Position sides, its sash with the stored width and hiding below 560px, View as List/Tree with the diffs in the list's order, each file's 35px diff gutter with Revert Block, the diff editor's line number lane, the `noCards` variant, first change selected and focused on open: cargo test -p app multi_diff. Each file side is its own code editor (workbench/code_editors.rs): a press focuses it, the modified side takes typing, undo, selection, IME, find and suggest, the host gets the file's edit, the edit recomputes the file's diff and makes the tab dirty and pinned, the dirty file opens as an inactive tab after 800ms (textFileEditorTracker.ts), the focused side's cursor blinks, every drawn side has its own color decorators, bracket pair colors come from the model: cargo test -p app a_file_side_is_a_code_editor every_drawn_file_side; ui-pair `steps-multi-diff-edit.json` (typed, undone, find) matches but for the reference's TypeScript diagnostics (port/notes.md, Comments in diff editors) |