Visual Studio Code, rebuilt in Rust
Rust
feat(exthost): list a gallery extension's compatible versions
rokarture82810355834
diff --git a/native/crates/exthost/src/gallery.rs b/native/crates/exthost/src/gallery.rsindex ea45e9be560..98d06116553 100644--- a/native/crates/exthost/src/gallery.rs+++ b/native/crates/exthost/src/gallery.rs@@ -109,6 +109,16 @@ fn target_platform_label(platform: &str) -> &str {}}+/// `IGalleryExtensionVersion`.+#[derive(Debug, Clone, PartialEq)]+pub struct GalleryVersion {+ pub version: String,+ /// `lastUpdated`, an ISO date.+ pub date: String,+ pub is_pre_release_version: bool,+ pub target_platforms: Vec<&'static str>,+}+/// `IExtensionInfo`.#[derive(Debug, Clone, Default)]pub struct ExtensionInfo {@@ -330,6 +340,47 @@ impl Gallery {Ok(self.query_gallery_extensions(query, &criteria)?.0.into_iter().next())}+ /// `getAllCompatibleVersions` (`getVersions`): the versions this product can install, newest first, each number+ /// once with the platforms it is built for.+ pub fn get_all_compatible_versions(&self, id: &str, uuid: Option<&str>, include_pre_release: bool) -> anyhow::Result<Vec<GalleryVersion>> {+ let mut query = match uuid {+ Some(uuid) => Query::new(1).with_filter(filter::EXTENSION_ID, &[uuid.to_owned()]),+ None => Query::new(1).with_filter(filter::EXTENSION_NAME, &[id.to_owned()]),+ };+ query.flags = flag::INCLUDE_VERSIONS | flag::INCLUDE_CATEGORY_AND_TAGS | flag::INCLUDE_FILES | flag::INCLUDE_VERSION_PROPERTIES;+ let Some(raw) = self.query_raw_gallery_extensions(&query)?.0.into_iter().next() else { return Ok(Vec::new()) };+ let all_target_platforms = all_target_platforms(&raw);+ if is_not_web_extension_in_web_target_platform(&all_target_platforms, CURRENT_TARGET_PLATFORM) {+ return Ok(Vec::new());+ }+ let criteria = VersionCriteria { target_platform: CURRENT_TARGET_PLATFORM, compatible: true, version: if include_pre_release { VersionKind::Latest } else { VersionKind::Release } };+ let mut versions = Vec::new();+ for mut version in raw["versions"].as_array().cloned().unwrap_or_default() {+ if property(&version, "Microsoft.VisualStudio.Code.Engine").is_none_or(str::is_empty) {+ self.set_engine_if_not_exists(id, &mut version);+ }+ if self.is_valid_version(&version, &criteria, &all_target_platforms) {+ versions.push(version);+ }+ }+ sort_extension_versions(&mut versions, CURRENT_TARGET_PLATFORM);+ let mut result: Vec<GalleryVersion> = Vec::new();+ for version in &versions {+ let number = version["version"].as_str().unwrap_or_default();+ let target_platform = target_platform_of(version);+ match result.iter_mut().find(|existing| existing.version == number) {+ Some(existing) => existing.target_platforms.push(target_platform),+ None => result.push(GalleryVersion {+ version: number.to_owned(),+ date: version["lastUpdated"].as_str().unwrap_or_default().to_owned(),+ is_pre_release_version: is_pre_release_version(version),+ target_platforms: vec![target_platform],+ }),+ }+ }+ Ok(result)+ }+/// `extensionsWorkbenchService._install(id)` then `checkAndGetCompatibleVersion`: the gallery version to download.pub fn installable_extension(&self, id: &str, version: Option<&str>, pre_release: bool) -> anyhow::Result<GalleryExtension> {let info = ExtensionInfo { id: id.into(), uuid: None, version: version.map(Into::into), pre_release };diff --git a/native/crates/exthost/src/gallery/tests.rs b/native/crates/exthost/src/gallery/tests.rsindex 3bed49d57ae..12a2b327821 100644--- a/native/crates/exthost/src/gallery/tests.rs+++ b/native/crates/exthost/src/gallery/tests.rs@@ -192,3 +192,21 @@ fn dependencies_and_packs_come_along_recursively() {let ids: Vec<&str> = found.iter().map(|extension| extension.id.as_str()).collect();assert_eq!(ids, ["a.dep", "a.leaf", "a.member"]);}++/// extensionGalleryService.ts `getAllCompatibleVersions`: every version that fits the product, the pre-release ones+/// only when asked for.+#[test]+fn all_compatible_versions_follow_the_kind_and_the_engine() {+ let url = serve_gallery(vec![("a.yaml".to_owned(), gallery_entry("a.yaml", &[], &[]))]);+ let versions = |product_version: &str, include_pre_release| {+ let gallery = Gallery { service_url: url.clone(), product_version: product_version.into() };+ let found = gallery.get_all_compatible_versions("a.yaml", Some("uuid-a.yaml"), include_pre_release).unwrap();+ found.into_iter().map(|version| (version.version, version.is_pre_release_version, version.date)).collect::<Vec<_>>()+ };+ let release = ("2.0.0".to_owned(), false, "2026-10-16T01:46:39.843678Z".to_owned());+ assert_eq!(versions("1.147.0", false), [release.clone()]);+ assert_eq!(versions("1.147.0", true), [("2.1.2026112008".to_owned(), true, "2026-11-20T08:11:26.894036Z".to_owned()), release]);+ assert_eq!(versions("1.90.0", true), []);+ let unknown = Gallery { service_url: url, product_version: "1.147.0".into() };+ assert_eq!(unknown.get_all_compatible_versions("a.other", None, true).unwrap(), []);+}