Skip to content

Visual Studio Code, rebuilt in Rust

Rust

feat(views): progress and icon badges on panel and secondary side bar tabs

rokartur102b0f1980f8
diff --git a/native/crates/app/src/workbench/activity.rs b/native/crates/app/src/workbench/activity.rs
index 3e97a731131..b2a79f8e39c 100644
--- a/native/crates/app/src/workbench/activity.rs
+++ b/native/crates/app/src/workbench/activity.rs
@@ -6,7 +6,7 @@ use std::collections::HashMap;
use std::sync::OnceLock;
use std::time::{Duration, Instant};
-use gpui::{Animation, AnimationExt, Context, Div, InteractiveElement, IntoElement, ParentElement, Styled, Transformation, Window, div, percentage, prelude::FluentBuilder, px, relative, svg};
+use gpui::{Animation, AnimationExt, AnyElement, Context, Div, InteractiveElement, IntoElement, ParentElement, Styled, Transformation, Window, div, percentage, prelude::FluentBuilder, px, relative, svg};
use serde_json::Value;
use super::Workbench;
@@ -18,6 +18,10 @@ const PROGRESS_MIN_TIME: Duration = Duration::from_millis(300);
/// progressService.css `.progress-badge > .badge-content::before`: the 13px sync glyph of its data URL mask.
const PROGRESS_ICON: &str = include_str!("activity/progress-badge.svg");
+pub(super) fn progress_badge_icon(color: gpui::Rgba) -> AnyElement {
+ svg().external_path(progress_icon_path()).size(px(13.)).text_color(color).into_any_element()
+}
+
/// gpui draws svgs from paths: the glyph is written once to the temporary folder.
fn progress_icon_path() -> &'static str {
static PATH: OnceLock<String> = OnceLock::new();
@@ -161,25 +165,23 @@ impl Workbench {
.when_some(self.theme.color("contrastBorder"), |badge, border| badge.border_1().border_color(border));
match content {
BadgeContent::Text(text) => badge.min_w(px(16.)).px(px(4.)).text_size(px(9.)).font_weight(gpui::FontWeight::SEMIBOLD).line_height(px(16.)).child(text),
- BadgeContent::Progress => badge.w(px(16.)).child(svg().external_path(progress_icon_path()).size(px(13.)).text_color(foreground).into_any_element()),
- // activityaction.css `.badge .codicon.badge-content`: the 13px glyph; codicon-animations.css `spin`: one turn
- // in 1.5s in 30 steps.
- BadgeContent::Icon(icon) => {
- let (name, spin) = icon.strip_suffix("~spin").map_or((icon, false), |name| (name, true));
- let glyph = match spin {
- true => svg()
- .external_path(crate::codicons::svg_path(&self.app_root, crate::symbol_icons::svg_name(name)).to_string_lossy().into_owned())
- .size(px(13.))
- .text_color(foreground)
- .with_animation("activity-badge-spin", Animation::new(Duration::from_millis(1500)).repeat(), |icon, delta| icon.with_transformation(Transformation::rotate(percentage((delta * 30.).floor() / 30.))))
- .into_any_element(),
- false => self.icon(name, 13., 13., foreground).into_any_element(),
- };
- badge.w(px(16.)).child(glyph)
- }
+ BadgeContent::Progress => badge.w(px(16.)).child(progress_badge_icon(foreground)),
+ // activityaction.css `.badge .codicon.badge-content`: the 13px glyph.
+ BadgeContent::Icon(icon) => badge.w(px(16.)).child(self.badge_icon(icon, 13., foreground)),
}
}
+ /// An `IconBadge`'s codicon; codicon-animations.css `spin`: one turn in 1.5s in 30 steps.
+ pub(super) fn badge_icon(&self, icon: &'static str, size: f32, color: gpui::Rgba) -> AnyElement {
+ let Some(name) = icon.strip_suffix("~spin") else { return self.icon(icon, size, size, color).into_any_element() };
+ svg()
+ .external_path(crate::codicons::svg_path(&self.app_root, crate::symbol_icons::svg_name(name)).to_string_lossy().into_owned())
+ .size(px(size))
+ .text_color(color)
+ .with_animation("activity-badge-spin", Animation::new(Duration::from_millis(1500)).repeat(), |icon, delta| icon.with_transformation(Transformation::rotate(percentage((delta * 30.).floor() / 30.))))
+ .into_any_element()
+ }
+
/// `showOnActivityBar` and `withCompositeProgress` for `$startProgress` at a view container or view location
/// (Explorer, Source Control, Extensions, or an id): the badge, and the progress bar of the container or the view.
pub(crate) fn start_activity_progress(&mut self, handle: u64, location: &Value, delay: Option<u64>, total: Option<f64>, window: &mut Window, cx: &mut Context<Self>) {
diff --git a/native/crates/app/src/workbench/panel.rs b/native/crates/app/src/workbench/panel.rs
index 7e78eeb7cf5..f0a01dd9d3c 100644
--- a/native/crates/app/src/workbench/panel.rs
+++ b/native/crates/app/src/workbench/panel.rs
@@ -13,6 +13,7 @@ use gpui::{
use serde_json::json;
use super::Workbench;
+use super::activity::{BadgeContent, visible_badge};
use super::hover::{HoverContent, HoverOptions, HoverPosition};
use super::layout::{Alignment, Part, Position};
use super::view_locations::{is_generated_container, location_code};
@@ -577,7 +578,18 @@ impl Workbench {
let foreground = if active { self.foreground_or("panelTitle.activeForeground") } else { self.foreground_or("panelTitle.inactiveForeground") };
let id = view.id;
let dragged = DraggedComposite { id, label: view.title.into(), icon: None, foreground, background: self.color(background) };
- let badge = self.painted_tab_badge(view).map(|badge| {
+ let status_badge = self.tab_status_badge(view).and_then(|content| {
+ let foreground = self.foreground_or("activityBarBadge.foreground");
+ // paneCompositePart.css: a progress badge's 16px circle around the 13px mask, an icon badge's 3px padding
+ // around the codicon at the `.badge-content` 10px font size.
+ let glyph = match content {
+ BadgeContent::Progress => super::activity::progress_badge_icon(foreground),
+ BadgeContent::Icon(icon) => self.badge_icon(icon, 10., foreground),
+ BadgeContent::Text(_) => return None,
+ };
+ Some(div().debug_selector(|| "panel-tab-status-badge".into()).ml(px(2.)).flex_none().size(px(16.)).flex().items_center().justify_center().rounded(px(8.)).bg(self.color("activityBarBadge.background")).child(glyph))
+ });
+ let badge = self.painted_tab_badge(view).filter(|_| status_badge.is_none()).map(|badge| {
let count = badge.number;
let text = count.to_string();
let text_width = text_width(&text, 10., window);
@@ -614,6 +626,7 @@ impl Workbench {
// connectedPaneTabs.css: the first tab's top left corner is the part's, square in compact density.
.when(active && !(first && self.compact_density()), |tab| tab.rounded_tl(px(7.)))
.child(div().flex_none().w(px(text_width(view.title, 13., window))).whitespace_nowrap().line_height(px(24.)).child(view.title))
+ .children(status_badge)
.children(badge)
.child(self.panel_tab_hover(view, window))
.on_drag(dragged, |dragged, _, _, cx| cx.new(|_| dragged.clone()))
@@ -801,6 +814,16 @@ impl Workbench {
}
}
+ /// compositeBarActions.ts `getVisibleBadges`: the container's progress badge, else its first icon badge, over its
+ /// number badges.
+ fn tab_status_badge(&self, tab: &CompositeTab) -> Option<BadgeContent> {
+ let mut badges = self.container_badges(tab.id);
+ if tab.id == super::view_locations::TESTING_CONTAINER {
+ badges.extend(self.testing_badge());
+ }
+ visible_badge(&badges).filter(|content| !matches!(content, BadgeContent::Text(_)) && self.badges_enabled(tab.id))
+ }
+
/// compositeBarActions.ts `updateActivity`: the badge shows while the container's badges are enabled.
fn painted_tab_badge(&self, tab: &CompositeTab) -> Option<NumberBadge> {
self.tab_badge(tab).filter(|_| self.badges_enabled(tab.id))
@@ -817,7 +840,10 @@ fn panel_tab_label(view: &CompositeTab, workbench: &Workbench) -> String {
/// The width `panel_tab` paints: 16px padding each side, the title, and the badge 2px after it.
fn panel_tab_width(view: &CompositeTab, workbench: &Workbench, window: &Window) -> f32 {
- let badge = workbench.painted_tab_badge(view).map_or(0., |badge| 2. + badge_width(text_width(&badge.number.to_string(), 10., window)));
+ let badge = match workbench.tab_status_badge(view) {
+ Some(_) => 18.,
+ None => workbench.painted_tab_badge(view).map_or(0., |badge| 2. + badge_width(text_width(&badge.number.to_string(), 10., window))),
+ };
32. + text_width(view.title, 13., window) + badge
}
diff --git a/native/crates/app/src/workbench/view_locations/tests.rs b/native/crates/app/src/workbench/view_locations/tests.rs
index 0fb82bdd8ff..112fe95c544 100644
--- a/native/crates/app/src/workbench/view_locations/tests.rs
+++ b/native/crates/app/src/workbench/view_locations/tests.rs
@@ -450,6 +450,22 @@ fn a_composite_drop_leaves_no_hover_under_the_pointer(cx: &mut TestAppContext) {
assert_eq!(workbench.read_with(cx, |workbench, _| workbench.hovers.shown_text().map(str::to_owned)), None);
}
+/// compositeBarActions.ts `updateActivity`: a container moved to the panel shows its `ProgressBadge` on its tab.
+#[gpui::test]
+fn a_moved_container_tab_shows_its_progress_badge(cx: &mut TestAppContext) {
+ let profile = Arc::new(Mutex::new(Storage::in_memory()));
+ let (workbench, cx) = open(profile, cx);
+ let extensions = crate::workbench::extensions_view::VIEWLET_ID;
+ workbench.update_in(cx, |workbench, window, cx| {
+ drop(workbench.execute_command(&format!("moveViewContainerTo{}", location_code(Part::Panel)), vec![json!(extensions)], window, cx));
+ workbench.start_activity_progress(1, &json!(5), None, None, window, cx);
+ });
+ cx.executor().advance_clock(std::time::Duration::from_millis(400));
+ cx.run_until_parked();
+ cx.update(|window, cx| drop(window.draw(cx)));
+ assert_eq!(cx.debug_bounds("panel-tab-status-badge").map(|bounds| bounds.size), Some(gpui::size(gpui::px(16.), gpui::px(16.))));
+}
+
/// An activity item drags as the browser's image of its element: its icon, not its title.
#[gpui::test]
fn an_activity_item_drags_as_its_icon(cx: &mut TestAppContext) {
diff --git a/port/ledger.md b/port/ledger.md
index 16d8e79d6de..537eddc40fc 100644
--- a/port/ledger.md
+++ b/port/ledger.md
@@ -456,7 +456,7 @@ One row per upstream unit, generated by `bun port/tools/gen-ledger.ts`; mileston
| workbench/services/userDataProfile | workbench service | M10 | verified | | one app-wide `UserDataProfilesService` (a gpui Global in app/src/user_data_profile.rs) for every window of the process: profile windows open in this process, a transient profile lives while a window runs it (userDataProfilesHandler.ts cleanup on close), and `onDidChangeProfiles` reaches every window (cargo test -p app workbench::user_data_profile: profile_windows_open_in_this_process, every_window_sees_a_profile_another_window_creates_and_removes); userDataProfileManagement.ts `switchProfile`, `removeProfile` and `changeCurrentProfile` (configuration, keybindings, global state and user extensions move to the profile's files, the extension host restarts, workbench/extension_host_restart.rs) in workbench/user_data_profile.rs; the configuration layers of a profile (`ApplicationConfiguration`, PROFILE_SCOPES, `workbench.settings.applyToAllProfiles`) with configurationService.test.ts's Profiles suite (cargo test -p config profile_tests); the settings, keybindings, tasks, snippets, globalState and extensions resources and the `.code-profile` template of userDataProfileImportExportService.ts as app/src/profile_template.rs (cargo test -p app profile_template); a template's extensions install the way extensionsResource.ts `apply` does, one publisher trust dialog for all of them and an error naming the ones that failed (cargo test -p app template_extensions_ask_for_publisher_trust_once); per-profile extensions.json (cargo test -p exthost extension_management); `createTroubleshootProfile` is removed with contrib/issue, its only caller (issueTroubleshoot.ts); profile templates from `profileTemplatesUrl` have no source, the product.json has none |
| workbench/services/userDataSync | workbench service | | removed | | no sign-in/AI by decision (port/notes.md); not ported |
| workbench/services/utilityProcess | workbench service | | verified | | no utility process workers: the file watcher worker, the one kept client, is files/src/watcher.rs on an FSEvents thread (platform/files; api-tests `vscode API - workspace-watcher` passes in the milestone 20 whole-suite run); localTranscription is AI, removed (port/notes.md milestone 20) |
-| workbench/services/views | workbench service | M11 | ported | [3 S] side_bar.rs:62: the compact activity bar's tabs have no item menu and no drag; [3 S] view_panes.rs:535: a collapsed pane of a container in the panel draws expanded, the reference as a narrow strip (ui-pair contributed-panes.json "moved", Third); [3 S] panel.rs:762 `tab_badge`: a panel or secondary side bar tab draws number badges only, no `IconBadge` or `ProgressBadge` (compositeBarActions.ts `updateActivity`: a moved Testing container's spinner during a run and eye while watching, a container's progress) | view containers of `viewsContainers.activitybar` and `viewsContainers.panel` and the tree views of every container (workbench/view_containers.rs): activity bar items while a view's `when` holds, `workbench.view.extension.<id>` with its "View: Show <title>" Command Palette item while `viewContainer.<id>.enabled` (cargo test -p app an_extension_container_is_shown), a panel container's tab after the built-in ones, its views as side-by-side panes under its "..." and "View: Toggle <title>" (cargo test -p app an_extension_panel_container_is_a_panel_tab), each contributed view's "<container>: Focus on <view> View" palette item (ui-pair port/fixtures/ui-pair/contributed-panes.json "palette" and "panel" match the reference but its Ports tab, removed by decision), `<view id>.focus`, `<view id>.active`, merged single views, view_panes.rs panes for the views of an extension container and of Testing (`PaneContainer::Contributed`: cargo test -p app view_containers::; ui-pair port/fixtures/ui-pair/contributed-panes.json with port/fixtures/extensions/contributed-panes, the Port Panes and Testing side bars as the reference), treeView.ts `noDataProviderMessage` (cargo test -p app tree_view::), contributed views of scm and debug as panes of those containers; the Explorer's ViewDescriptorsState (view_panes.rs); ui-pair port/results/references-view.md; `visibility` (`hidden` views stay out until the Views submenu of the Explorer's "..." shows them, `collapsed`; workbench/view_visibility.rs: cargo test -p app view_visibility); the Explorer container's ViewDescriptorsState (view_panes.rs); moving views (workbench/view_locations.rs, verified): `views.customizations` viewLocations and generated containers `workbench.views.service.<location>.<uuid>` with their activity bar items and panel tabs, View: Move View, Move Focused View, Reset Focused View Location, a view header dropped on another container's pane (at its position), on the activity bar or on a panel's title (a new entry), `focusedView`; the folder view, Open Editors, Outline, Timeline, Source Control's Changes, Search, the debug views and the panel's views move into any built-in container or a new entry and back, the moved view opens focused, the picker lists only visible views, a moved view's hidden state is in its current container's state (cargo test -p app a_moved_view_is_hidden); an activity item's and a tab's context menu with Move To (the other locations) and Reset Location away from the default location or for a lone view at home (paneCompositeBar.ts `getContextMenuActionsForComposite`: cargo test -p app the_explorer_item_menu), above them Configure Keybinding, Hide/Keep '{name}' and Show/Hide Badge, a panel or secondary side bar tab's menu ending with its bar's actions and its unpinned tabs hidden (compositeBarActions.ts `showContextMenu`, panelPart.ts `fillExtraContextMenuActions`: cargo test -p app an_item_menu_hides), an activity item dragged onto the panel or secondary side bar and a tab dropped on the activity bar (compositeBar.ts `CompositeDragAndDrop.drop`: cargo test -p app the_explorer_item_drags; at the drop index, reordered on its own bar and stored in its pinned items, opened focused: cargo test -p app a_dropped_composite; an activity item drags as its icon: cargo test -p app an_activity_item_drags_as_its_icon; no hover after a drop: cargo test -p app a_composite_drop_leaves_no_hover; ui-pair contributed-panes.json "moved": Port Panes moves into the panel and opens in both), the Extensions and Testing containers move to the panel and the secondary side bar and back with their views and open commands (cargo test -p app the_extensions_and_testing_containers; ui-pair contributed-panes.json "extensions-moved" and "testing-moved": both items dragged onto the panel open there as in the reference); cargo test -p app (2594 passed); ui-pair port/fixtures/ui-pair/m11/move-view.json, port/results/move-view.md (8 steps match, Ports removed by decision); verified: ui-pair port/results/references-view.md (milestone 11 verification) |
+| workbench/services/views | workbench service | M11 | ported | [3 S] side_bar.rs:62: the compact activity bar's tabs have no item menu and no drag; [3 S] view_panes.rs:535: a collapsed pane of a container in the panel draws expanded, the reference as a narrow strip (ui-pair contributed-panes.json "moved", Third) | view containers of `viewsContainers.activitybar` and `viewsContainers.panel` and the tree views of every container (workbench/view_containers.rs): activity bar items while a view's `when` holds, `workbench.view.extension.<id>` with its "View: Show <title>" Command Palette item while `viewContainer.<id>.enabled` (cargo test -p app an_extension_container_is_shown), a panel container's tab after the built-in ones, its views as side-by-side panes under its "..." and "View: Toggle <title>" (cargo test -p app an_extension_panel_container_is_a_panel_tab), each contributed view's "<container>: Focus on <view> View" palette item (ui-pair port/fixtures/ui-pair/contributed-panes.json "palette" and "panel" match the reference but its Ports tab, removed by decision), `<view id>.focus`, `<view id>.active`, merged single views, view_panes.rs panes for the views of an extension container and of Testing (`PaneContainer::Contributed`: cargo test -p app view_containers::; ui-pair port/fixtures/ui-pair/contributed-panes.json with port/fixtures/extensions/contributed-panes, the Port Panes and Testing side bars as the reference), treeView.ts `noDataProviderMessage` (cargo test -p app tree_view::), contributed views of scm and debug as panes of those containers; the Explorer's ViewDescriptorsState (view_panes.rs); ui-pair port/results/references-view.md; `visibility` (`hidden` views stay out until the Views submenu of the Explorer's "..." shows them, `collapsed`; workbench/view_visibility.rs: cargo test -p app view_visibility); the Explorer container's ViewDescriptorsState (view_panes.rs); moving views (workbench/view_locations.rs, verified): `views.customizations` viewLocations and generated containers `workbench.views.service.<location>.<uuid>` with their activity bar items and panel tabs, View: Move View, Move Focused View, Reset Focused View Location, a view header dropped on another container's pane (at its position), on the activity bar or on a panel's title (a new entry), `focusedView`; the folder view, Open Editors, Outline, Timeline, Source Control's Changes, Search, the debug views and the panel's views move into any built-in container or a new entry and back, the moved view opens focused, the picker lists only visible views, a moved view's hidden state is in its current container's state (cargo test -p app a_moved_view_is_hidden); an activity item's and a tab's context menu with Move To (the other locations) and Reset Location away from the default location or for a lone view at home (paneCompositeBar.ts `getContextMenuActionsForComposite`: cargo test -p app the_explorer_item_menu), above them Configure Keybinding, Hide/Keep '{name}' and Show/Hide Badge, a panel or secondary side bar tab's menu ending with its bar's actions and its unpinned tabs hidden (compositeBarActions.ts `showContextMenu`, panelPart.ts `fillExtraContextMenuActions`: cargo test -p app an_item_menu_hides), an activity item dragged onto the panel or secondary side bar and a tab dropped on the activity bar (compositeBar.ts `CompositeDragAndDrop.drop`: cargo test -p app the_explorer_item_drags; at the drop index, reordered on its own bar and stored in its pinned items, opened focused: cargo test -p app a_dropped_composite; an activity item drags as its icon: cargo test -p app an_activity_item_drags_as_its_icon; no hover after a drop: cargo test -p app a_composite_drop_leaves_no_hover; a moved container's tab with its progress or icon badge over its number: cargo test -p app a_moved_container_tab_shows; ui-pair contributed-panes.json "moved": Port Panes moves into the panel and opens in both), the Extensions and Testing containers move to the panel and the secondary side bar and back with their views and open commands (cargo test -p app the_extensions_and_testing_containers; ui-pair contributed-panes.json "extensions-moved" and "testing-moved": both items dragged onto the panel open there as in the reference); cargo test -p app (2594 passed); ui-pair port/fixtures/ui-pair/m11/move-view.json, port/results/move-view.md (8 steps match, Ports removed by decision); verified: ui-pair port/results/references-view.md (milestone 11 verification) |
| workbench/services/workingCopy | workbench service | M8 | verified | | the text file and untitled working copies are the editor models (dirty state, save, revert, the window's edited dot of `onDidChangeDirty`): cargo test -p app untitled (30), lifecycle (3); WorkingCopyFileService create, move, copy, delete with participants: cargo test -p files operations (12); WorkingCopyHistoryService and its tracker for saves into User/History, entries following renames and folder moves (`moveEntries`): cargo test -p app local_history (10); WorkingCopyBackupService and the backup tracker with hot exit (backups.rs, workbench/backup_tracker.rs), a backup of a deleted file restoring as an orphaned model (`doResolveFromBackup`), modified scratchpads backing up: cargo test -p app backup (19); the working copies of editable custom documents (MainThreadCustomEditorModel, workbench/custom_documents.rs: `$onDidEdit` edits for undo and redo with `$disposeEdits`, `$onContentChange`, dirty tabs, `$onSave`, Save As with `$onSaveAs` and the editor moved to the target, `$revert`, `$backup` into a `vscode-custom-editor` backup restored with its backup id): cargo test -p app custom_documents (3), and port/fixtures/extensions/custom-document-tests (FIXTURE=custom-document-tests port/tools/webview-check: 4/4 in the reference and 4/4 in the port). Notebook working copies are the contrib/notebook row's; their backups are typed (`hashIdentifier` with a type id, backups.rs: cargo test -p app backups::, the upstream typed hashes) and the shutdown joins backups still being written |
| workbench/services/workspaces | workbench service | M12 | verified | | workspace_trust.rs: WorkspaceTrustManagementService (uriTrustInfo in shared storage, longest trusted parent, empty window memento, parent folder trust) and WorkspaceTrustRequestService: cargo test -p app workspace_trust; workbench/workspace_editing.rs: abstractWorkspaceEditingService.ts addFolders, removeFolders, updateFolders, saveAndEnterWorkspace, enterWorkspace in the same window (stopped and started host, settings, backups, storage, Explorer, title), duplicate workspace: cargo test -p app folders_added_and_removed_in_a_workspace_reach_its_file_the_explorer_settings_and_host adding_a_folder_enters_an_untitled_workspace_in_the_same_window workspace_editing (the Remove Folder picker's ROOT_FOLDER icons, `setProfileForWorkspace`: a_new_workspace_keeps_the_window_profile); ui-pair port/fixtures/ui-pair/m12/workspace-folders.json, verified at port-m12b-verify |
| workbench/contrib/accessibility | workbench contribution | M19 | verified | | workbench/accessible_view.rs and workbench/accessibility.rs: accessible view and accessibility help (Alt+F2, Alt+F1 with the editor, hover, view help providers, the hover's and a workbench hover's accessible view, Escape from the latter focusing the hover again, a focused contributed tree or webview view's `accessibilityHelpContent`, a webview view the `focusedView` while its webview has the keyboard; Alt+F6, Alt+H, Alt+K, Alt+A, Alt+]/[), notification aria labels with the verbosity hint, unfocused editor dimming, Toggle Screen Reader Accessibility Mode, status entry; cargo test -p app accessib (alt_f1_shows_the_editor_help..., alt_f1_in_a_contributed_view..., alt_f1_in_a_webview_view..., dimming), cargo test -p app content_hover (the hover's accessible view), port/tools/a11y-check reads the help text area (port/notes.md milestone 19) |