Visual Studio Code, rebuilt in Rust
Rust
docs(port): plan the architecture deepening and the Zed gate (#45)
Artur Rok5ac6691b03e5
diff --git a/port/ledger.md b/port/ledger.mdindex 4a37e1a2033..83d2600d328 100644--- a/port/ledger.md+++ b/port/ledger.md@@ -46,6 +46,8 @@ 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 | open | 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. | 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 | 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). | || M23 Linux | app/src/webview/linux.rs:370 | open | [linux S] a webview in a Wayland desktop with `WAYLAND_DISPLAY` unset panics ("GTK on X11"): GPUI falls back to X11, GTK still connects to `wayland-0`, and `embedded_window` expects an X11 display. `GDK_BACKEND=x11` avoids it (found in PR #15's NixOS test, the same with the plain archive). GTK has to take the backend GPUI took. | |diff --git a/port/plans/architecture-deepening.md b/port/plans/architecture-deepening.mdnew file mode 100644index 00000000000..82012ac0283--- /dev/null+++ b/port/plans/architecture-deepening.md@@ -0,0 +1,180 @@+# 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"++**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++**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.++**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.++**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.++**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`): port/plans/multi-instance-editor.md 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.++**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.