Skip to content

Visual Studio Code, rebuilt in Rust

Rust

fix(profiles): install template extensions with one trust dialog

rokartur78def177c052
diff --git a/native/crates/app/src/main.rs b/native/crates/app/src/main.rs
index b1deffcd1db..6e1ca105fed 100644
--- a/native/crates/app/src/main.rs
+++ b/native/crates/app/src/main.rs
@@ -589,6 +589,7 @@ pub(crate) fn open_window(request: WindowRequest, cx: &mut App) -> anyhow::Resul
workbench.watch_window_close(window, cx);
workbench.set_installed_extensions(builtins.clone(), user_extensions.clone_for_profile(), developed.clone(), cx);
workbench.set_user_data_profiles(profile, cx);
+ workbench.install_template_extensions(window, cx);
workbench.offer_settings_import(window, cx);
workbench.start_terminal_host();
workbench.watch_editor_focus(window, cx);
diff --git a/native/crates/app/src/workbench/settings_import.rs b/native/crates/app/src/workbench/settings_import.rs
index 821f9804639..765790c8fe0 100644
--- a/native/crates/app/src/workbench/settings_import.rs
+++ b/native/crates/app/src/workbench/settings_import.rs
@@ -157,7 +157,7 @@ fn import_sources() -> Vec<Source> {
}
#[cfg(test)]
-mod tests {
+pub(super) mod tests {
use std::path::Path;
use gpui::TestAppContext;
@@ -199,6 +199,18 @@ mod tests {
std::fs::remove_dir_all(dir).unwrap();
}
+ /// A gallery on localhost that answers every query with `redhat.vscode-yaml` and `beta.vscode-yaml`, of the
+ /// untrusted publishers "Red Hat" and "Beta".
+ pub(in crate::workbench) fn two_publisher_gallery() -> String {
+ let yaml: Value = serde_json::from_str(include_str!("../../../exthost/src/gallery/vscode-yaml-latest.json")).unwrap();
+ let mut other = yaml.clone();
+ other["publisher"]["publisherName"] = "beta".into();
+ other["publisher"]["displayName"] = "Beta".into();
+ other["extensionId"] = "00000000-0000-0000-0000-000000000002".into();
+ let body = serde_json::json!({ "results": [{ "extensions": [yaml, other], "resultMetadata": [{ "metadataType": "ResultCount", "metadataItems": [{ "name": "TotalCount", "count": 2 }] }] }] });
+ serve_gallery(body.to_string())
+ }
+
/// A gallery on localhost that answers every request with `body`.
fn serve_gallery(body: String) -> String {
use std::io::{Read, Write};
@@ -218,13 +230,7 @@ mod tests {
/// trust once, in one dialog that names both.
#[gpui::test]
fn imported_extensions_ask_for_publisher_trust_once(cx: &mut TestAppContext) {
- let yaml: Value = serde_json::from_str(include_str!("../../../exthost/src/gallery/vscode-yaml-latest.json")).unwrap();
- let mut other = yaml.clone();
- other["publisher"]["publisherName"] = "beta".into();
- other["publisher"]["displayName"] = "Beta".into();
- other["extensionId"] = "00000000-0000-0000-0000-000000000002".into();
- let body = serde_json::json!({ "results": [{ "extensions": [yaml, other], "resultMetadata": [{ "metadataType": "ResultCount", "metadataItems": [{ "name": "TotalCount", "count": 2 }] }] }] });
- let gallery_url = serve_gallery(body.to_string());
+ let gallery_url = two_publisher_gallery();
let app_root = Path::new(env!("VSCODE_SRC")).to_path_buf();
let themes = exthost::scan::scan_extension(&app_root.join("extensions/theme-defaults"), true).unwrap();
let theme = crate::theme::load_theme(&[themes], "Dark Modern").unwrap();
diff --git a/native/crates/app/src/workbench/user_data_profile.rs b/native/crates/app/src/workbench/user_data_profile.rs
index 61a3094d138..cb0fcc425f4 100644
--- a/native/crates/app/src/workbench/user_data_profile.rs
+++ b/native/crates/app/src/workbench/user_data_profile.rs
@@ -65,7 +65,6 @@ impl Workbench {
/// and commands.
pub fn set_user_data_profiles(&mut self, state: ProfileState, cx: &mut Context<Self>) {
let window = cx.entity_id();
- let profile_id = state.current.id.clone();
cx.update_global(|service: &mut UserDataProfilesService, _| service.set_window_profile(window, Some(&state.current)));
// userDataProfilesHandler.ts `unsetProfileForWorkspace` on close: a transient profile no other window runs goes.
cx.on_release(move |workbench, cx| {
@@ -82,7 +81,6 @@ impl Workbench {
self.user_data_profiles.state = Some(state);
self.user_data_profiles.editor.name_focus = Some(cx.focus_handle());
self.profiles_changed(cx);
- self.install_template_extensions(&profile_id, cx);
}
/// A change of the app's profiles, then `onDidChangeProfiles` in every window.
@@ -343,18 +341,30 @@ impl Workbench {
if restart {
self.restart_extension_host(window, cx);
}
- self.install_template_extensions(&profile.id, cx);
+ self.install_template_extensions(window, cx);
}
- /// `ExtensionsResource.apply`: the template's extensions the profile does not have yet.
- fn install_template_extensions(&mut self, profile_id: &str, cx: &mut Context<Self>) {
- let pending = cx.update_global(|service: &mut UserDataProfilesService, _| service.pending_installs.remove(profile_id)).unwrap_or_default();
+ /// `ExtensionsResource.apply`: the current profile's template extensions it does not have yet, with one trust
+ /// dialog and an error naming the ones that did not install.
+ pub(crate) fn install_template_extensions(&mut self, window: &mut Window, cx: &mut Context<Self>) {
+ let Some(profile_id) = self.user_data_profiles.state.as_ref().map(|state| state.current.id.clone()) else { return };
+ let pending = cx.update_global(|service: &mut UserDataProfilesService, _| service.pending_installs.remove(&profile_id)).unwrap_or_default();
let installed: Vec<String> = self.extensions.iter().map(|extension| extension.id.to_lowercase()).collect();
- for id in pending {
- if !installed.contains(&id) {
- drop(self.install_from_gallery(id, None, false, cx));
- }
+ let missing: Vec<String> = pending.into_iter().map(|id| id.to_lowercase()).filter(|id| !installed.contains(id)).collect();
+ if missing.is_empty() {
+ return;
}
+ let failed = self.install_gallery_extensions(missing, window, cx);
+ cx.spawn(async move |workbench, cx| {
+ let failed = failed.await;
+ if failed.is_empty() {
+ return;
+ }
+ let lines: Vec<String> = failed.iter().map(|(id, reason)| format!("{id}: {reason}")).collect();
+ let message = format!("Extensions of the profile that were not installed:\n{}", lines.join("\n"));
+ let _ = workbench.update(cx, |workbench, _| workbench.notify_error(message));
+ })
+ .detach();
}
}
diff --git a/native/crates/app/src/workbench/user_data_profile/tests.rs b/native/crates/app/src/workbench/user_data_profile/tests.rs
index b31dc053436..e3f8a52266d 100644
--- a/native/crates/app/src/workbench/user_data_profile/tests.rs
+++ b/native/crates/app/src/workbench/user_data_profile/tests.rs
@@ -56,6 +56,27 @@ fn profile_windows_open_in_this_process(cx: &mut TestAppContext) {
assert!(current.is_transient && current.name == "Temp 1", "{current:?}");
}
+/// extensionsResource.ts `apply` through `installGalleryExtensions`: a template's extensions of two untrusted
+/// publishers ask for trust once, in one dialog that names both.
+#[gpui::test]
+fn template_extensions_ask_for_publisher_trust_once(cx: &mut TestAppContext) {
+ profiles_service("template-trust", cx);
+ let gallery_url = crate::workbench::settings_import::tests::two_publisher_gallery();
+ let handle = cx.update(|cx| open_window(WindowRequest::default(), cx));
+ handle
+ .update(cx, |workbench, window, cx| {
+ workbench.gallery_url = gallery_url;
+ let profile_id = workbench.user_data_profiles.state.as_ref().unwrap().current.id.clone();
+ let ids = vec!["redhat.vscode-yaml".to_owned(), "beta.vscode-yaml".to_owned()];
+ cx.global_mut::<UserDataProfilesService>().pending_installs.insert(profile_id, ids);
+ workbench.install_template_extensions(window, cx);
+ })
+ .unwrap();
+ cx.run_until_parked();
+ let messages = handle.read_with(cx, |workbench, _| workbench.dialogs.iter().map(|shown| shown.dialog.message.clone()).collect::<Vec<_>>()).unwrap();
+ assert_eq!(messages, ["Do you trust publishers \"Red Hat\" and \"Beta\"?"]);
+}
+
/// userDataProfile.ts `onDidChangeProfiles`: a profile one window creates is in every window's Profiles menus and
/// commands, and one it removes leaves them.
#[gpui::test]
diff --git a/port/ledger.md b/port/ledger.md
index 7fcfdc82a2d..be353d38525 100644
--- a/port/ledger.md
+++ b/port/ledger.md
@@ -453,7 +453,7 @@ One row per upstream unit, generated by `bun port/tools/gen-ledger.ts`; mileston
| workbench/services/userActivity | workbench service | M19 | verified | | workbench/user_activity.rs: domActivityTracker.ts 30 s checks and the 10 s inactive debounce over every keystroke and mouse press, sent as $onDidChangeWindowActive (cargo test -p app user_activity); a progress held over 15 s while active keeps the mark until it ends, as progressService.ts `withProgress` (cargo test -p app a_long_progress_holds_the_window_active_until_it_ends) |
| workbench/services/userAttention | workbench service | M19 | n/a | | its only consumer is editTelemetry (editSourceTrackingImpl.ts); the port has no telemetry by decision (port/notes.md) |
| workbench/services/userData | workbench service | M10 | removed | | userDataInit.ts initializes a web window's user data from Settings Sync: browser only, and no sync by decision (port/notes.md) |
-| 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); 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/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 M] view_locations.rs:523: extension containers take no added views, hidden state keyed by Explorer <br> [3 M] view_containers.rs:296, :317: the views of a `viewsContainers.activitybar` container and the contributed views below Testing are sections drawn by `contributed_view_sections`, not view_panes.rs panes: no sashes, stored sizes and order, header drag, or Views submenu ("...") on the container title <br> [3 M] view_containers.rs:5: `viewsContainers.panel`: an extension's panel container gets no panel tab and its views do not draw | view containers of `viewsContainers.activitybar` and the tree views of every container (workbench/view_containers.rs): activity bar items while a view's `when` holds, `workbench.view.extension.<id>`, `<view id>.focus`, `<view id>.active`, merged single views, sections in the scm, debug and test side bars; 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 (shortcut in view_locations.rs: contributed extension containers take no added views; a moved view's hidden state stays under its old container's key); 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) |