Skip to content

Visual Studio Code, rebuilt in Rust

Rust

fix(packaging): make the Markdown preview work in the packaged app (#102)

Artur Rokeac3b5e54e9b
diff --git a/native/crates/app/src/workbench/keyboard.rs b/native/crates/app/src/workbench/keyboard.rs
index 51051df95f5..724b6e5c00f 100644
--- a/native/crates/app/src/workbench/keyboard.rs
+++ b/native/crates/app/src/workbench/keyboard.rs
@@ -512,6 +512,8 @@ impl Workbench {
super::welcome_page::WALKTHROUGH_SCHEME => "gettingStartedPage",
super::disassembly_view::DISASSEMBLY_SCHEME => "workbench.debug.disassemblyView",
_ if self.active_notebook_editor().is_some() => "workbench.editor.notebook",
+ // editor.contribution.ts: `TextResourceEditor` shows `UntitledTextEditorInput`.
+ "untitled" => "workbench.editors.textResourceEditor",
// textfiles.ts `TEXT_FILE_EDITOR_ID`.
_ => "workbench.editors.files.textFileEditor",
};
diff --git a/native/crates/app/src/workbench/keyboard/tests.rs b/native/crates/app/src/workbench/keyboard/tests.rs
index 791bd63849f..2be70b8f733 100644
--- a/native/crates/app/src/workbench/keyboard/tests.rs
+++ b/native/crates/app/src/workbench/keyboard/tests.rs
@@ -150,6 +150,18 @@ fn a_focused_text_editor_is_an_input(cx: &mut TestAppContext) {
assert_eq!(input, Some(Value::Bool(true)));
}
+/// editor.contribution.ts: an untitled editor shows in `TextResourceEditor`, so `activeEditor` holds its id and
+/// markdown-language-features' Open as Preview, which asks for the text file editor, stays hidden.
+#[gpui::test]
+fn an_untitled_editor_is_a_text_resource_editor(cx: &mut TestAppContext) {
+ let (workbench, cx, _) = workbench_with(Vec::new(), cx);
+ let active_editor = workbench.update_in(cx, |workbench, window, cx| {
+ drop(workbench.execute_command("workbench.action.files.newUntitledFile", Vec::new(), window, cx));
+ workbench.key_context(window)["activeEditor"].clone()
+ });
+ assert_eq!(active_editor, "workbench.editors.textResourceEditor");
+}
+
/// keybindingService.ts `UserKeybindings`: an edit of keybindings.json made outside the app reaches the file watcher
/// and applies 50 ms later.
#[gpui::test]
diff --git a/port/notes.md b/port/notes.md
index c3e5a43288c..be57123d4c4 100644
--- a/port/notes.md
+++ b/port/notes.md
@@ -817,7 +817,7 @@ Scope as in the M19 Work row of port/ledger.md.
- Update service (`update.rs`, `update/install.rs`, updateService.darwin.ts with Squirrel.Mac's part): one per app, created with the first window; `update.mode` as upstream (`none` disables and drops a pending download, `manual`, `start` 30 s after startup, `default` also hourly). A check first refuses a bundle it cannot replace (App Translocation, a read-only volume, no write access) with Squirrel's message, then reads the feed; a newer build downloads at once with curl into `~/Library/Caches/com.rokartur.vscrs.ShipIt/update` (progress from the file size and Content-Length), then is verified: the zip's SHA-256 against the feed, `ditto -x -k`, exactly one `.app`, `codesign --verify --deep --strict` against the installed app's designated requirement (Squirrel's check: an Apple-issued certificate, the Team ID and the bundle id) and the same `Identifier` and `TeamIdentifier`; an ad-hoc signed installed app verifies nothing. States: Uninitialized, Disabled, Idle, CheckingForUpdates, AvailableForDownload, Downloading, Downloaded, Ready, Restarting; an error goes back to Idle, with its message only for an explicit check (upstream). On a metered connection (`network.meteredConnection` or the OS's) an automatic check is skipped, and an update an automatic check found waits as AvailableForDownload; both resume once the connection is not metered (abstractUpdateService.ts). Not reached: Updating (Windows), Overwriting, Cancelling.
ShipIt (`vscrs --apply-update <pid> <staged> <installed> [--relaunch <args>]`, logging to `ShipIt_stderr.log` in the ShipIt folder): Restart to Update quits every window (a veto puts Ready back) and the helper starts on app quit; a plain Quit while Ready installs too, without relaunch (Squirrel installs a downloaded update on quit). The helper waits for the app's pid to exit, verifies the staged bundle again, renames the installed app to `.Vscrs.app.old`, moves the update in (a ditto copy across volumes) or on any failure puts the old one back, relaunches the executable with the app's arguments, then deletes the old copy.
Workbench (`workbench/update.rs`, update.ts): the Manage menu's `7_update` items by `updateState` (Check for Updates..., Checking for Updates..., Download Update (1), Downloading Update..., Install Update... (1), Restart to Update (1)), the palette's Check for Updates... and Restart to Update, the Manage item's badge (1 with "New Vscrs update available.", a progress badge while checking or downloading, the description in its hover title, the profile badge hidden meanwhile), "There are currently no updates available." in the focused window after an explicit check. The title bar's update entry and its sticky tooltip (`workbench/update_title_bar.rs`, updateTitleBarEntry.ts and updateTooltip.ts, `update.titleBar`) sit before the right-side items of the main window's custom title bar; an explicit check's error shows in the tooltip, not as a notification. After an update to a new major or minor version (`releaseNotes/lastVersion` in application storage, `update.showReleaseNotes`), the release notes editor (`workbench/release_notes.rs`) shows the body of the GitHub release `v<version>` under `releaseNotesUrl` (the API's `/tags/v<version>`); when it cannot be fetched, the prompt "Welcome to Vscrs v{0}! Would you like to read the Release Notes?" opens `releaseNotesUrl`. Tests: `cargo test -p app update::`; end to end `port/tools/update-check` (port/tools/update-feed serves the packages laid out like GitHub releases; `?cut` cuts a download midway).
-- Packaging (`port/tools/package-app`, `port/tools/app-smoke`): Vscrs.app with the release binary and bun in Contents/MacOS, the app files in Contents/Resources/app (the binary takes them as its root when it runs from a bundle; bun next to the executable wins over PATH), pnpm entries copied with their links (a built-in's dependency only when its shipped code requires, `require.resolve`s or imports it: upstream bundles every built-in and ships none, the port runs the unbundled `out`; mermaid-markdown-features' mermaid stack only feeds its prebuilt webviews; ripgrep-universal keeps the target's `bin/darwin-<arch>` only, as build/lib/copilot.ts; the app went from 817 MB to 366 MB, the update zip from 268 MB to 128 MB, VS Code 1.148.0 arm64 is 1.0 GB unpacked), Info.plist with the reference's 65 document types and the `vscrs` URL scheme, every Mach-O signed with the hardened runtime (bun with allow-jit, allow-unsigned-executable-memory, disable-library-validation). The Studio has Gatekeeper assessments disabled, so `spctl -a` accepts any bundle there; package-app refuses to report it as a pass. The app icon is `port/AppIcon.icon` (Icon Composer: one black background, tinted and clear looks from macOS), compiled by actool into Assets.car and AppIcon.icns. Intel Macs (ARCH=x64, built on the arm64 Studio): the `x86_64-apple-darwin` release binary, bun's `bun-darwin-x64-baseline` release of the host's bun version (pinned with its sha256 in package-app; the baseline build runs without AVX2, on Intel Macs before Haswell that macOS 12 supports and under Rosetta before macOS 15), ripgrep's `darwin-x64`, and the native modules the shipped packages load (kerberos, @vscode/spdlog, @vscode/fs-copyfile, all N-API) rebuilt with `node-gyp rebuild --arch=x64` (node-gyp from port/tools/node-gyp's lockfile, installed with `npm ci`) from a scratch copy of their source package. package-app refuses a bundle with a Mach-O of another arch (`lipo -archs` of every file `file` names Mach-O), and as build/.moduleignore drops node-gyp's `build/Release/obj.target` and `.deps` (their object files are Mach-O of the host's arch). Universal builds are not made.
+- Packaging (`port/tools/package-app`, `port/tools/app-smoke`): Vscrs.app with the release binary and bun in Contents/MacOS, the app files in Contents/Resources/app (the binary takes them as its root when it runs from a bundle; bun next to the executable wins over PATH), pnpm entries copied with their links (a built-in's dependency, dev ones included (markdown-language-features loads its devDependency `@vscode/hubrpc`, which upstream's bundle inlines; issue 23), only when its shipped code requires, `require.resolve`s or imports it: upstream bundles every built-in and ships none, the port runs the unbundled `out`; mermaid-markdown-features' mermaid stack only feeds its prebuilt webviews; ripgrep-universal keeps the target's `bin/darwin-<arch>` only, as build/lib/copilot.ts; the app went from 817 MB to 366 MB, the update zip from 268 MB to 128 MB, VS Code 1.148.0 arm64 is 1.0 GB unpacked), Info.plist with the reference's 65 document types and the `vscrs` URL scheme, every Mach-O signed with the hardened runtime (bun with allow-jit, allow-unsigned-executable-memory, disable-library-validation). The Studio has Gatekeeper assessments disabled, so `spctl -a` accepts any bundle there; package-app refuses to report it as a pass. The app icon is `port/AppIcon.icon` (Icon Composer: one black background, tinted and clear looks from macOS), compiled by actool into Assets.car and AppIcon.icns. Intel Macs (ARCH=x64, built on the arm64 Studio): the `x86_64-apple-darwin` release binary, bun's `bun-darwin-x64-baseline` release of the host's bun version (pinned with its sha256 in package-app; the baseline build runs without AVX2, on Intel Macs before Haswell that macOS 12 supports and under Rosetta before macOS 15), ripgrep's `darwin-x64`, and the native modules the shipped packages load (kerberos, @vscode/spdlog, @vscode/fs-copyfile, all N-API) rebuilt with `node-gyp rebuild --arch=x64` (node-gyp from port/tools/node-gyp's lockfile, installed with `npm ci`) from a scratch copy of their source package. package-app refuses a bundle with a Mach-O of another arch (`lipo -archs` of every file `file` names Mach-O), and as build/.moduleignore drops node-gyp's `build/Release/obj.target` and `.deps` (their object files are Mach-O of the host's arch). Universal builds are not made.
- Branding, intended port differences (Artur): (1) Name: every name the user sees is port/product.json's `nameLong`/`nameShort` (Vscrs), read by `product.rs` (app; before `product::load` the overlay alone answers) and `exthost::product_name` (init data `appName`, gallery and install messages). Where upstream hardcodes "VS Code", "Code" or the dev build's "Code - OSS" (install and engine messages, the external website and protocol url prompts, the system-wide keybinding warning, the Editor Playground text, the update commands' `nameShort` category in the reference dump, the built-in walkthroughs' titles, steps and alt texts through `walkthroughs::branded`, the trusted domains and extensions.json templates) the port says Vscrs; links and texts naming Microsoft's docs keep "VS Code", and so does Settings Import, where it names the other app. An unbundled run (`cargo run`) embeds an Info.plist with CFBundleName in `__TEXT,__info_plist` (build.rs), so the app menu names Vscrs there too (the Dock's label keeps the executable name, `vscrs`). `--version` prints upstream's version, commit and arch lines, without a name, as upstream's does. Kept: the Keychain service `Code - OSS Secret Storage` (renaming it loses stored extension secrets) and the gallery's `User-Agent`/`X-Market-Client-Id` (Open VSX compatibility); setting descriptions and built-in extension texts stay upstream's. (2) Icon: `port/AppIcon.icon`, a block cursor slanted like italics with two square eyes, black on an orange background, orange on black in dark mode (it replaced a gradient slash with three code lines on a black background); the bundle gets actool's Assets.car and AppIcon.icns. build.rs renders it, `port/AppIconBars.icon` (three slanted bars indented like lines of code, an amber to violet gradient on a black background) and `port/AppIconBarsCream.icon` (the same bars on a cream background, black in dark mode) with Icon Composer's ictool, light and dark, into the binary. `port/AppIcon.png` (the Linux icon) and `port/assets/icon.png` (the README) are ictool's 512 px Default render of `port/AppIcon.icon` and its 256 px copy. The port setting `window.appIcon` (`default` | `bars` | `barsCream`, config/port-settings.json) picks the Dock icon (`app_icon.rs`, `NSApplication.applicationIconImage`), the light or dark rendering after the system appearance, live; `default` in Vscrs.app restores the bundle's icon, and an unbundled run shows the rendered default. Finder and Launchpad keep the bundle icon. On macOS 27 the About sheet (NSAlert) shows no icon, as Code - OSS's does not (ui-pair, host lane). (3) Letterpress: the empty editor group draws `workbench/letterpress.svg` (the icon's cursor in one fill, its eyes cut out, cropped to the logo) in place of upstream's letterpress-*.svg, at the same size (256 px, 200 px in a part of several groups) and position, black at 0.3 (dark) and 0.1 (light), #3C3C3C (hc dark) and #D9D9D9 (hc light) as upstream's files paint it. Tests: `cargo test -p app product`, `menubar`, `command_palette`; `cargo test -p exthost session extension_validator extension_management`.
- Rename (Artur): the port was VSRustium until 1.148.0.x and is Vscrs (binary, data folder, bundle id, URL protocol and repository `vscrs`). `default_user_data` moves `~/.vsrustium` to `~/.vscrs` once, while `~/.vscrs` does not exist (`main.rs` `user_data_moves_from_vsrustium_once`); a folder's `.vsrustium/` stays read and written, under `.vscrs/` (`config::service::FOLDER_CONFIG_DIRS`, `vsrustium_is_read_and_written_until_vscrs_exists`), without a jsonValidation schema. The bundle id changed with the name, so an installed VSRustium.app cannot verify a Vscrs update (`update/install.rs` checks the `Identifier`): users download the first Vscrs release by hand. Policies set for `com.rokartur.vsrustium` and `vsrustium://` links stop working.
- File > New File... (`workbench/new_file.rs`, newFile.contribution.ts): `MenuId.NewFile` with the built-in Text File and `contributes.menus["file/newFile"]` (ipynb's New Jupyter Notebook), one entry runs directly, more show the picker by group with the source as description, a gear button to the Keyboard Shortcuts editor, and Create New File (name) for typed text.
diff --git a/port/tools/app-files.ts b/port/tools/app-files.ts
index 20e8b1dce2e..8a83f23d44c 100644
--- a/port/tools/app-files.ts
+++ b/port/tools/app-files.ts
@@ -3,6 +3,7 @@
// the shipped built-in extensions (port/tools/shipped-files.ts, with port/patches/extensions-*.patch applied) with the
// packages they and the host resolve, the licenses; and the update feed entries of port/notes.md "Update feed".
import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
+import { isBuiltin } from 'node:module';
import { tmpdir } from 'node:os';
import { basename, dirname, join, relative } from 'node:path';
import { inertPackages, shippedBuiltins } from './shipped-files.ts';
@@ -87,10 +88,12 @@ export async function copyAppFiles(app: string, extensionsDir: string, platform:
cpSync(extension, target, { recursive: true, filter: source => !skipped.test(relative(extension, source)) });
const manifest = JSON.parse(readFileSync(join(extension, 'package.json'), 'utf8'));
// Upstream bundles every built-in and ships no node_modules; the port runs the unbundled `out`, so it ships the
- // dependencies that code loads (mermaid-markdown-features' are inputs of its prebuilt webviews, 300 MB).
+ // dependencies that code loads (mermaid-markdown-features' are inputs of its prebuilt webviews, 300 MB), dev ones
+ // included: the bundle inlines them (markdown-language-features' `@vscode/hubrpc`). A package named as a Node module
+ // (emmet's `util`) never loads.
const code = [...new Bun.Glob('**/*.{js,cjs,mjs}').scanSync(target)].map(file => readFileSync(join(target, file), 'utf8')).join('\n');
const loaded = (name: string) => new RegExp(`(require(\\.resolve)?\\(|import\\(|from )\\s*['"]${name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}['"/]`).test(code);
- for (const [name, path] of copyDependencies(extension, Object.keys({ ...manifest.dependencies, ...manifest.optionalDependencies }).filter(loaded))) {
+ for (const [name, path] of copyDependencies(extension, Object.keys({ ...manifest.dependencies, ...manifest.optionalDependencies, ...manifest.devDependencies }).filter(name => loaded(name) && !isBuiltin(name)))) {
link(path, join(target, 'node_modules', name));
}
}
diff --git a/port/tools/app-smoke b/port/tools/app-smoke
index 4bfb8ed0b59..86505c8bc9a 100755
--- a/port/tools/app-smoke
+++ b/port/tools/app-smoke
@@ -2,7 +2,8 @@
# Starts the packaged Vscrs.app (port/tools/package-app) from outside the checkout on a copy of
# port/fixtures/workspace with notes.txt, without VSCODE_GPUI_EXTENSIONS, so every file comes from the bundle, and
# checks the extension host started from the bundled bun and activated the eager built-ins (vscode.git needs a trusted
-# workspace, so trust is off as in port/tools/linux/smoke); then runs
+# workspace, so trust is off as in port/tools/linux/smoke) and that README.md activates the markdown built-ins
+# (issue 23: the bundle lacked markdown-language-features' devDependency @vscode/hubrpc); then runs
# port/fixtures/extensions/encoding-guess-tests in it with files.autoGuessEncoding on. Run on the Studio.
set -uo pipefail
repo=$PWD
@@ -13,7 +14,7 @@ dir=$(mktemp -d)
cp -R port/fixtures/workspace "$dir/workspace"
mkdir -p "$dir/user-data/User" && echo '{"workbench.startupEditor":"none"}' >"$dir/user-data/User/settings.json"
cd "$dir" || exit 1
-env -u VSCODE_GPUI_EXTENSIONS PATH=/usr/bin:/bin "$APP/Contents/MacOS/vscrs" "$dir/workspace" "$dir/workspace/notes.txt" --user-data-dir "$dir/user-data" --disable-workspace-trust >"$dir/log" 2>&1 &
+env -u VSCODE_GPUI_EXTENSIONS PATH=/usr/bin:/bin "$APP/Contents/MacOS/vscrs" "$dir/workspace" "$dir/workspace/notes.txt" "$dir/workspace/README.md" --user-data-dir "$dir/user-data" --disable-workspace-trust >"$dir/log" 2>&1 &
pid=$!
for _ in $(seq 40); do grep -q "eager extensions activated" "$dir/log" && break; sleep 1; done
sleep 2
@@ -22,6 +23,7 @@ echo "host: $(ps -o comm= -p "$host" 2>/dev/null)"
kill "$pid"; wait "$pid" 2>/dev/null
grep -E "eager extensions activated|failed|error" "$dir/log" | head -5
grep -qE "eager extensions activated: (.*, )?vscode\.git(, |$)" "$dir/log" && code=0 || code=1
+! grep -q "activating .* failed" "$dir/log" || code=1
fixtures=$VSCODE_SRC/src/vs/workbench/services/textfile/test/node/encoding/fixtures
cp "$fixtures/some.shiftjis.txt" "$fixtures/some.cp1252.txt" "$dir/workspace/"