Visual Studio Code, rebuilt in Rust
Rust
#!/bin/bash
# Pixel check: reference capture (CDP) against the port's Metal readback, per window and theme. Run from the repo root on the Studio.
# Windows: "empty" (no folder), "folder" (port/fixtures/workspace, copied outside the repo so git sees no repository)
# "file" (the folder with notes.txt open), "main" (the folder with src/main.ts open, for token colors), "multiroot"
# (a .code-workspace file with the folder and a copy of its docs folder as roots) and "folded"
# (port/fixtures/folding with long.py open, scrolled to the end and two regions folded by typing KEYS) and "find"
# (notes.txt with the find widget open on "the") and "quickopen" (notes.txt with Quick Open's file list). "chord" (the
# file window with Cmd+K pressed: the status bar's chord message) and "titlebar" (the file window with
# `window.commandCenter` off: the window title instead, 32px high on macOS 26) are not in the default list. "split"
# (notes.txt split into a second group with Cmd+\) and "panel" (the split, then Cmd+J opens the panel's Terminal).
# "git" (the folder as a git repository with notes.txt changed and an untracked file, for git's file decorations)
# is not in the default list.
# WINDOWS="file" checks only the listed windows, THEMES="dark hclight" only the listed themes; the themes of the other
# built-in theme extensions are abyss kimbie monokai dimmed quiet red sdark slight tnb, not in the default list.
# Prints "window theme different anti_aliased total"; images land in $OUT/<window>.
set -uo pipefail
OUT=${OUT:-/tmp/pixel-check-$(basename "$PWD")}
mkdir -p "$OUT"
rm -rf "$OUT/workspace" "$OUT/workspace2" "$OUT/folding" && cp -R port/fixtures/workspace "$OUT/workspace" && cp -R port/fixtures/workspace/docs "$OUT/workspace2" && cp -R port/fixtures/folding "$OUT/folding"
echo '{ "folders": [{ "path": "workspace" }, { "path": "workspace2", "name": "Second Folder" }] }' >"$OUT/multi.code-workspace"
(cd native && cargo gc build --release -q -p app --features screenshot && cargo gc build --release -q -p pixeldiff) || exit 1
source port/tools/gui-lock.sh
# GPUI takes hover from the real pointer on the first frame; the reference window gets no mouse move.
echo 'import CoreGraphics; CGWarpMouseCursorPosition(.zero)' | swift - || exit 1
# Runs a capture; one still alive after 120 s gets its stacks sampled into $1, then is killed (exit 124).
capture() {
local sample=$1; shift
"$@" & local pid=$!
for _ in $(seq 120); do
kill -0 $pid 2>/dev/null || { wait $pid; return; }
sleep 1
done
sample $pid 3 -file "$sample" >/dev/null 2>&1
kill $pid; wait $pid; return 124
}
for window in ${WINDOWS:-empty folder file main multiroot folded find quickopen split panel}; do
case $window in empty) folder= ;; multiroot) folder=$OUT/multi.code-workspace ;; git) folder=$OUT/gitspace ;; *) folder=$OUT/workspace ;; esac
keys= settings=
case $window in
file) file=$OUT/workspace/notes.txt ;;
find) file=$OUT/workspace/notes.txt keys="cmd-f t h e" ;;
split) file=$OUT/workspace/notes.txt keys='cmd-\' ;;
panel) file=$OUT/workspace/notes.txt keys='cmd-\ cmd-j' ;;
quickopen) file=$OUT/workspace/notes.txt keys="cmd-p" ;;
chord) file=$OUT/workspace/notes.txt keys="cmd-k" ;;
titlebar) file=$OUT/workspace/notes.txt settings='{ "window.commandCenter": false }' ;;
main) file=$OUT/workspace/src/main.ts ;;
git)
rm -rf "$OUT/gitspace" && cp -R port/fixtures/workspace "$OUT/gitspace"
(cd "$OUT/gitspace" && git init -q && git add . && git -c user.name=port -c user.email=port@localhost commit -qm fixture && echo changed >>notes.txt && echo new >untracked.txt)
file=$OUT/gitspace/notes.txt ;;
folded) folder=$OUT/folding file=$OUT/folding/long.py keys="cmd-down up alt-cmd-[ up up up up up up up up up up up up alt-cmd-[" ;;
*) file= ;;
esac
dir="$OUT/$window"
mkdir -p "$dir"
FOLDER=$folder FILE=$file KEYS=$keys SETTINGS=$settings bun port/tools/ref-screenshot "$dir/reference" ${THEMES:-} >/dev/null || exit 1
for theme in ${THEMES:-dark light hc hclight}; do
case $theme in dark) theme_id="Dark Modern" ;; light) theme_id="Light Modern" ;; hc) theme_id="Default High Contrast" ;; hclight) theme_id="Default High Contrast Light" ;;
abyss) theme_id=Abyss ;; kimbie) theme_id="Kimbie Dark" ;; monokai) theme_id=Monokai ;; dimmed) theme_id="Monokai Dimmed" ;;
quiet) theme_id="Quiet Light" ;; red) theme_id=Red ;; sdark) theme_id="Solarized Dark" ;; slight) theme_id="Solarized Light" ;;
tnb) theme_id="Tomorrow Night Blue" ;;
esac
user_data=$(mktemp -d)
# No Welcome page and no watermark shortcuts, as ref-user-data.ts freezes the reference.
port_settings='{"workbench.startupEditor":"none","workbench.tips.enabled":false}'
[[ -n $settings ]] && port_settings="{\"workbench.startupEditor\":\"none\",\"workbench.tips.enabled\":false,${settings#\{}"
mkdir -p "$user_data/User" && echo "$port_settings" >"$user_data/User/settings.json"
VSCODE_GPUI_EXTENSIONS=${VSCODE_GPUI_EXTENSIONS:-$HOME/Developer/vscode-ref-1.148.0/extensions} \
capture "$dir/port-$theme.sample" native/target/release/vsrustium $folder $file --user-data-dir "$user_data" --disable-workspace-trust --theme "$theme_id" --screenshot "$dir/port-$theme.png" --screenshot-keys "$keys" 2>"$dir/port-$theme.log" || { echo "$window $theme: code-gpui failed with exit $? (124: hung 120 s, stacks in $dir/port-$theme.sample), see $dir/port-$theme.log"; exit 1; }
counts=$(native/target/release/pixeldiff "$dir/reference/$theme.png" "$dir/port-$theme.png" "$dir/diff-$theme.png")
echo "$window $theme $counts"
done
done