From 0699acaaa3e2cd104e39326552b534244f2c8067 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Mon, 6 May 2024 16:05:20 +0200 Subject: [PATCH] fix #211832 (#211913) --- ...ensionRecommendationNotificationService.ts | 6 +++- .../extensions/browser/extensionsViews.ts | 6 +++- .../browser/extensionsWorkbenchService.ts | 4 +-- .../common/extensionManagement.ts | 2 ++ .../common/extensionManagementService.ts | 29 ++++++++++++++++++- 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/vs/workbench/contrib/extensions/browser/extensionRecommendationNotificationService.ts b/src/vs/workbench/contrib/extensions/browser/extensionRecommendationNotificationService.ts index 5fc9e11597a14..4152bf2f35130 100644 --- a/src/vs/workbench/contrib/extensions/browser/extensionRecommendationNotificationService.ts +++ b/src/vs/workbench/contrib/extensions/browser/extensionRecommendationNotificationService.ts @@ -444,7 +444,11 @@ export class ExtensionRecommendationNotificationService extends Disposable imple } if (resourceExtensions.length) { const extensions = await this.extensionsWorkbenchService.getResourceExtensions(resourceExtensions, true); - result.push(...extensions); + for (const extension of extensions) { + if (await this.extensionsWorkbenchService.canInstall(extension)) { + result.push(extension); + } + } } } return result; diff --git a/src/vs/workbench/contrib/extensions/browser/extensionsViews.ts b/src/vs/workbench/contrib/extensions/browser/extensionsViews.ts index f6451dd55c0b5..43d323c791439 100644 --- a/src/vs/workbench/contrib/extensions/browser/extensionsViews.ts +++ b/src/vs/workbench/contrib/extensions/browser/extensionsViews.ts @@ -910,7 +910,11 @@ export class ExtensionsListView extends ViewPane { } if (resourceExtensions.length) { const extensions = await this.extensionsWorkbenchService.getResourceExtensions(resourceExtensions, true); - result.push(...extensions); + for (const extension of extensions) { + if (await this.extensionsWorkbenchService.canInstall(extension)) { + result.push(extension); + } + } } } return result; diff --git a/src/vs/workbench/contrib/extensions/browser/extensionsWorkbenchService.ts b/src/vs/workbench/contrib/extensions/browser/extensionsWorkbenchService.ts index f3ef2fb217ccf..863b2e4aa34d2 100644 --- a/src/vs/workbench/contrib/extensions/browser/extensionsWorkbenchService.ts +++ b/src/vs/workbench/contrib/extensions/browser/extensionsWorkbenchService.ts @@ -1028,7 +1028,7 @@ export class ExtensionsWorkbenchService extends Disposable implements IExtension changedExtensions.push(...extensions); } if (workspaceExtensions.length) { - const extensions = await this.getResourceExtensions(workspaceExtensions.map(e => e.extensionLocation), true) + const extensions = await this.getResourceExtensions(workspaceExtensions.map(e => e.extensionLocation), true); changedExtensions.push(...extensions); } for (const changedExtension of changedExtensions) { @@ -1891,7 +1891,7 @@ export class ExtensionsWorkbenchService extends Disposable implements IExtension return false; } - if (extension.resourceExtension) { + if (extension.resourceExtension && await this.extensionManagementService.canInstall(extension.resourceExtension)) { return true; } diff --git a/src/vs/workbench/services/extensionManagement/common/extensionManagement.ts b/src/vs/workbench/services/extensionManagement/common/extensionManagement.ts index d17f98f886aff..f1c1a1ead5290 100644 --- a/src/vs/workbench/services/extensionManagement/common/extensionManagement.ts +++ b/src/vs/workbench/services/extensionManagement/common/extensionManagement.ts @@ -69,6 +69,8 @@ export interface IWorkbenchExtensionManagementService extends IProfileAwareExten getExtensions(locations: URI[]): Promise; getInstalledWorkspaceExtensions(includeInvalid: boolean): Promise; + canInstall(extension: IGalleryExtension | IResourceExtension): Promise; + installVSIX(location: URI, manifest: IExtensionManifest, installOptions?: InstallOptions): Promise; installFromLocation(location: URI): Promise; installResourceExtension(extension: IResourceExtension, installOptions: InstallOptions): Promise; diff --git a/src/vs/workbench/services/extensionManagement/common/extensionManagementService.ts b/src/vs/workbench/services/extensionManagement/common/extensionManagementService.ts index 8e69418b0cc25..f2cfce13a037e 100644 --- a/src/vs/workbench/services/extensionManagement/common/extensionManagementService.ts +++ b/src/vs/workbench/services/extensionManagement/common/extensionManagementService.ts @@ -39,6 +39,10 @@ import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storag import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; +function isResourceExtension(extension: any): extension is IResourceExtension { + return extension && !!(extension as IResourceExtension).manifest; +} + export class ExtensionManagementService extends Disposable implements IWorkbenchExtensionManagementService { declare readonly _serviceBrand: undefined; @@ -315,7 +319,14 @@ export class ExtensionManagementService extends Disposable implements IWorkbench return Promise.reject('No Servers'); } - async canInstall(gallery: IGalleryExtension): Promise { + async canInstall(extension: IGalleryExtension | IResourceExtension): Promise { + if (isResourceExtension(extension)) { + return this.canInstallResourceExtension(extension); + } + return this.canInstallGalleryExtension(extension); + } + + private async canInstallGalleryExtension(gallery: IGalleryExtension): Promise { if (this.extensionManagementServerService.localExtensionManagementServer && await this.extensionManagementServerService.localExtensionManagementServer.extensionManagementService.canInstall(gallery)) { return true; @@ -337,6 +348,19 @@ export class ExtensionManagementService extends Disposable implements IWorkbench return false; } + private canInstallResourceExtension(extension: IResourceExtension): boolean { + if (this.extensionManagementServerService.localExtensionManagementServer) { + return true; + } + if (this.extensionManagementServerService.remoteExtensionManagementServer && this.extensionManifestPropertiesService.canExecuteOnWorkspace(extension.manifest)) { + return true; + } + if (this.extensionManagementServerService.webExtensionManagementServer && this.extensionManifestPropertiesService.canExecuteOnWeb(extension.manifest)) { + return true; + } + return false; + } + async updateFromGallery(gallery: IGalleryExtension, extension: ILocalExtension, installOptions?: InstallOptions): Promise { const server = this.getServer(extension); if (!server) { @@ -427,6 +451,9 @@ export class ExtensionManagementService extends Disposable implements IWorkbench } async installResourceExtension(extension: IResourceExtension, installOptions: InstallOptions): Promise { + if (!this.canInstallResourceExtension(extension)) { + throw new Error('This extension cannot be installed in the current workspace.'); + } if (!installOptions.isWorkspaceScoped) { return this.installFromLocation(extension.location); }