Visual Studio Code, rebuilt in Rust
Rust
fix(workbench): keep layout fixed when the color theme changes
rokartura90066b10569
diff --git a/native/crates/app/src/workbench.rs b/native/crates/app/src/workbench.rsindex ed4d07cbd27..ab93b07cac7 100644--- a/native/crates/app/src/workbench.rs+++ b/native/crates/app/src/workbench.rs@@ -1959,8 +1959,9 @@ impl Workbench {.items_center().justify_between().px(px(4.))- .when_some(self.theme.color("sideBarTitle.border"), |title, border| title.border_b_1().border_color(border))- // The h2 keeps its 32px line under the HC border-bottom, so it is laid out from the top, not centered.+ // compositePart.ts `updateStyles` adds the border-bottom inside the border-box title, under a fixed-height+ // label and actions (part.css), so nothing in the title moves when a theme defines it.+ .when_some(self.theme.color("sideBarTitle.border"), |title, border| title.child(div().absolute().left_0().right_0().bottom_0().h(px(1.)).bg(border)))// part.css `.title-label h2`: ellipsis where `.title-actions` (8px padding-left) takes the room..child(div().self_start().min_w_0().truncate().pl(px(8.)).line_height(px(32.)).text_size(px(12.)).font_weight(FontWeight::SEMIBOLD).text_color(self.foreground_or("sideBarTitle.foreground")).child(name))}diff --git a/native/crates/app/src/workbench/dialog_view.rs b/native/crates/app/src/workbench/dialog_view.rsindex b7c3888ac71..0894451e937 100644--- a/native/crates/app/src/workbench/dialog_view.rs+++ b/native/crates/app/src/workbench/dialog_view.rs@@ -343,7 +343,8 @@ impl Workbench {.line_height(px(16.)).bg(self.color(background)).text_color(self.color(foreground))- .when_some(self.theme.color("button.border"), |button, border| button.border_1().border_color(border))+ .border_1()+ .border_color(self.theme.color("button.border").unwrap_or(gpui::transparent_black().into())).hover(move |button| button.bg(hover_color)).whitespace_nowrap().child(button.label.clone());diff --git a/native/crates/app/src/workbench/notifications_view.rs b/native/crates/app/src/workbench/notifications_view.rsindex ae895bf285a..4f7feef327d 100644--- a/native/crates/app/src/workbench/notifications_view.rs+++ b/native/crates/app/src/workbench/notifications_view.rs@@ -824,7 +824,8 @@ impl Workbench {.cursor_pointer().bg(self.color(background)).text_color(self.color(foreground))- .when_some(self.theme.color(if primary { "button.border" } else { "button.secondaryBorder" }), |button, border| button.border_1().border_color(border))+ .border_1()+ .border_color(self.theme.color(if primary { "button.border" } else { "button.secondaryBorder" }).unwrap_or(gpui::transparent_black().into())).hover(move |button| button.bg(hover_color)).whitespace_nowrap().child(action.label.clone())diff --git a/native/crates/app/src/workbench/profiles_editor_view.rs b/native/crates/app/src/workbench/profiles_editor_view.rsindex ad1c77998d4..7280788482c 100644--- a/native/crates/app/src/workbench/profiles_editor_view.rs+++ b/native/crates/app/src/workbench/profiles_editor_view.rs@@ -1125,7 +1125,8 @@ impl Workbench {.rounded(px(4.)).bg(self.color(background)).text_color(self.color(foreground))- .when_some(self.theme.color(if primary { "button.border" } else { "button.secondaryBorder" }), |button, border| button.border_1().border_color(border))+ .border_1()+ .border_color(self.theme.color(if primary { "button.border" } else { "button.secondaryBorder" }).unwrap_or(gpui::transparent_black().into())).when(!enabled, |button| button.opacity(0.4)).when(enabled, |button| {buttondiff --git a/native/crates/app/src/workbench/quick_input_view.rs b/native/crates/app/src/workbench/quick_input_view.rsindex bf390641950..871295c3074 100644--- a/native/crates/app/src/workbench/quick_input_view.rs+++ b/native/crates/app/src/workbench/quick_input_view.rs@@ -693,7 +693,8 @@ impl Workbench {.rounded(px(4.)).bg(self.color(background)).text_color(self.color(foreground))- .when_some(self.theme.color("button.border"), |button, border| button.border_1().border_color(border))+ .border_1()+ .border_color(self.theme.color("button.border").unwrap_or(gpui::transparent_black().into())).hover(|button| button.bg(self.color(hover))).child(label)}diff --git a/native/crates/app/src/workbench/settings_editor_view/list_widget.rs b/native/crates/app/src/workbench/settings_editor_view/list_widget.rsindex 0d2a0b73ce1..e7f381c2340 100644--- a/native/crates/app/src/workbench/settings_editor_view/list_widget.rs+++ b/native/crates/app/src/workbench/settings_editor_view/list_widget.rs@@ -815,7 +815,8 @@ fn text_button(workbench: &Workbench, label: &'static str, primary: bool) -> gpu.cursor_pointer().bg(workbench.color(background)).text_color(workbench.color(foreground))- .when_some(workbench.theme.color(if primary { "button.border" } else { "button.secondaryBorder" }), |button, border| button.border_1().border_color(border))+ .border_1()+ .border_color(workbench.theme.color(if primary { "button.border" } else { "button.secondaryBorder" }).unwrap_or(gpui::transparent_black().into())).hover(move |button| button.bg(hover_color)).whitespace_nowrap().child(label)diff --git a/native/crates/app/src/workbench/themes/tests.rs b/native/crates/app/src/workbench/themes/tests.rsindex f9f0d4f43ff..c946e20a5ae 100644--- a/native/crates/app/src/workbench/themes/tests.rs+++ b/native/crates/app/src/workbench/themes/tests.rs@@ -248,3 +248,137 @@ fn the_host_color_scheme_picks_the_preferred_theme_setting(cx: &mut TestAppConteassert_eq!(written["workbench.preferredDarkColorTheme"], "Dark Modern");assert_eq!(written.get("workbench.colorTheme"), None);}++/// Where the last frame drew: the bounds of every debug selector, then of every hitbox and icon sprite.+/// The test platform's text system draws no glyphs: text shows through the hitboxes of its rows and buttons.+fn drawn_layout(cx: &mut gpui::VisualTestContext) -> (Vec<String>, Vec<String>) {+ let mut selectors: Vec<String> = cx.all_debug_bounds().into_iter().map(|(selector, bounds)| format!("{selector} {bounds:?}")).collect();+ selectors.sort();+ let mut boxes = cx.read_rendered_frame(|scene, hitboxes| {+ let mut boxes = Vec::new();+ for hitbox in hitboxes {+ boxes.push(format!("hitbox y {} x {} {}x{}", hitbox.origin.y, hitbox.origin.x, hitbox.size.width, hitbox.size.height));+ }+ for bounds in scene.monochrome_sprites.iter().map(|sprite| sprite.bounds).chain(scene.polychrome_sprites.iter().map(|sprite| sprite.bounds)) {+ boxes.push(format!("icon y {} x {} {}x{} (device px)", bounds.origin.y.0, bounds.origin.x.0, bounds.size.width.0, bounds.size.height.0));+ }+ boxes+ });+ boxes.sort();+ (selectors, boxes)+}++/// The entries of `a` not in `b`, as a multiset.+fn missing_from(a: &[String], b: &[String]) -> Vec<String> {+ let mut rest = b.to_vec();+ let mut missing = Vec::new();+ for entry in a {+ match rest.iter().position(|other| other == entry) {+ Some(index) => drop(rest.swap_remove(index)),+ None => missing.push(entry.clone()),+ }+ }+ missing+}++/// A window on a folder with two open files, the panel and a toast with two buttons, under Dark Modern, and the+/// temporary directory it reads.+fn laid_out_workbench(cx: &mut TestAppContext) -> (gpui::Entity<Workbench>, &mut gpui::VisualTestContext, std::path::PathBuf) {+ use crate::notifications::{Action, Notification, Run, Severity};+ use config::workspace::Workspace;+ let app_root = Path::new(env!("VSCODE_SRC")).to_path_buf();+ let mut extensions = Vec::new();+ for entry in std::fs::read_dir(app_root.join("extensions")).unwrap() {+ let path = entry.unwrap().path();+ if path.file_name().unwrap().to_string_lossy().starts_with("theme-") {+ extensions.push(scan_extension(&path, true).unwrap());+ }+ }+ let dir = std::env::temp_dir().join(format!("code-gpui-theme-layout-{}-{:?}", std::process::id(), std::thread::current().id()));+ let _ = std::fs::remove_dir_all(&dir);+ std::fs::create_dir_all(dir.join("folder")).unwrap();+ let files = [dir.join("folder/a.txt"), dir.join("folder/b.txt")];+ for file in &files {+ std::fs::write(file, "hello world\nsecond line").unwrap();+ }+ let settings = Arc::new(Mutex::new(Settings::load(Registry::with_extensions(&[]), dir.join("User"), None)));+ let theme = load_theme(&extensions, "Dark Modern").unwrap();+ let (workbench, cx) = cx.add_window_view(|window, cx| {+ let workspace = Some(Workspace::folder(dir.join("folder")));+ let mut workbench = Workbench::new(theme, app_root.clone(), workspace, Languages::new(&[]), settings.clone(), HostSync::new(std::sync::mpsc::channel().0), cx);+ workbench.skip_dialogs = true;+ workbench.color_themes = color_themes(&extensions).unwrap();+ for file in &files {+ workbench.open_file(file.clone(), true, window, cx);+ }+ workbench+ });+ cx.run_until_parked();+ workbench.update_in(cx, |workbench, window, cx| {+ drop(workbench.execute_command("workbench.action.togglePanel", Vec::new(), window, cx));+ let action = |label: &str| Action { id: label.into(), label: label.into(), run: Run::Command(String::new(), Vec::new()) };+ let mut notification = Notification::new(Severity::Info, "message");+ notification.primary = vec![action("Yes"), action("No")];+ drop(workbench.notify(notification));+ });+ cx.run_until_parked();+ (workbench, cx, dir)+}++/// What `after` draws elsewhere than `before`, empty when nothing moved.+fn moved(before: &(Vec<String>, Vec<String>), after: &(Vec<String>, Vec<String>)) -> String {+ let gone = [missing_from(&before.0, &after.0), missing_from(&before.1, &after.1)].concat();+ let new = [missing_from(&after.0, &before.0), missing_from(&after.1, &before.1)].concat();+ if gone.is_empty() && new.is_empty() {+ return String::new();+ }+ format!("\n was {gone:?}\n now {new:?}")+}++// Upstream's parts keep their size and place across non-high-contrast themes: a border color a theme leaves+// undefined still lays out, or is drawn as an outline that takes no space (workbench/browser/media/part.css).+#[gpui::test]+fn switching_the_color_theme_moves_nothing(cx: &mut TestAppContext) {+ use super::SettingTarget;+ let (workbench, cx, dir) = laid_out_workbench(cx);+ let dark_modern = drawn_layout(cx);+ assert!(dark_modern.1.len() > 50, "{:?}", dark_modern.1);+ let themes = workbench.read_with(cx, |workbench, _| workbench.color_themes.iter().filter(|theme| !theme.kind.is_high_contrast()).map(|theme| theme.settings_id.clone()).collect::<Vec<_>>());+ let mut moves = Vec::new();+ for theme in themes.iter().chain(["Dark Modern".to_string()].iter()) {+ workbench.update(cx, |workbench, cx| workbench.set_color_theme(theme, SettingTarget::Preview, cx));+ cx.run_until_parked();+ let diff = moved(&dark_modern, &drawn_layout(cx));+ if !diff.is_empty() {+ moves.push(format!("{theme}:{diff}"));+ }+ }+ assert!(moves.is_empty(), "{}", moves.join("\n"));+ std::fs::remove_dir_all(dir).unwrap();+}++// Third-party themes define borders no built-in one does. Upstream lays out only these when defined:+// window.activeBorder insets the grid (layout.ts), contrastBorder and contrastActiveBorder add high contrast borders.+#[gpui::test]+fn defining_a_border_color_moves_nothing(cx: &mut TestAppContext) {+ let (workbench, cx, dir) = laid_out_workbench(cx);+ let undefined = drawn_layout(cx);+ let mut moves = Vec::new();+ for key in include_str!("../../webview/color_ids.txt").lines().filter(|id| id.to_lowercase().ends_with("border")) {+ if matches!(key, "contrastBorder" | "contrastActiveBorder" | "window.activeBorder" | "window.inactiveBorder") {+ continue;+ }+ let colors = Value::Object([(key.to_string(), json!("#ff00ff"))].into_iter().collect());+ workbench.update(cx, |workbench, cx| {+ workbench.theme.set_customizations(&colors, &Value::Null);+ cx.notify();+ });+ cx.run_until_parked();+ let diff = moved(&undefined, &drawn_layout(cx));+ if !diff.is_empty() {+ moves.push(format!("{key}:{diff}"));+ }+ }+ assert!(moves.is_empty(), "{}", moves.join("\n"));+ std::fs::remove_dir_all(dir).unwrap();+}diff --git a/native/crates/app/src/workbench/views_welcome.rs b/native/crates/app/src/workbench/views_welcome.rsindex 2678ee881bd..4d37d07e9b9 100644--- a/native/crates/app/src/workbench/views_welcome.rs+++ b/native/crates/app/src/workbench/views_welcome.rs@@ -155,7 +155,8 @@ impl Workbench {.line_height(px(16.)).bg(self.color("button.background")).text_color(foreground)- .when_some(self.theme.color("button.border"), |button, border| button.border_1().border_color(border))+ .border_1()+ .border_color(self.theme.color("button.border").unwrap_or(gpui::transparent_black().into())).child(self.button_label(label, foreground)).when(!enabled, |button| button.opacity(0.4)).when(enabled, |button| {diff --git a/port/ledger.md b/port/ledger.mdindex fc0ef6d1558..72bf8b44548 100644--- a/port/ledger.md+++ b/port/ledger.md@@ -442,7 +442,7 @@ One row per upstream unit, generated by `bun port/tools/gen-ledger.ts`; mileston| workbench/services/textfile | workbench service | M8 | verified | | Cmd+S writes the model's encoding (files::encoding, port of encoding.ts with iconv-lite DOS code pages and its cp950 table: cargo test -p files encoding); `files.encoding` read for the resource's language, the open model's else its path's, also for `workspace.decode`/`encode` (cargo test -p files files_encoding_of_the_resource_language_wins, cargo test -p app workspace_encodings_read_files_encoding_of_the_resource_language) and clears dirty state (cargo test -p app keys_and_typed_text_edit_the_focused_editor_and_reach_the_host); save participants: the extensions' for extension saves, trim trailing whitespace, insert final newline and trim final newlines for every save (cargo test -p app save_participants), an auto save sparing the cursor lines; auto save (editorAutoSave.ts): after delay, on focus change, on window change, a delay restarted by each edit, saves held back by error markers, a dirty tab with a short delay drawn clean (`isSaving`) (cargo test -p app auto_save); Save As, Save without Formatting, revert as one undoable edit, save conflict and read-only/permission errors with their actions, file changes and deletes on disk (orphaned tabs), `files.associations` re-detection (workbench/text_files.rs): cargo test -p app text_files; the save conflict Compare editor (`conflictResolution` diff with the help message, Learn More and Don't Show Again, the accept and revert title actions, the help again on a failed save from it; workbench/save_conflict.rs): cargo test -p app compare_opens_the_save_conflict_editor; Format on Save: cargo test -p app format (format_on_save_formats_after_trimming_and_before_the_final_newline); `files.autoGuessEncoding` and `files.candidateGuessEncodings` (encoding.ts `guessEncodingByBuffer` over upstream's jschardet 3.1.4 and iconv-lite in a Bun worker, app/src/encoding_guess.rs; also the Reopen with Encoding picker's guess): cargo test -p app encoding_guess, the encoding.test.ts autoGuessEncoding cases; the packaged, Developer ID signed app ships the worker's jschardet and @vscode/iconv-lite-umd with their licenses appended to its ThirdPartyNotices.txt (port/tools/package-app) and guesses Shift JIS and windows-1252 files: port/tools/app-smoke (port/fixtures/extensions/encoding-guess-tests 2 ok) || workbench/services/textmodelResolver | workbench service | M8 | verified | | models keep a non-file URI's query, so two git refs of one file are two models: cargo test -p app two_refs_of_one_file_diff_as_two_models; content providers newest first (`ContentProviders`, workbench/text_model_resolver.rs, main_thread.rs `$registerTextContentProvider`), model lifetime as `destroyReferencedObject` (`EditorGroup::is_referenced`: dirty, a diff side, an unexpired host reference), `inmemory` without a model fails to resolve: cargo test -p app text_model_resolver (11 textModelResolverService.test.ts cases); the synthetic-document and multi-diff cases need chat and the multi-diff editor (milestone 14's `workbench/contrib/multiDiffEditor`), `canHandleResource`'s one caller is compareWithClipboard (milestone 12's files contribution); content provider registrations newest first and provider-backed models (main_thread.rs) || workbench/services/textresourceProperties | workbench service | M8 | verified | | `getEOL`: a model without line breaks takes the resource's and language's `files.eol`, LF for `auto` on macOS (editor.rs `default_eol`): cargo test -p app files_eol; the remote OS branch belongs to remote, removed; `getEOL`: a model without line breaks takes the resource's and language's `files.eol`, LF for `auto` on macOS (editor.rs `default_eol`): cargo test -p app files_eol; no remote OS |-| workbench/services/themes | workbench service | M7 | verified | | `.tmTheme` themes and `tokenColors` paths, JSON `settings` themes (themeCompatibility.ts `convertSettings`): theme::tests::tm_theme_settings_give_token_rules_and_editor_colors. Icon theme keys with a parent folder (file_icons::tests::keys_with_a_parent_folder_match_inside_that_folder_only). all 19 built-in color themes with `include` and tokenColors, `workbench.colorCustomizations` and `editor.tokenColorCustomizations` with `[theme]` scopes and token groups, `window.autoDetectColorScheme`, `window.autoDetectHighContrast` and the four preferred theme settings (system appearance and Increase Contrast, followed while running), the theme and file icon theme follow settings.json edits (cargo test -p app theme themes configuration); `semanticTokenColors` and `editor.semanticTokenColorCustomizations` (editor/contrib/semanticTokens row); product icon themes (productIconThemeData.ts: `contributes.productIconThemes`, `workbench.productIconTheme`, truetype, opentype, woff and woff2 fonts (woff2 through the wuff crate), glyphs drawn as SVG paths since GPUI cannot load icon fonts: product_icons.rs, cargo test -p app product_icon; port/tools/product-icons-pair with port/fixtures/extensions/product-icons: the activity bar glyphs match the reference, 86 of 50000 pixels off in the activity bar crop). Registered icon ids resolve as `_resolveIconDefinition` does (codicons.rs `icon_ids`, the defaults generated by port/tools/gen-icon-registry.ts): the activity bar draws `explorer-view-icon` and the other view container icons, and the fixture's woff2 font and `explorer-view-icon` definition match the reference in product-icons-pair; views that still pass codicon ids are listed in port/notes.md milestone 20; all 19 built-in color themes with `include` and tokenColors, `workbench.colorCustomizations` and `editor.tokenColorCustomizations` with `[theme]` scopes and token groups, `window.autoDetectColorScheme`, `window.autoDetectHighContrast` and the four preferred theme settings (system appearance and Increase Contrast, followed while running), the theme and file icon theme follow settings.json edits (cargo test -p app theme themes configuration). Blocked: `semanticTokenColors` and `editor.semanticTokenColorCustomizations` need semantic tokens (editor/contrib/semanticTokens, milestone 13); product icon themes need a contributing extension (gallery, milestone 18); all 19 built-in color themes incl. hc-light, tokenColors (theme.rs, syntax.rs); cargo test -p app theme::tests; `setColorTheme` from the theme picker (preview, write, `$onColorThemeChange`), not on a settings.json edit; no semanticTokenColors (needs semantic tokens), no icon themes; extension `contributes.colors` defaults (colorExtensionPoint.ts, theme.rs `extension_colors`): cargo test -p app a_contributed_color_has_its_default_in_themes_without_it |+| workbench/services/themes | workbench service | M7 | verified | | `.tmTheme` themes and `tokenColors` paths, JSON `settings` themes (themeCompatibility.ts `convertSettings`): theme::tests::tm_theme_settings_give_token_rules_and_editor_colors. Icon theme keys with a parent folder (file_icons::tests::keys_with_a_parent_folder_match_inside_that_folder_only). all 19 built-in color themes with `include` and tokenColors, `workbench.colorCustomizations` and `editor.tokenColorCustomizations` with `[theme]` scopes and token groups, `window.autoDetectColorScheme`, `window.autoDetectHighContrast` and the four preferred theme settings (system appearance and Increase Contrast, followed while running), the theme and file icon theme follow settings.json edits (cargo test -p app theme themes configuration); `semanticTokenColors` and `editor.semanticTokenColorCustomizations` (editor/contrib/semanticTokens row); product icon themes (productIconThemeData.ts: `contributes.productIconThemes`, `workbench.productIconTheme`, truetype, opentype, woff and woff2 fonts (woff2 through the wuff crate), glyphs drawn as SVG paths since GPUI cannot load icon fonts: product_icons.rs, cargo test -p app product_icon; port/tools/product-icons-pair with port/fixtures/extensions/product-icons: the activity bar glyphs match the reference, 86 of 50000 pixels off in the activity bar crop). Registered icon ids resolve as `_resolveIconDefinition` does (codicons.rs `icon_ids`, the defaults generated by port/tools/gen-icon-registry.ts): the activity bar draws `explorer-view-icon` and the other view container icons, and the fixture's woff2 font and `explorer-view-icon` definition match the reference in product-icons-pair; views that still pass codicon ids are listed in port/notes.md milestone 20; all 19 built-in color themes with `include` and tokenColors, `workbench.colorCustomizations` and `editor.tokenColorCustomizations` with `[theme]` scopes and token groups, `window.autoDetectColorScheme`, `window.autoDetectHighContrast` and the four preferred theme settings (system appearance and Increase Contrast, followed while running), the theme and file icon theme follow settings.json edits (cargo test -p app theme themes configuration). Blocked: `semanticTokenColors` and `editor.semanticTokenColorCustomizations` need semantic tokens (editor/contrib/semanticTokens, milestone 13); product icon themes need a contributing extension (gallery, milestone 18); all 19 built-in color themes incl. hc-light, tokenColors (theme.rs, syntax.rs); cargo test -p app theme::tests; `setColorTheme` from the theme picker (preview, write, `$onColorThemeChange`), not on a settings.json edit; no semanticTokenColors (needs semantic tokens), no icon themes; extension `contributes.colors` defaults (colorExtensionPoint.ts, theme.rs `extension_colors`): cargo test -p app a_contributed_color_has_its_default_in_themes_without_it; switching between non-high-contrast themes or defining any border color but `window.*Border` and `contrast*Border` moves nothing in the workbench (cargo test -p app moves_nothing) || workbench/services/timer | workbench service | M19 | verified | | timer.rs: timerService.ts startup metrics over the marks main.rs sets for the phases the native process has (Electron-only phases have no marks and no rows); cargo test -p app timer:: || workbench/services/title | workbench service | M11 | verified | | titleService.ts registers the title bar part: workbench.rs `title_bar` (workbench/parts/titlebar), active and inactive.; verified: every pair of port/results/windows.md (milestone 11 verification): the title bar and command center, "[Extension Development Host]" titles || workbench/services/treeSitter | workbench service | M7 | n/a | | tree-sitter tokens run only with `editor.experimental.preferTreeSitter.*` (experimental, off by default) or `editor.experimental.treeSitterTelemetry` (telemetry, removed); its other user is the chat agent terminal tools (AI, removed). TextMate tokens cover every language (workbench/services/textMate) |