Visual Studio Code, rebuilt in Rust
Rust
fix(workbench): send the replace source when the last match is replaced (#80)
Artur Rok42523f1a3782
diff --git a/native/crates/app/src/workbench/find_widget.rs b/native/crates/app/src/workbench/find_widget.rsindex 8ca50a8142e..9ccaa4fb0d6 100644--- a/native/crates/app/src/workbench/find_widget.rs+++ b/native/crates/app/src/workbench/find_widget.rs@@ -325,9 +325,10 @@ impl Workbench {let scrolled = self.animate_scroll_from(scroll, cx) || self.editors.viewport.top_whitespace != top_whitespace;self.find.version_id = self.editors.active().expect("checked above").text_model().version_id;self.find.ignore_own_change = true;- // findModel.ts: replace all leaves its command's selection; a replace moves on to the next match by `setSelection`.+ // findModel.ts: replace all leaves its command's selection; a replace moves on to the next match by `setSelection` while one is left.let source = match change.as_ref().map(|change| super::model_events::edit_source(&change.reason)) {Some("replaceAll") => "replaceAll",+ Some("replace") if self.find.controller.state.matches_count == 0 => "replace",_ => "api",};self.model_content_changed(change, crate::workbench::model_events::Cursor { moved, source, reveal: crate::editor::Reveal::Nothing }, cx);diff --git a/native/crates/app/src/workbench/model_events/tests.rs b/native/crates/app/src/workbench/model_events/tests.rsindex 3dcf463f97d..36978a33c8e 100644--- a/native/crates/app/src/workbench/model_events/tests.rs+++ b/native/crates/app/src/workbench/model_events/tests.rs@@ -153,11 +153,22 @@ enum EditPath {BulkEditOfAnotherGroup,BulkEditOfAModelWithoutEditor,ReplaceAll,+ ReplaceTheLastMatch,HostEdit,SaveParticipant,Revert,}+fn find_a_to_replace_with_x(workbench: &gpui::Entity<Workbench>, cx: &mut VisualTestContext) {+ run(workbench, "actions.find", vec![], cx);+ workbench.update(cx, |workbench, _| {+ let viewport = workbench.editors.viewport;+ let editor = workbench.editors.active_mut().unwrap();+ let new = crate::editor::find::state::NewFindState { search_string: Some("a".into()), replace_string: Some("x".into()), ..Default::default() };+ workbench.find.controller.change(editor, viewport, new, false);+ });+}+fn insert_at_start(file: &Path, text: &str) -> Value {json!([{ "resource": file_uri(file), "textEdit": { "range": { "startLineNumber": 1, "startColumn": 1, "endLineNumber": 1, "endColumn": 1 }, "text": text } }])}@@ -176,6 +187,7 @@ fn every_path_of_an_edit_tells_the_host_first_and_wakes_the_shown_editor(cx: &mu(EditPath::BulkEditOfAnotherGroup, false, None),(EditPath::BulkEditOfAModelWithoutEditor, false, None),(EditPath::ReplaceAll, true, Some("replaceAll")),+ (EditPath::ReplaceTheLastMatch, true, Some("replace")),(EditPath::HostEdit, true, Some("MainThreadTextEditor")),(EditPath::SaveParticipant, true, Some("insertFinalNewLine")),(EditPath::Revert, true, Some("modelChange")),@@ -193,6 +205,13 @@ fn every_path_of_an_edit_tells_the_host_first_and_wakes_the_shown_editor(cx: &mumatch path {EditPath::Undo => run(&workbench, "type", vec![json!({ "text": "x" })], cx),EditPath::Revert => std::fs::write(&a, "ab").unwrap(),+ // findModel.ts `replace`: the first run selects the only match, the second replaces it. The code lens+ // answer comes first: asked after a find selection, the edit asks no lenses again (port/notes.md).+ EditPath::ReplaceTheLastMatch => {+ answer(&receiver, cx);+ find_a_to_replace_with_x(&workbench, cx);+ run(&workbench, "editor.action.replaceOne", vec![], cx);+ }EditPath::BulkEditOfAnotherGroup => {run(&workbench, "workbench.action.splitEditor", vec![], cx);workbench.update_in(cx, |workbench, window, cx| workbench.open_file(dir.join("b.ts"), true, window, cx));@@ -208,15 +227,10 @@ fn every_path_of_an_edit_tells_the_host_first_and_wakes_the_shown_editor(cx: &muEditPath::BulkEditOfTheActiveEditor | EditPath::BulkEditOfAnotherGroup => drop(workbench.update(cx, edit_a)),EditPath::BulkEditOfAModelWithoutEditor => drop(workbench.update(cx, |workbench, cx| workbench.apply_workspace_text_edits(&insert_at_start(&dir.join("b.ts"), "x"), &json!([]), files::operations::new_undo_group(), None, cx).unwrap())),EditPath::ReplaceAll => {- run(&workbench, "actions.find", vec![], cx);- workbench.update(cx, |workbench, _| {- let viewport = workbench.editors.viewport;- let editor = workbench.editors.active_mut().unwrap();- let new = crate::editor::find::state::NewFindState { search_string: Some("a".into()), replace_string: Some("x".into()), ..Default::default() };- workbench.find.controller.change(editor, viewport, new, false);- });+ find_a_to_replace_with_x(&workbench, cx);run(&workbench, "editor.action.replaceAll", vec![], cx);}+ EditPath::ReplaceTheLastMatch => run(&workbench, "editor.action.replaceOne", vec![], cx),EditPath::HostEdit => {let edits = json!([{ "range": { "startLineNumber": 1, "startColumn": 1, "endLineNumber": 1, "endColumn": 1 }, "text": "x" }]);let version = workbench.read_with(cx, |workbench, _| workbench.editors.active().unwrap().text_model().version_id);diff --git a/port/ledger.md b/port/ledger.mdindex 6c334af1a73..2fec567c3ff 100644--- a/port/ledger.md+++ b/port/ledger.md@@ -46,7 +46,7 @@ Status: `open`, `in progress`, `waiting on Artur`, `later` (postponed), `done`,| Milestones | M24 Windows build | in progress | Branch `worktree-m24-windows`, beside milestone 23 on the same seams: macOS and Linux code stays as it is, each Windows counterpart sits behind `cfg(target_os = "windows")` in the function where it is a few lines, in a `windows.rs` beside `macos.rs` and `linux.rs` where it is not. Scope: WebView2, the Win32 file dialogs and message boxes, the in-window menu bar and custom title bar, Credential Manager (keyring), named pipes for the extension host and single instance, ConPTY for the terminal (terminal/pty/conpty.rs, the VT backend libghostty-vt is platform-neutral), drive-letter paths and file URIs, the user-setup install path with `bin` on the user PATH (code.iss `addtopath`), `%APPDATA%\Code` settings import, an x64 and arm64 zip and a user installer, no Authenticode signing (the Windows signing decision). Cross build on the Studio (cargo-xwin, `x86_64-pc-windows-msvc` and `aarch64-pc-windows-msvc`) for compile checks and host-run unit tests; real runs on GitHub Actions `windows` runners (`.github/workflows/windows.yml`, by hand). Seams: the "M24 Windows" rows. | `cargo build --release -p app` and the area tests pass on win32-x64 and win32-arm64 runners; the app opens a folder, edits, saves, runs an extension (the exthost handshake, emmet and git activate) and shows a webview on the runner; `v1.147.0-insider` carries `VSRustium-win32-x64-1.147.0-insider.zip`, `VSRustium-win32-arm64-1.147.0-insider.zip` and both user setups; the macOS and Linux builds are unchanged (their area tests as before). || Milestones | M25 virtual workspaces | later | Artur: its own milestone after M20, not part of the gap audits. A folder of a non-file scheme (`.code-workspace` `uri` folders, `--folder-uri`, `vscode.openFolder` with an extension file system provider scheme) kept as a URI; every reader of workspace folders (173 `.folders` uses in 70 files: explorer, search, quick open, terminal cwd, tasks, git, watcher, settings layers, trust) goes through the file system providers; the workspace marked virtual, `virtualWorkspaces: false` extensions disabled with the `notSupportedInWorkspace` message (config/workspace.rs:101, port/notes.md provider entries deferred until virtual workspaces). | not started || Milestones | M26 GPUI on gpui-fast | done | Artur, 2026-12-01: the port's GPUI moved from Wu (dstrml/wu a3ced28) to gpui-fast (longbridge/gpui-fast f0a91cf952678e4d205da1ec189b6d134e975bcd, base zed a36d485, vendored in `native/vendor/gpui-fast`), a Zed GPUI fork whose Retained Mode redraws only the views that changed; `native/vendor/wu` is deleted. Reason, risks, sync, the gate's results and the open gaps (outer shadow clip, Linux `super-q`): port/notes.md "GPUI on gpui-fast". | All area tests and `port/tools/api-tests` green; `cargo test -p app corner_lab` within today's thresholds; a Retained Mode on/off differential test without differences; GUI: open a folder, edit, save, an extension (exthost handshake, emmet, git), a webview, a long list scroll, the terminal; `port/tools/bench` not worse than Wu in any column; `bun port/tools/ledger-check.ts` passes. Results: port/notes.md "GPUI on gpui-fast", "M26 gate". |-| Milestones | M27 architecture deepening | done | Artur, 2026-12-02: the six candidates of the architecture review, one per session and worktree, in the order 4, 1, 3, 5, 6, 2: one answer to who serves a MainThread call, one announcement of a model content change, one extension host start per window, editor options as a module, language feature registrations decoded once, one pass over the editors of every group (the swap of `with_group` stays, the multi-instance code editor builds on it). Every candidate is pixel-neutral and keeps the invariants of ARCHITECTURE.md; performance is M28. Plan, evidence and the picked interfaces of candidates 4 and 1: port/plans/architecture-deepening.md. Done: 4, 1, 3, 5, 6, 2 (port/notes.md "Architecture deepening"). Pixel-neutral, measured once over the six from `f4d6aabdf09` to the last candidate (port/notes.md "Architecture deepening"): `port/tools/pixel-check` gives identical port images in 36 of 40 window and theme pairs, the 4 `panel` ones differing only in the checkout path the terminal prompt prints; `port/tools/ui-pair` with ONLY=port over steps-params-actions, steps-color and steps-ghost gives identical images. Open from 6: the `$provide*` calls stay built by each feature (83 `"ExtHostLanguageFeatures"` sites), not in the language features module as the plan's goal says; its "Done when" holds. Open from 5: the editor options are read under the settings lock on every call, not once per settings change (the settings service has no change counter to key a cache on; the typing and scroll gates did not move); `language_setting`, `suggest_setting`, `editor_bool_setting` and the raw `get_value` reads of word wrap, folding, paste and comments still hold their own defaults outside `workbench/editor_options.rs`. | Each candidate's "Done when" of port/plans/architecture-deepening.md holds; `port/tools/pixel-check` and the area's `port/tools/ui-pair` steps show no difference from the commit before each candidate; `bun port/tools/ledger-check.ts` passes. |+| Milestones | M27 architecture deepening | done | Artur, 2026-12-02: the six candidates of the architecture review, one per session and worktree, in the order 4, 1, 3, 5, 6, 2: one answer to who serves a MainThread call, one announcement of a model content change, one extension host start per window, editor options as a module, language feature registrations decoded once, one pass over the editors of every group (the swap of `with_group` stays, the multi-instance code editor builds on it). Every candidate is pixel-neutral and keeps the invariants of ARCHITECTURE.md; performance is M28. Plan, evidence and the picked interfaces of candidates 4 and 1: port/plans/architecture-deepening.md, removed after the milestone, in `git show 4fc0cf39e4e:port/plans/architecture-deepening.md`. Done: 4, 1, 3, 5, 6, 2 (port/notes.md "Architecture deepening"). Pixel-neutral, measured once over the six from `f4d6aabdf09` to the last candidate (port/notes.md "Architecture deepening"): `port/tools/pixel-check` gives identical port images in 36 of 40 window and theme pairs, the 4 `panel` ones differing only in the checkout path the terminal prompt prints; `port/tools/ui-pair` with ONLY=port over steps-params-actions, steps-color and steps-ghost gives identical images. Open from 6: the `$provide*` calls stay built by each feature (83 `"ExtHostLanguageFeatures"` sites), not in the language features module as the plan's goal says; its "Done when" holds. Open from 5: the editor options are read under the settings lock on every call, not once per settings change (the settings service has no change counter to key a cache on; the typing and scroll gates did not move); `language_setting`, `suggest_setting`, `editor_bool_setting` and the raw `get_value` reads of word wrap, folding, paste and comments still hold their own defaults outside `workbench/editor_options.rs`. | Each candidate's "Done when" of the plan holds; `port/tools/pixel-check` and the area's `port/tools/ui-pair` steps show no difference from the commit before each candidate; `bun port/tools/ledger-check.ts` passes. || Milestones | M28 Zed gate | open | Artur, 2026-12-02: the port is not behind Zed in any metric of `port/tools/bench`, time and memory. Its own track, apart from M27. Behind today (README.md, port/results/benchmark.md): peak footprint and peak RSS. The plan follows a memory profile of the peak footprint. | `port/tools/bench > run.tsv && bun port/tools/bench-check.ts run.tsv vsrustium zed` prints no `BEHIND` on a quiet machine (the run's load under `max_load` of port/budgets.json). || M23 Linux | app/src/webview/linux.rs:66 | done | [linux L] webviews through WebKitGTK: webview panels and views, editor insets, notebook outputs, extension details, release notes. | `FIXTURE=webview-tests port/tools/linux/smoke` on X11 (Xvfb): 10/10 ok; `cargo gc test -p app webview` on Linux: 19 passed || M23 Linux | app/src/webview/linux.rs:47 | open | [linux L] webviews in a Wayland session. Linux shows now: no webview under Wayland: GPUI has no X window there to hold the GTK window, so `supported()` is false and each webview surface stays empty. Needs a route that does not embed: GTK opens its own Wayland connection, and a `wl_subsurface` cannot take a surface of another client, so the reparenting X11 uses has no Wayland form; WPE WebKit rendering offscreen into a GPUI texture, with input forwarded, is the route left (not started). | |diff --git a/port/notes.md b/port/notes.mdindex f069151739b..ef9ba2faa66 100644--- a/port/notes.md+++ b/port/notes.md@@ -1174,7 +1174,7 @@ Work the port does at another time than 1.147.0, accepted with a measured same r| 6c3b7094c6f | fix(gpui): shrink the background behind an opaque rounded border | quads | no | `style.rs`, `fast/layers/paint.rs` | 2, 0 || 2a560ca76e0 | build(port): vendor wu's gpui and gpui_apple through [patch] | vendor | | | |-## Architecture deepening (milestone 27, port/plans/architecture-deepening.md)+## Architecture deepening (milestone 27)- Candidate 4, one answer to who serves a MainThread call (branch refactor/m27-host-call-paths): the forward list of `app/src/main.rs::run_extension_host`, `HOST_REQUESTS`, `Workbench::host_request`, the session's `OBSERVED` and the `_ => Outcome::done()` defaults became one private match, `app/src/main_thread_commands.rs::route`, that gives each call its `exthost::main_thread::Path` (`Blocking`, `Forwarded`, `Observed`) and its handler. `Session::forward` takes its projection `path` as a `fn` pointer, so a forward never queues behind the `MainThread` object `Session::serve` has taken out. A call the table does not name stays with the session (`Session::serve`), as before.- Finding, fixed test first: `MainThreadLanguageFeatures` was forwarded as a whole proxy and the pump checked the forward list before `Session::serve`, so `$resolvePasteFileData` and `$resolveDocumentOnDropFileData` (mainThreadLanguageFeatures.ts) answered null instead of the file's bytes. Now `Blocking`: the workbench names the file, the session thread reads it (cargo test -p app resolve_paste_file_data).@@ -1182,7 +1182,8 @@ Work the port does at another time than 1.147.0, accepted with a measured same r- `$trySaveDocument` keeps its blocking path, but its handler returns `Outcome::Pending`; the blocking loop of `app/src/workbench/extension_host_restart.rs` awaits it.- Candidate 1, one announcement of a model content change (branch refactor/m27-model-content-changed): `ContentChanged` names its model and every edit and cursor move goes through `app/src/workbench/model_events.rs::Workbench::model_content_changed` or `cursor_position_changed`, which send `$acceptModelChanged` and the shown editor's selection before any listener runs. `editor_edited`, `editor_edited_revealing`, `cursors_changed`, `send_model_edit` and `HostSync::send_content_change` are gone; `app/src/workbench/model_events/tests.rs::every_path_of_an_edit_tells_the_host_first_and_wakes_the_shown_editor` makes one edit by each of 10 paths.- Skips closed test first (model_events/tests.rs): a bulk, host or save participant edit of the shown model now asks code lens, inlay hints and colors again (codelensController.ts, inlayHintsController.ts, colorDetector.ts); a cursor move wakes code actions, parameter hints and linked editing (codeActionModel.ts, parameterHintsModel.ts, linkedEditing.ts); a click in the output view locks its scroll (outputView.ts `onDidChangeCursorPosition`, reason `Explicit`). The selection after an edit takes the cursor's source instead of a fixed `keyboard` (cursor.ts `onModelContentChanged` sends `modelChange`).-- Selection source of an edit through the editor (branch refactor/m27-selection-source): codeEditorWidget.ts `executeEdits` and `executeCommands` pass one string as both the cursor event's `source` and the edit reason's `detailedSource`, so `model_events.rs::edit_source` reads it back from `EditReason` (undo, redo and an EOL change: `modelChange`). `editor_command_ran` sends it, so `deleteRight` sends its id and undo `modelChange`; Replace All sends `replaceAll` (findModel.ts `_executeEditorCommand`), a replace keeps `api` for its move to the next match; of the save participants only `insertFinalNewLine` edits through the editor (saveParticipants.ts `FinalNewLineParticipant`). The listeners that read the source follow upstream: suggestModel.ts keeps a session for `keyboard` and `deleteLeft`, inlineCompletionsController.ts starts on typing and its `triggerCommands` (`tab`, `deleteLeft`, `deleteRight`, the insert line actions), so the other edit commands (word deletes, line operations) no longer start inline completions. Test: `every_path_of_an_edit_tells_the_host_first_and_wakes_the_shown_editor`.+- Selection source of an edit through the editor (branch refactor/m27-selection-source): codeEditorWidget.ts `executeEdits` and `executeCommands` pass one string as both the cursor event's `source` and the edit reason's `detailedSource`, so `model_events.rs::edit_source` reads it back from `EditReason` (undo, redo and an EOL change: `modelChange`). `editor_command_ran` sends it, so `deleteRight` sends its id and undo `modelChange`; Replace All sends `replaceAll` (findModel.ts `_executeEditorCommand`), a replace keeps `api` for its move to the next match, and sends `replace` when it replaced the last one (`research(true)` finds none to move to); of the save participants only `insertFinalNewLine` edits through the editor (saveParticipants.ts `FinalNewLineParticipant`). The listeners that read the source follow upstream: suggestModel.ts keeps a session for `keyboard` and `deleteLeft`, inlineCompletionsController.ts starts on typing and its `triggerCommands` (`tab`, `deleteLeft`, `deleteRight`, the insert line actions), so the other edit commands (word deletes, line operations) no longer start inline completions. Test: `every_path_of_an_edit_tells_the_host_first_and_wakes_the_shown_editor`.+- Finding, not traced: when the find selection moves the cursor before the first `$provideCodeLenses` is answered, the next edit asks no code lenses (`code_lens_content_changed` returns early without groups or a pending request is the suspect); the replace test answers first to stay off it.- Trap: with one announcement, the find widget's own Replace All reached `find_editor_edited` and reset its match position; `ignore_own_change` skips it as findModel.ts `_ignoreModelContentChanged` does. Language detection lost its own `edited` channel and runs from the model listeners.- Candidate 3, one extension host start per window (branch refactor/m27-host-start): `app/src/extension_host_start.rs`. Three interfaces, on one axis, where the start reads the window state the host needs (extensions, settings, storage, trust, workspace, runtime, user data): (a) from the caller, one free function over a 16-field struct both callers fill; (b) from a `HostStarter` object the workbench keeps, holding the channels and the process kind; (c) from the `Workbench` itself, `Workbench::spawn_extension_host(HostStart, HostLaunch, development)`, with only what `open_window` alone knows (`HostLaunch`: the process and `--user-data-dir`) stored once on the workbench. Picked (c): (a) leaves both callers gathering the same list, the place the copies drifted; (b) is a class beside state the workbench already owns. `HostStart::new` makes the channels and queues the color theme and language ids before `Workbench::new`, which takes the `HostSync`.- The seam has two adapters, `HostProcess::Runtime` (Bun, or Node with `--node`) and, in tests, `HostProcess::Silent` over `ExtensionHost::silent`, which hands the test the init data and its end of the socket. The restart's `cfg!(test)` return is gone: a test's `Workbench` has no `host_launch` and only counts the start; `app/src/workbench/extension_host_restart/tests.rs::a_host_restart_starts_the_host_as_the_window_did` sets one and checks the host the restart opens.diff --git a/port/plans/architecture-deepening.md b/port/plans/architecture-deepening.mddeleted file mode 100644index 02803f7e2f9..00000000000--- a/port/plans/architecture-deepening.md+++ /dev/null@@ -1,192 +0,0 @@-# Architecture deepening--Ledger task: the "M27 architecture deepening" row of port/ledger.md's Work table. Source: the architecture review of 2026-12-02 (six candidates, ranked). Vocabulary is the codebase-design skill's: module, interface, depth, seam, adapter, leverage, locality.--Every count below is `rg` over `native/crates/app/src` without `tests.rs` files, measured on 2026-12-02 at `7a01ac58b2c`. Paths start at a crate of `native/crates`.--## Rules for every candidate--- One candidate per session, in its own worktree, in this order: 4, 1, 3, 5, 6, 2. The order goes from the smallest change to the widest.-- Pixel-neutral: `port/tools/pixel-check` and the `port/tools/ui-pair` steps of the touched area show no difference from the commit before.-- Performance is its own track (M28). A candidate that touches a hot path reports its gate of docs/performance.md before and after.-- The invariants of ARCHITECTURE.md stay: the Workbench is the only owner of window state, a model does not call the workbench, user-visible behaviour goes through `app/src/commands.rs::execute_command`, the message order to the host is fixed, the main thread never waits for another process.-- A candidate that finds a difference from upstream fixes it test first, with the upstream file cited in the test. A difference it does not fix becomes a gap in the ledger.-- Tests that call the interface survive unchanged. A test that reaches into what the candidate hides is rewritten at the interface, not deleted.-- Candidates 4 and 1 have their interface picked below from three variants. Candidates 3, 5, 6 and 2 start their session with three variants that differ on one named axis.--## 4. One answer to "who serves this MainThread call"--**Status.** Done on branch `refactor/m27-host-call-paths`: `app/src/main_thread_commands.rs::route`; findings in port/notes.md, "Architecture deepening".--**Evidence.** Five places decide the path of a call, and they must agree by hand:--- `app/src/main.rs::run_extension_host`: a list of 42 strings (`"MainThreadFoo"` or `"MainThreadFoo.$bar"`) handed to `exthost/src/session.rs::Session::forward`.-- `app/src/workbench/host_requests.rs::HOST_REQUESTS`: 33 pairs the session thread blocks on, and `Workbench::host_request` with two `unreachable!` arms.-- `app/src/main_thread.rs::WorkbenchMainThread::handle`: arms that need `&mut Session`, plus a `HOST_REQUESTS.contains` guard.-- `app/src/main_thread_commands.rs::handle_host_request`: 64 arms, ending in `_ => Outcome::done()`. The same silent default is in 4 files, 5 times.-- `exthost/src/session.rs`: the guarded arms of the pump and the `OBSERVED` list.--The lists already disagree. `"MainThreadLanguageFeatures"` is forwarded as a whole proxy, and the pump checks the forward list before `Session::serve`. So `$resolvePasteFileData` and `$resolveDocumentOnDropFileData` never reach their arm in `WorkbenchMainThread::handle` or their `HOST_REQUESTS` pairs: they fall to the silent default and answer null. Found by reading; the session starts by proving it with a test that sends the call through a `Session`.--**Variants** (axis: what holds the membership of a path).--| Variant | Membership lives in | Cost | Left over |-|---|---|---|---|-| A, one table | One private `match (proxy, method)` in `app/src/main_thread_commands.rs` that gives the path and the handler | About 100 arms rewrapped | `WorkbenchMainThread::handle` keeps its `&mut Session` arms |-| B, one module per upstream class | `enum Method` per `mainThread<Class>.ts`, exhaustive `route` and `handle` | About 45 new files, `port/tools/gen-proxy-ids.ts` emits method names | Nothing; a new upstream class does not compile until placed |-| C, forwarded unless claimed | A `claims(proxy, method)` predicate on the session side; everything else is forwarded | The 42 strings go; one predicate | `HOST_REQUESTS` stays, and `claims` repeats the session's own match |--**Pick: A.** It is the only variant where the path and the handler are one value, so the two threads cannot disagree, at a cost that fits one session. B gives a compile-time guarantee the next uplift wants; revisit it then, on top of A's table. C is the smallest diff but keeps two lists.--```rust-// exthost/src/main_thread.rs-pub enum Path {- Blocking, // the session thread waits in MainThread::handle- Forwarded, // sent on as ForwardedRequest, answered by Session::reply- Observed, // the session answers; the workbench gets a copy-}-pub type PathOf = fn(proxy: &str, method: &str) -> Option<Path>; // None: the session's own--// exthost/src/session.rs: the string list becomes the function-pub fn forward(&mut self, path_of: PathOf, send: impl FnMut(ForwardedRequest) + Send + 'static, replies: Receiver<(u32, Result<Value, Value>)>);--// app/src/main_thread_commands.rs-pub fn path(proxy: &str, method: &str) -> Option<Path>; // pure, any thread-impl Workbench {- pub fn handle_host_request(&mut self, request: ForwardedRequest, window: &mut Window, cx: &mut Context<Self>) -> Outcome;-}-```--`path` and `handle_host_request` read the same private match. `PathOf` is a `fn` pointer, not a trait method, because `Session::serve` takes the `MainThread` object out while it is busy and a forward must not queue behind it. The order of messages does not change: the session's guarded arms run first, a forwarded call leaves the pump in arrival order, a blocking call queues behind a busy handler, `flush` precedes the reply.--**Steps.**--1. The failing test for `$resolvePasteFileData` through a `Session`.-2. An inventory of what reaches the silent defaults today: `SessionLog::host_calls` over `port/tools/api-tests` and `port/tools/extension-tests`. Each deliberate `undefined` becomes an explicit arm with its ledger gap. Without this, unported methods start to reject and extensions see errors upstream never gives.-3. The table, then the error: a call with no arm answers `Unknown method $bar on actor MainThreadFoo` (rpcProtocol.ts `_doInvokeHandler`).-4. Delete the 42 strings, `HOST_REQUESTS`, `Workbench::host_request`, `OBSERVED` and both `unreachable!`.--**Tests that survive.** The 9 test files that call `handle_host_request`. The 3 that call `host_request` change to build a `ForwardedRequest`.--**Done when.** `rg 'HOST_REQUESTS|_ => Outcome::done\(\)|unreachable!' app/src/main_thread.rs app/src/main_thread_commands.rs app/src/workbench/host_requests.rs` finds nothing; `rg -c '"MainThread' app/src/main.rs` is 0 inside `run_extension_host`; the test of step 1 passes; `port/tools/api-tests` and `port/tools/extension-tests` give the counts of the commit before.--## 1. One announcement of a model content change--**Status.** Done on branch `refactor/m27-model-content-changed`: `app/src/workbench/model_events.rs`; findings in port/notes.md, "Architecture deepening"; the selection sources still off upstream are a gap of the `mainthread/MainThreadTextEditors` ledger row.--**Evidence.** A model is edited at 42 `.execute_edits(` sites in 26 files. What happens next depends on which of four functions the site calls: `.editor_edited(` or `.editor_edited_revealing(` (20 sites in 13 files), `.send_model_edit(` (11 in 9), `.cursors_changed(` (11 in 6), `.editor_command_ran(` (10 in 1). Four more sites tell the host by hand (`host.send_content_change(` or `host.send_model_change(`: 7 sites in 6 files), and `host.send_selection(` has 23 sites in 18 files. Each function runs a different list of reactions.--Skips three independent readings agreed on (read, not run):--- `send_model_edit` (bulk edits, host edits, save participants) wakes no code lens, inlay hints, colors or links. `host_requests.rs::apply_model_edits` patches links by hand.-- `cursors_changed` wakes no code actions, parameter hints, linked editing, inline completions or snippet state.-- `output_cursor_moved` runs only from `cursors_changed`, so an edit that moves the cursor skips it.--Not skips: find, folding, outline, quick diff, auto save and backup catch up per frame in `Workbench::render`.--**Variants** (axis: what the caller hands over).--| Variant | The caller hands over | Types | Cost at call sites |-|---|---|---|---|-| A, the change | The `ContentChanged` it got, which names its model, and how the cursor moved | 1 struct | 46 sites change mechanically |-| B, two tiers | An entry per tier (model, active editor) with event values after `textModelEvents.ts` and `cursorEvents.ts` | 5 types | 16 sites, old functions kept as forwards |-| C, the edit itself | A closure that edits; the module snapshots selections and announces | 1 enum, 1 struct | 24 `execute_edits` sites move into closures that cannot touch `self` |--**Pick: A, with B's two private lists and C's first step.** A is the smallest interface a caller cannot get wrong: there is no choice of function left. C hides the most but its closure cannot reach `self`, which `color_picker.rs` and `linked_editing.rs` need. B's five types have few readers today.--```rust-// editor/edit.rs: the change names its model-pub struct ContentChanged { pub model: SharedModel, /* fields as today */ }--// workbench/model_events.rs (new)-pub(super) struct Cursor<'a> {- pub before: Option<&'a [Selection]>, // None: only the edit moved them- pub source: &'a str, // "keyboard", "mouse", "api", "modelChange", ...- pub reveal: Reveal,-}-impl Workbench {- /// onDidChangeModelContent of the change's model, then onDidChangeCursorPosition when the active code editor shows it.- pub(super) fn model_content_changed(&mut self, change: Option<ContentChanged>, cursor: Cursor, cx: &mut Context<Self>);- /// onDidChangeCursorPosition of the active code editor.- pub(super) fn cursor_position_changed(&mut self, cursor: Cursor, cx: &mut Context<Self>);-}-```--Inside, two flat private lists, one line per feature: reactions to any model (host change, dirty state and tabs, search, language detection, semantic tokens, cell status bar) and reactions of the active code editor (selection and visible ranges to the host, code lens, inlay hints, colors, links, snippet, suggest, parameter hints, code actions, linked editing, inline completions, format on type). The host gets `$acceptModelChanged` before any reaction runs, so every provider request follows the edit. No token type guards the host sends; the check below does.--**Steps.**--1. The old four functions call the two lists. No call site changes. Each closed skip gets a failing test first that cites the upstream listener; a skip upstream also has stays out of the list.-2. Convert the call sites, `editor_edited*` and `send_model_edit` first, the 23 direct `host.send_selection` sites last: each of those starts to wake cursor reactions.-3. Delete `editor_edited`, `editor_edited_revealing`, `cursors_changed`, `send_model_edit` and `HostSync::send_content_change`.--**Open.** `HostSync::send_content_change` sends the selection with source `"keyboard"` for every edit. Step 1 keeps that on the wire; step 2 compares it with upstream per path.--**Tests that survive.** Every feature test that types or runs a command through the `Workbench`. New: one table test that makes the same one-character edit by each path (type, command, undo, bulk edit to the active editor, to another group, to a model with no editor, replace all, host edit, save participant, revert) and compares the host messages and the reactions woken.--**Done when.** `rg 'host\.send_(model|content)_change\(' app/src/workbench -g '!model_events.rs' -g '!**/tests.rs'` finds nothing; the four old functions are gone; the table test passes; `app/src/syntax.rs::typing_latency_on_a_large_file` reports p95 before and after, under 16 ms.--## 3. One extension host start per window--**Evidence.** `app/src/main.rs::open_window` and `app/src/workbench/extension_host_restart.rs::start_extension_host` each choose the extensions, build the channels and inboxes, the `WorkbenchMainThread`, the `HostSync` with theme and languages, spawn the thread and run the status loop. Both end in `app/src/main.rs::run_extension_host`, which takes 16 arguments. The restart copy returns at once under `cfg!(test)`, so no test covers the wiring. A sub-agent reported the copies have drifted (the restart reads the runtime again from `std::env::args()` and derives `user_data` from the settings path); the session confirms that first.--**Goal.** One module builds everything a host needs for a window; the first start and the restart call it. Its seam has two adapters: the Bun or Node process, and `ExtensionHost::silent`.--**Tests that survive.** `extension_host_restart` tests at the `Workbench`. New: restart sends the host the same opening sequence as the first start.--**Status.** Done on branch `refactor/m27-host-start`: `app/src/extension_host_start.rs`; variants, pick and findings in port/notes.md, "Architecture deepening".--**Done when.** `rg -c 'run_extension_host\(' app/src` is one call; `rg 'cfg!\(test\)' app/src/workbench/extension_host_restart.rs` finds nothing in the start path; the new test passes; `window_s` and `ready_s` of `port/tools/bench` stay within budget.--## 5. Editor options as a module--**Evidence.** `self.setting("editor.` appears 76 times in 35 files. Each site knows the key, the default (`.unwrap_or(200)`), the validation (`!= json!(false)`) and whether the `[lang]` override applies. Upstream holds all of that in editorOptions.ts. In `workbench/editor_view.rs::editor_lines`, `editor.guides.indentation` takes the language override and `editor.renderWhitespace` does not, and the function reads settings under the lock several times per frame.--**Goal.** One module answers "this option, for this editor": default, validation, language override, read once per settings change.--**Tests that survive.** The settings tests of each feature. New: tests per option at the module (default, invalid value, `[lang]`), against editorOptions.ts.--**Status.** Done on branch `refactor/m27-editor-options`: `app/src/workbench/editor_options.rs`; variants, pick and findings in port/notes.md, "Architecture deepening". Still open, in the M27 ledger row: the read once per settings change, and the global reads without `[lang]` (a gap of the editor/common row).--**Done when.** `rg 'self\.setting\("editor\.' app/src -g '!**/tests.rs'` finds matches only in the module; `app/src/workbench/scroll_frame_time.rs` and the typing gate report before and after.--## 6. Language feature registrations decoded once--**Evidence.** `app/src/language_features.rs::Registration` carries `pub args: Vec<Value>`, the wire tuple. `"ExtHostLanguageFeatures"` appears 83 times in 27 files and there are 30 positional reads (`registration.args[2]`, `.args.get(3)`) in 16 files of `app/src/workbench`. Each feature decodes `$register*` by position and builds its own `$provide*` call; upstream keeps both in mainThreadLanguageFeatures.ts. `LanguageFeatures::ordered` and `score` are deep and stay.--**Goal.** One module knows the shape of each `$register*` and `$provide*`: named fields in, a call out.--**Status.** Done on branch `refactor/m27-language-registrations`: `app/src/language_features.rs::Registration::decode`; variants, pick and findings in port/notes.md, "Architecture deepening". Still open, in the M27 ledger row: the `$provide*` calls stay built by each feature.--**Done when.** `rg 'registration\.args(\[|\.get\()|\.args\.get\(\d\)' app/src/workbench -g '!**/tests.rs'` finds nothing; `port/tools/api-tests` gives the counts of the commit before.--## 2. One pass over the editors of every group--**Decided.** The swap stays (`with_group`, 45 sites in 21 files; `activate_group`, 51 in 22; `with_code_editor`): the multi-instance code editor (port/ledger.md, M20) builds on it. This candidate removes only the traversals that differ in reach without saying so.--**Evidence.** Four traversals exist: `editors.editors`, `EditorGroup::code_editors`, `EditorGroup::all_editors` and `EditorGroup::model`. The pattern `editors.editors.iter().chain(&editors.models)` visits the active group and the models without an editor, and skips the editors of every other group. It caused a data loss bug: a dirty file in an inactive group got no backup and no auto save (fixed on branch `fix/backup-inactive-groups`, tests `in_another_group`).--The check of "Done when" below finds 38 sites in 24 files (5 of them fixed by that branch). Each is a suspect until a test says otherwise. The ones read so far:--| Site | If the file is in another group |-|---|---|-| `workbench/configuration.rs::update_model_options` | A changed `editor.tabSize` does not reach its model |-| `workbench/text_files.rs::text_files_editors_changed` | Its stat, orphan mark and preferred language are dropped |-| `workbench/text_files.rs::files_associations_changed` | Its language does not follow `files.associations` |-| `workbench/coverage_decorations.rs::sync_inline_coverage`, `workbench/inline_breakpoints.rs`, `workbench/breakpoint_widget.rs::sync_stack_frame_columns` | No inline coverage, inline breakpoints or stack frame column |-| `workbench/debug_view.rs` (2 sites) | A breakpoint in a dirty file shows as verified |-| `workbench/host_requests.rs::try_open_document` | The first-opened casing of the path is not found |-| `workbench/hierarchy_peek.rs::api_prepare_hierarchy` | `Illegal argument` for an open document |-| `workbench/problems_quick_fix.rs`, `workbench/goto_definition_link.rs`, `workbench/peek_view.rs` (2 sites), `workbench/suggest_controller.rs` | A lookup misses the open model: no quick fix, a preview read from disk, word completions without its words |--**Goal.** Two named traversals, each with its reach in the name: the tabs of the active group, and every open editor and model. `&mut` included, which `all_editors` lacks today.--**Status.** Done on branch `refactor/m27-group-editors`: `app/src/editor.rs::EditorGroup::all_tabs` and `all_editors`, each with a `_mut`; every row of the table above and the other suspects closed test first (27 tests with the file in another group); variants, pick, the sites kept on the active group and findings in port/notes.md, "Architecture deepening". Still open, in the M27 ledger row: the quick diff widget's close.--**Done when.** `rg -U 'editors\s*\.editors\s*\.iter(_mut)?\(\)\s*\.chain\(' app/src -g '!**/tests.rs' -g '!editor.rs'` finds nothing; each row of the table has a test with the file in another group, or a line here on why upstream skips it too.--## Not in this plan--- M28, the Zed gate: `bun port/tools/bench-check.ts run.tsv vsrustium zed` prints no `BEHIND` on a quiet machine. Its plan follows a memory profile of the peak footprint.-- Lower in the queue, each speculative until measured: one decoration store for the text area, overview ruler and minimap; the reach of a redraw (`cx.notify()`); the context key helpers of a focused list; the shape of `HostMessage`; cleanup of host registrations on restart; `OpenEditor` as tab, view state and model handle at once.-- The current-group fields read through the swap (`editors.viewport` and the like): decided to stay, see candidate 2.