Skip to content

Visual Studio Code, rebuilt in Rust

Rust

feat(extensions): apply an extension to all profiles

rokartur0dcb0cde974f
diff --git a/native/crates/app/src/menus.rs b/native/crates/app/src/menus.rs
index 0e994a66e0b..a9c595fedd1 100644
--- a/native/crates/app/src/menus.rs
+++ b/native/crates/app/src/menus.rs
@@ -905,6 +905,9 @@ pub fn workbench_menus() -> Vec<MenuItem> {
let entry = Entry::Command { id: id.into(), precondition: None, toggled: None, alt: None };
items.push(MenuItem { menu: MenuId::ExtensionContext, entry, title: title.into(), group: String::new(), order, when: Expr::deserialize(when) });
}
+ let entry = Entry::Command { id: "workbench.extensions.action.toggleApplyToAllProfiles".into(), precondition: None, toggled: Toggled::when(Expr::deserialize("isApplicationScopedExtension")), alt: None };
+ let when = Expr::deserialize("extensionStatus == 'installed' && !isDefaultApplicationScopedExtension && !isBuiltinExtension && isWorkspaceScopedExtension == false");
+ items.push(MenuItem { menu: MenuId::ExtensionContext, entry, title: "Apply Extension to all Profiles".into(), group: "2_configure".into(), order: 3., when });
// stickyScrollActions.ts and breadcrumbsControl.ts: the toggles' checked titles, the only ones the menu shows while it is open.
for (id, setting, title) in [("breadcrumbs.toggle", "breadcrumbs.enabled", "Breadcrumbs"), ("editor.action.toggleStickyScroll", "editor.stickyScroll.enabled", "Sticky Scroll")] {
let entry = Entry::Command { id: id.into(), precondition: None, toggled: Toggled::when(Expr::deserialize(&format!("config.{setting} == true"))), alt: None };
diff --git a/native/crates/app/src/workbench/extensions_list_view.rs b/native/crates/app/src/workbench/extensions_list_view.rs
index 08e71d1f7f1..7411f15c2a6 100644
--- a/native/crates/app/src/workbench/extensions_list_view.rs
+++ b/native/crates/app/src/workbench/extensions_list_view.rs
@@ -580,6 +580,8 @@ impl Workbench {
context.insert("isWorkspaceScopedExtension".into(), json!(false));
if let Some(local) = &extension.local {
context.insert("extensionSource".into(), local.description["__metadata"]["source"].clone());
+ context.insert("isDefaultApplicationScopedExtension".into(), json!(extension.is_language_pack()));
+ context.insert("isApplicationScopedExtension".into(), json!(local.description["isApplicationScoped"] == true));
}
// extensionGalleryManifestService.ts gives the product's gallery `signing.allPublicRepositorySigned: true`.
context.insert("galleryAllPublicRepositorySigned".into(), json!(true));
diff --git a/native/crates/app/src/workbench/extensions_list_view/tests.rs b/native/crates/app/src/workbench/extensions_list_view/tests.rs
index 018f8a49939..1b3cc60f18a 100644
--- a/native/crates/app/src/workbench/extensions_list_view/tests.rs
+++ b/native/crates/app/src/workbench/extensions_list_view/tests.rs
@@ -69,9 +69,14 @@ fn the_manage_menu_lists_the_extension_context_menu(cx: &mut TestAppContext) {
}).collect::<Vec<_>>()
};
let enablement = ["Enable (disabled)", "Enable (Workspace) (disabled)", "---", "Disable", "Disable (Workspace) (disabled)", "---"];
- let context = ["---", "Copy", "Copy Extension ID", "---", "Settings"];
+ let context = ["---", "Copy", "Copy Extension ID", "---", "Settings", "Apply Extension to all Profiles"];
assert_eq!(menu(&configured), [&enablement[..], &["Auto Update", "Auto Update (Publisher) (disabled)", "---", "Install Specific Version... (disabled)", "Uninstall"], &context[..], &["---", "Report Extension"]].concat());
assert_eq!(menu(&builtin), [&enablement[..], &["Install Specific Version... (disabled)", "Uninstall (disabled)", "---", "Copy", "Copy Extension ID"]].concat());
+ let language_pack = Extension { local: Some(ScannedExtension { id: "test.pack".into(), location: app_root.clone(), description: json!({ "contributes": { "localizations": [{ "languageId": "de" }] } }) }), ..configured.clone() };
+ assert!(!menu(&language_pack).contains(&"Apply Extension to all Profiles".to_owned()), "a language pack is always application scoped");
+ let scoped = Extension { local: Some(ScannedExtension { id: "test.scoped".into(), location: app_root.clone(), description: json!({ "isApplicationScoped": true }) }), ..configured.clone() };
+ let actions = workbench.update_in(cx, |workbench, window, _| workbench.manage_extension_actions(&scoped, false, window));
+ assert!(actions.iter().any(|action| matches!(action, MenuAction::Command { id, checked: true, .. } if id == "workbench.extensions.action.toggleApplyToAllProfiles")));
}
/// extensions.contribution.ts `SetColorThemeAction` and `SetFileIconThemeAction` items: shown for an installed
diff --git a/native/crates/app/src/workbench/extensions_view.rs b/native/crates/app/src/workbench/extensions_view.rs
index f360fb042ba..f6f795af878 100644
--- a/native/crates/app/src/workbench/extensions_view.rs
+++ b/native/crates/app/src/workbench/extensions_view.rs
@@ -7,6 +7,7 @@ use std::collections::HashMap;
use std::sync::Arc;
use std::time::Duration;
+use anyhow::Context as _;
use exthost::extension_management::{Job, UserExtensions, add_user_extensions};
use exthost::gallery::{ExtensionInfo, Gallery, GalleryExtension, QueryOptions};
use exthost::scan::ScannedExtension;
@@ -337,6 +338,35 @@ impl Workbench {
scanned
}
+ /// extensionsWorkbenchService.ts `toggleApplyExtensionToAllProfiles`: the extension and its pack members, except
+ /// language packs and built-ins, change scope with it.
+ fn toggle_apply_extension_to_all_profiles(&mut self, id: &str) -> anyhow::Result<()> {
+ let local = self.local_extensions();
+ let Some(extension) = local.iter().find(|extension| extension.identifier().id.eq_ignore_ascii_case(id)) else { return Ok(()) };
+ let mut ids = vec![extension.identifier().id];
+ let mut index = 0;
+ // `getAllPackedExtensions`: the pack members, theirs, and so on.
+ while index < ids.len() {
+ let packed = local.iter().find(|extension| extension.identifier().id.eq_ignore_ascii_case(&ids[index])).and_then(|extension| extension.local.as_ref());
+ for member in packed.map(|scanned| crate::cli_process::string_list(&scanned.description["extensionPack"])).unwrap_or_default() {
+ if !ids.iter().any(|id| id.eq_ignore_ascii_case(&member)) {
+ ids.push(member);
+ }
+ }
+ index += 1;
+ }
+ let user = self.extensions_viewlet.user.as_ref().context("The user extensions are not read.")?;
+ for id in &ids {
+ let Some(extension) = local.iter().find(|extension| extension.identifier().id.eq_ignore_ascii_case(id)) else { continue };
+ if extension.local.is_none() || extension.is_language_pack() || extension.is_builtin() {
+ continue;
+ }
+ user.toggle_application_scope(id)?;
+ }
+ self.rescan_installed_extensions();
+ Ok(())
+ }
+
/// The `Extension`s of the installed list (`extensionsWorkbenchService.local`) with their enablement and runtime state.
pub fn local_extensions(&self) -> Vec<Extension> {
self.local_extensions_where(|_| true)
@@ -632,6 +662,13 @@ impl Workbench {
let id = args.first().and_then(Value::as_str).unwrap_or_default();
workbench.execute_command("workbench.action.openGlobalKeybindings", vec![json!(format!("@ext:{id}"))], window, cx)
});
+ self.commands.register("workbench.extensions.action.toggleApplyToAllProfiles", |workbench, args, _, _| {
+ let id = args.first().and_then(Value::as_str).unwrap_or_default();
+ match workbench.toggle_apply_extension_to_all_profiles(id) {
+ Ok(()) => Outcome::done(),
+ Err(error) => Outcome::error(format!("{error:#}")),
+ }
+ });
let theme_actions = [
("workbench.extensions.action.setColorTheme", ThemeType::Color),
("workbench.extensions.action.setFileIconTheme", ThemeType::FileIcon),
diff --git a/native/crates/app/src/workbench/extensions_view/tests.rs b/native/crates/app/src/workbench/extensions_view/tests.rs
index dba0dc293fd..dfd5b7259b2 100644
--- a/native/crates/app/src/workbench/extensions_view/tests.rs
+++ b/native/crates/app/src/workbench/extensions_view/tests.rs
@@ -114,3 +114,45 @@ fn an_arriving_icon_redraws_the_rows_view_alone(cx: &mut gpui::TestAppContext) {
assert_eq!(side_bar_notified.get(), 1, "the row's view draws the icon");
assert_eq!(workbench_notified.get(), 0, "the workbench stays unnotified");
}
+
+/// extensionsWorkbenchService.ts `toggleApplyExtensionToAllProfiles`: the pack members change scope with the pack,
+/// a language pack among them stays as it is.
+#[gpui::test]
+fn apply_to_all_profiles_toggles_the_pack_and_its_members(cx: &mut gpui::TestAppContext) {
+ let root = std::env::temp_dir().join(format!("apply-to-all-profiles-{}", std::process::id()));
+ let _ = std::fs::remove_dir_all(&root);
+ let user = UserExtensions::new(root.join("extensions"), "1.147.0");
+ let manifests = [
+ ("pack", serde_json::json!({ "extensionPack": ["port.member", "port.de"] })),
+ ("member", serde_json::json!({})),
+ ("de", serde_json::json!({ "contributes": { "localizations": [{ "languageId": "de" }] } })),
+ ];
+ for (name, extra) in manifests {
+ let folder = root.join(name);
+ std::fs::create_dir_all(&folder).unwrap();
+ let mut manifest = serde_json::json!({ "name": name, "publisher": "port", "version": "1.0.0", "engines": { "vscode": "^1.80.0" } });
+ manifest.as_object_mut().unwrap().extend(extra.as_object().unwrap().clone());
+ std::fs::write(folder.join("package.json"), manifest.to_string()).unwrap();
+ user.install_folder(&folder).unwrap();
+ }
+ let app_root = std::path::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();
+ let (workbench, cx) = cx.add_window_view(|_, cx| {
+ let mut workbench = Workbench::new(theme, app_root.clone(), None, crate::languages::Languages::new(&[]), crate::default_settings(), crate::host_sync::HostSync::new(std::sync::mpsc::channel().0), cx);
+ workbench.extensions_viewlet.user = Some(user.clone_for_profile());
+ workbench.rescan_installed_extensions();
+ workbench
+ });
+ let scoped = |workbench: &Workbench| {
+ let mut scoped: Vec<_> = workbench.extensions_viewlet.installed.iter().filter(|extension| extension.description["isApplicationScoped"] == true).map(|extension| extension.id.to_lowercase()).collect();
+ scoped.sort();
+ scoped
+ };
+ assert_eq!(workbench.read_with(cx, |workbench, _| scoped(workbench)), ["port.de"]);
+ workbench.update_in(cx, |workbench, window, cx| drop(workbench.execute_command("workbench.extensions.action.toggleApplyToAllProfiles", vec![serde_json::json!("port.pack")], window, cx)));
+ assert_eq!(workbench.read_with(cx, |workbench, _| scoped(workbench)), ["port.de", "port.member", "port.pack"]);
+ workbench.update_in(cx, |workbench, window, cx| drop(workbench.execute_command("workbench.extensions.action.toggleApplyToAllProfiles", vec![serde_json::json!("port.pack")], window, cx)));
+ assert_eq!(workbench.read_with(cx, |workbench, _| scoped(workbench)), ["port.de"]);
+ std::fs::remove_dir_all(&root).unwrap();
+}
diff --git a/native/crates/exthost/src/extension_management.rs b/native/crates/exthost/src/extension_management.rs
index 98e60ac3c6f..e44e9cf7c49 100644
--- a/native/crates/exthost/src/extension_management.rs
+++ b/native/crates/exthost/src/extension_management.rs
@@ -41,11 +41,18 @@ impl UserExtensions {
UserExtensions { folder: self.folder.clone(), extensions_file: self.extensions_file.clone(), profiles_home: self.profiles_home.clone(), product_version: self.product_version.clone() }
}
- /// `scanUserExtensions` without invalid extensions: the profile's entries, the latest version of each id.
+ /// `scanUserExtensions` without invalid extensions: the profile's entries, with the default profile's application
+ /// scoped ones in another profile (`scanExtensionsFromProfile`), one per id as `dedupExtensions` picks it.
/// An extension that fails validation is left out with its reason on stderr, as the scanner logs it.
pub fn scan(&self) -> anyhow::Result<Vec<ScannedExtension>> {
+ let mut entries = self.profile()?;
+ let default_file = self.default_profile_file();
+ if self.extensions_file != default_file {
+ entries.retain(|entry| !is_application_scoped(entry));
+ entries.extend(self.read_profile(&default_file)?.into_iter().filter(|entry| entry["metadata"]["isBuiltin"] == true || is_application_scoped(entry)));
+ }
let mut extensions: Vec<ScannedExtension> = Vec::new();
- for entry in self.profile()? {
+ for entry in entries {
let location = self.entry_location(&entry);
let extension = match self.scan_valid(&location, &entry["metadata"]) {
Ok(extension) => extension,
@@ -55,7 +62,7 @@ impl UserExtensions {
}
};
match extensions.iter().position(|other| other.id.eq_ignore_ascii_case(&extension.id)) {
- Some(index) if version_of(&extensions[index]) < version_of(&extension) => extensions[index] = extension,
+ Some(index) if replaces(&extensions[index], &extension) => extensions[index] = extension,
Some(_) => {}
None => extensions.push(extension),
}
@@ -108,8 +115,14 @@ impl UserExtensions {
if key.contains(['/', '\\']) || key.starts_with('.') || key.contains("..") {
bail!("VSIX invalid: '{key}' is not a valid extension folder name.");
}
+ // `installExtensions`: an application scoped extension installs into the default profile, so the one it
+ // replaces is the default profile's application scoped entry before the profile's own.
+ let default_file = self.default_profile_file();
+ let defaults = self.read_profile(&default_file)?;
let profile = self.profile()?;
- let existing = profile.iter().find(|entry| entry_id(entry).eq_ignore_ascii_case(&id));
+ let same_id = |entry: &&Value| entry_id(entry).eq_ignore_ascii_case(&id);
+ let existing = defaults.iter().filter(|entry| is_application_scoped(entry)).find(same_id).or_else(|| profile.iter().find(same_id));
+ let application_scoped = is_language_pack(manifest) || existing.is_some_and(|existing| is_application_scoped(existing) || existing["metadata"]["isBuiltin"] == true);
let mut metadata = Map::new();
if let Some(existing) = existing {
@@ -117,6 +130,9 @@ impl UserExtensions {
metadata.insert(key.into(), json!(existing["metadata"][key] == true));
}
}
+ if application_scoped {
+ metadata.insert("isApplicationScoped".into(), json!(true));
+ }
metadata.insert("installedTimestamp".into(), json!(now_millis()));
metadata.insert("source".into(), json!(if gallery.is_some() { "gallery" } else { "vsix" }));
let location = self.folder.join(&key);
@@ -153,22 +169,57 @@ impl UserExtensions {
}
}
}
- self.add_to_profile(&id, version, &location, Value::Object(metadata))?;
+ let file = if application_scoped { &default_file } else { &self.extensions_file };
+ self.add_to_profile(file, &id, version, &location, Value::Object(metadata))?;
self.scan_valid(&location, &Value::Null)
}
/// `UninstallExtensionInProfileTask`, then the folder is marked for removal as no profile has it
/// (ExtensionsWatcher `deleteExtensions`); the next start deletes it.
+ /// An application scoped extension leaves the default profile, so every profile.
pub fn uninstall(&self, id: &str) -> anyhow::Result<()> {
- let mut profile = self.profile()?;
+ let default_file = self.default_profile_file();
+ let application_scoped = self.read_profile(&default_file)?.iter().any(|entry| is_application_scoped(entry) && entry_id(entry).eq_ignore_ascii_case(id));
+ let file = if application_scoped { &default_file } else { &self.extensions_file };
+ let mut profile = self.read_profile(file)?;
let removed: Vec<Value> = profile.extract_if(.., |entry| entry_id(entry).eq_ignore_ascii_case(id)).collect();
if removed.is_empty() {
bail!("Extension '{id}' is not installed.");
}
- self.write_profile(&profile)?;
+ self.write_profile(file, &profile)?;
self.set_for_removal(&removed)
}
+ /// `toggleApplicationScope` from this profile: an application scoped extension stays in the default profile and
+ /// this one only; another one joins the default profile as application scoped (`copyExtension`).
+ pub fn toggle_application_scope(&self, id: &str) -> anyhow::Result<()> {
+ let default_file = self.default_profile_file();
+ let mut defaults = self.read_profile(&default_file)?;
+ if let Some(entry) = defaults.iter_mut().find(|entry| is_application_scoped(entry) && entry_id(entry).eq_ignore_ascii_case(id)) {
+ entry["metadata"]["isApplicationScoped"] = json!(false);
+ let entry = entry.clone();
+ self.write_profile(&default_file, &defaults)?;
+ if self.extensions_file != default_file {
+ self.copy_to_profile(&self.extensions_file, &entry, false)?;
+ }
+ return Ok(());
+ }
+ let profile = self.profile()?;
+ let entry = profile.iter().find(|entry| entry_id(entry).eq_ignore_ascii_case(id)).with_context(|| format!("Extension '{id}' is not installed."))?;
+ self.copy_to_profile(&default_file, entry, true)
+ }
+
+ /// `copyExtension`: the entry joins the profile `file` with the metadata of the entry it replaces, its own and
+ /// `isApplicationScoped`.
+ fn copy_to_profile(&self, file: &Path, entry: &Value, application_scoped: bool) -> anyhow::Result<()> {
+ let id = entry_id(entry);
+ let target = self.read_profile(file)?.into_iter().find(|target| entry_id(target).eq_ignore_ascii_case(id));
+ let mut metadata = target.and_then(|target| target["metadata"].as_object().cloned()).unwrap_or_default();
+ metadata.extend(entry["metadata"].as_object().cloned().unwrap_or_default());
+ metadata.insert("isApplicationScoped".into(), json!(application_scoped));
+ self.add_to_profile(file, id, entry["version"].as_str().unwrap_or_default(), &self.entry_location(entry), Value::Object(metadata))
+ }
+
/// `ExtensionsScanner.cleanUp` at startup: deletes `.vsctmp` folders and the folders marked as removed.
pub fn clean_up(&self) -> anyhow::Result<()> {
let Ok(children) = std::fs::read_dir(&self.folder) else { return Ok(()) };
@@ -192,9 +243,12 @@ impl UserExtensions {
/// The profile's entries; without `extensions.json` the default profile adds the folder's extensions first
/// (`doInitializeDefaultProfileExtensions`), another profile starts empty.
fn profile(&self) -> anyhow::Result<Vec<Value>> {
- let file = &self.extensions_file;
+ self.read_profile(&self.extensions_file)
+ }
+
+ fn read_profile(&self, file: &Path) -> anyhow::Result<Vec<Value>> {
match std::fs::read_to_string(file) {
- Err(error) if error.kind() == std::io::ErrorKind::NotFound && *file != self.folder.join("extensions.json") => Ok(Vec::new()),
+ Err(error) if error.kind() == std::io::ErrorKind::NotFound && file != self.default_profile_file() => Ok(Vec::new()),
Ok(text) if text.trim().is_empty() => Ok(Vec::new()),
Ok(text) => match serde_json::from_str(&text)? {
Value::Array(entries) => Ok(entries),
@@ -219,27 +273,32 @@ impl UserExtensions {
entries.push(profile_entry(&extension.id.to_lowercase(), &version, &child.path(), metadata));
}
if self.folder.is_dir() {
- self.write_profile(&entries)?;
+ self.write_profile(&self.default_profile_file(), &entries)?;
}
Ok(entries)
}
/// `addExtensionsToProfile`: other versions of the id leave the profile and are marked for removal.
- fn add_to_profile(&self, id: &str, version: &str, location: &Path, metadata: Value) -> anyhow::Result<()> {
- let mut profile = self.profile()?;
+ fn add_to_profile(&self, file: &Path, id: &str, version: &str, location: &Path, metadata: Value) -> anyhow::Result<()> {
+ let mut profile = self.read_profile(file)?;
let replaced: Vec<Value> = profile.extract_if(.., |entry| entry_id(entry).eq_ignore_ascii_case(id)).collect();
profile.push(profile_entry(id, version, location, metadata));
- self.write_profile(&profile)?;
+ self.write_profile(file, &profile)?;
let other_versions: Vec<Value> = replaced.into_iter().filter(|entry| self.entry_location(entry) != location).collect();
self.set_for_removal(&other_versions)
}
- fn write_profile(&self, entries: &[Value]) -> anyhow::Result<()> {
+ fn write_profile(&self, file: &Path, entries: &[Value]) -> anyhow::Result<()> {
std::fs::create_dir_all(&self.folder)?;
- if let Some(parent) = self.extensions_file.parent() {
+ if let Some(parent) = file.parent() {
std::fs::create_dir_all(parent)?;
}
- Ok(std::fs::write(&self.extensions_file, serde_json::to_string(entries)?)?)
+ Ok(std::fs::write(file, serde_json::to_string(entries)?)?)
+ }
+
+ /// The default profile's `extensions.json`, which also lists the application scoped extensions of every profile.
+ fn default_profile_file(&self) -> PathBuf {
+ self.folder.join("extensions.json")
}
fn entry_location(&self, entry: &Value) -> PathBuf {
@@ -273,6 +332,7 @@ impl UserExtensions {
}
description["isBuiltin"] = json!(metadata["isBuiltin"] == true);
description["isUserBuiltin"] = json!(metadata["isBuiltin"] == true);
+ description["isApplicationScoped"] = json!(metadata["isApplicationScoped"] == true);
description["preRelease"] = json!(metadata["preRelease"] == true);
Ok(extension)
}
@@ -469,6 +529,25 @@ fn entry_id(entry: &Value) -> &str {
entry["identifier"]["id"].as_str().unwrap_or_default()
}
+/// `dedupExtensions` `pick` between two user copies of one id: the application scoped one, else the later version.
+fn replaces(existing: &ScannedExtension, extension: &ScannedExtension) -> bool {
+ let scoped = |extension: &ScannedExtension| extension.description["isApplicationScoped"] == true;
+ match (scoped(existing), scoped(extension)) {
+ (true, false) => false,
+ (false, true) => true,
+ _ => version_of(existing) < version_of(extension),
+ }
+}
+
+fn is_application_scoped(entry: &Value) -> bool {
+ entry["metadata"]["isApplicationScoped"] == true
+}
+
+/// extensions.ts `isApplicationScopedExtension`: a language pack applies to every profile.
+fn is_language_pack(manifest: &Value) -> bool {
+ manifest["contributes"]["localizations"].as_array().is_some_and(|localizations| !localizations.is_empty())
+}
+
fn version_of(extension: &ScannedExtension) -> Option<semver::Version> {
semver_version(extension.description["version"].as_str().unwrap_or_default())
}
diff --git a/native/crates/exthost/src/extension_management/tests.rs b/native/crates/exthost/src/extension_management/tests.rs
index a4a8064c807..9a7def6ae65 100644
--- a/native/crates/exthost/src/extension_management/tests.rs
+++ b/native/crates/exthost/src/extension_management/tests.rs
@@ -154,6 +154,52 @@ fn another_profile_starts_empty_and_keeps_a_folder_in_use() {
assert_eq!(other.removed().unwrap().len(), 1);
}
+/// extensionsScannerService.ts `scanExtensionsFromProfile` and abstractExtensionManagementService.ts
+/// `toggleApplicationScope`: an application scoped extension of the default profile is in every profile.
+#[test]
+fn an_application_scoped_extension_is_in_every_profile() {
+ let fixture = Fixture::new("application-scope");
+ let profiles_home = fixture.root.join("User/profiles");
+ let other = UserExtensions { extensions_file: profiles_home.join("p1/extensions.json"), profiles_home: Some(profiles_home.clone()), ..UserExtensions::new(fixture.extensions.folder.clone(), "1.147.0") };
+ std::fs::create_dir_all(&fixture.extensions.folder).unwrap();
+ assert!(fixture.extensions.scan().unwrap().is_empty());
+ other.install_vsix(&fixture.vsix("1.0.0", "^1.80.0")).unwrap();
+ assert!(fixture.extensions.scan().unwrap().is_empty());
+
+ other.toggle_application_scope("port.sample").unwrap();
+ let scoped = fixture.extensions.scan().unwrap();
+ assert_eq!(scoped.iter().map(|extension| (extension.id.as_str(), &extension.description["isApplicationScoped"])).collect::<Vec<_>>(), [("Port.Sample", &json!(true))]);
+ assert_eq!(other.scan().unwrap()[0].description["isApplicationScoped"], json!(true), "the default profile's copy wins");
+ let third = UserExtensions { extensions_file: profiles_home.join("p2/extensions.json"), ..other.clone_for_profile() };
+ assert_eq!(third.scan().unwrap().len(), 1);
+
+ other.toggle_application_scope("port.sample").unwrap();
+ assert!(third.scan().unwrap().is_empty());
+ assert_eq!(other.scan().unwrap()[0].description["isApplicationScoped"], json!(false));
+ assert_eq!(fixture.extensions.scan().unwrap()[0].description["isApplicationScoped"], json!(false), "the default profile keeps it, unscoped");
+
+ fixture.extensions.toggle_application_scope("port.sample").unwrap();
+ assert_eq!(third.scan().unwrap().len(), 1);
+ third.uninstall("port.sample").unwrap();
+ assert!(fixture.extensions.scan().unwrap().is_empty());
+ assert!(third.scan().unwrap().is_empty());
+}
+
+/// abstractExtensionManagementService.ts `installExtensions`: a language pack installs into the default profile.
+#[test]
+fn a_language_pack_installs_for_every_profile() {
+ let fixture = Fixture::new("language-pack");
+ let manifest = json!({ "name": "pack", "publisher": "Port", "version": "1.0.0", "engines": { "vscode": "^1.80.0" }, "contributes": { "localizations": [{ "languageId": "de" }] } }).to_string();
+ let vsix = fixture.root.join("pack.vsix");
+ std::fs::write(&vsix, write_stored(&[("extension/package.json", manifest.as_bytes())])).unwrap();
+ let profiles_home = fixture.root.join("User/profiles");
+ let other = UserExtensions { extensions_file: profiles_home.join("p1/extensions.json"), profiles_home: Some(profiles_home), ..UserExtensions::new(fixture.extensions.folder.clone(), "1.147.0") };
+ other.install_vsix(&vsix).unwrap();
+ assert_eq!(fixture.profile_ids(), [("port.pack".to_owned(), "port.pack-1.0.0".to_owned())]);
+ assert_eq!(fixture.extensions.scan().unwrap()[0].description["isApplicationScoped"], json!(true));
+ assert!(other.profile().unwrap().is_empty());
+}
+
#[test]
fn skips_an_invalid_extension() {
let fixture = Fixture::new("invalid");
diff --git a/port/notes.md b/port/notes.md
index 8b0d8af0bfb..406a335d899 100644
--- a/port/notes.md
+++ b/port/notes.md
@@ -690,6 +690,7 @@ Scope (milestone 18): extension management on disk with VSIX install and uninsta
- Workbench strings: upstream looks messages up by module and key. Command Palette items carry the reference call's `module#key`: port/tools/ref-commands runs the reference from an APFS clone (ref-nls-clone.ts, in the temp folder, vscode-ref untouched) whose out/vs/nls.js tags each `localize`/`localize2` result with its key and the calling module from the stack, and `nls::localize_key` reads `contents[module][key]` of the pack. The same dump's `nlsKeys` map, per menu bar menu (by `MenuId` name), view and view container id, each item text or title to its key; `nls::localize_in(scope, text)` translates the menu bar's items (in `menu_actions`), side bar titles and pane headers through it, and a text with no key in its scope (a folder name, an extension's view) stays as it is. The top-level menus, the app menu and the Window menu take electron-main/menubar.ts's own keys (`main_label` in workbench/menubar.rs). A palette item without a key falls back to build.rs's index of every `localize`/`localize2` of src/vs (module, key, message): shortcut: there a message two modules translate differently gets the first module's text. shortcut: other surfaces (context menus, dialogs, view contents) still show English.
- The restart for the display language spawns the same binary with its arguments and working folder once this process exits; gpui's `App::restart` uses `open`, which loses the working folder of an unbundled binary.
- ExtensionsWatcher (extensionsWatcher.ts, `onDidChangeExtensionsByAnotherSource`): the workbench watches the folder of the profile's `extensions.json` (a profile switch moves the watch) and reads it again 100 ms after its last change; enabled user extensions the host does not run start, running user extensions no longer installed stop, both as one `Job::Delta`. What this window installs already runs when its change arrives, so it makes no delta. A read that fails (a half-written file) makes no delta. main.rs creates the extensions folder at startup as main.ts `initServices` does, so the watch has a folder from the first run. extensions-check runs the release binary as the CLI against the running window's user data dir.
+- Application scope (abstractExtensionManagementService.ts `installExtensions`, `toggleApplicationScope`; extensionsScannerService.ts `scanExtensionsFromProfile`): an application scoped extension is an entry of the default profile's `extensions.json` with `isApplicationScoped`, and `UserExtensions::scan` of another profile adds it, the scoped copy winning over the profile's own. A language pack, or an update of an application scoped or user built-in extension, installs there; Apply Extension to all Profiles (`workbench.extensions.action.toggleApplyToAllProfiles`) moves the extension and its pack members in and out. shortcut: upstream also installs a gallery copy of a bundled (system) extension as application scoped; `UserExtensions` does not know the bundled ids, so that copy stays in the profile until an install takes the built-in list.
- `port/tools/extensions-check` needs a fresh `out-exthost`: `port/tools/build-exthost` first (a stale bundle fails the ESM check with "Cannot find package 'vscode'").
## Milestone 17: webviews and notebooks