Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 authored May 6, 2024
1 parent 49101b1 commit 0699aca
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export interface IWorkbenchExtensionManagementService extends IProfileAwareExten
getExtensions(locations: URI[]): Promise<IResourceExtension[]>;
getInstalledWorkspaceExtensions(includeInvalid: boolean): Promise<ILocalExtension[]>;

canInstall(extension: IGalleryExtension | IResourceExtension): Promise<boolean>;

installVSIX(location: URI, manifest: IExtensionManifest, installOptions?: InstallOptions): Promise<ILocalExtension>;
installFromLocation(location: URI): Promise<ILocalExtension>;
installResourceExtension(extension: IResourceExtension, installOptions: InstallOptions): Promise<ILocalExtension>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -315,7 +319,14 @@ export class ExtensionManagementService extends Disposable implements IWorkbench
return Promise.reject('No Servers');
}

async canInstall(gallery: IGalleryExtension): Promise<boolean> {
async canInstall(extension: IGalleryExtension | IResourceExtension): Promise<boolean> {
if (isResourceExtension(extension)) {
return this.canInstallResourceExtension(extension);
}
return this.canInstallGalleryExtension(extension);
}

private async canInstallGalleryExtension(gallery: IGalleryExtension): Promise<boolean> {
if (this.extensionManagementServerService.localExtensionManagementServer
&& await this.extensionManagementServerService.localExtensionManagementServer.extensionManagementService.canInstall(gallery)) {
return true;
Expand All @@ -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<ILocalExtension> {
const server = this.getServer(extension);
if (!server) {
Expand Down Expand Up @@ -427,6 +451,9 @@ export class ExtensionManagementService extends Disposable implements IWorkbench
}

async installResourceExtension(extension: IResourceExtension, installOptions: InstallOptions): Promise<ILocalExtension> {
if (!this.canInstallResourceExtension(extension)) {
throw new Error('This extension cannot be installed in the current workspace.');
}
if (!installOptions.isWorkspaceScoped) {
return this.installFromLocation(extension.location);
}
Expand Down

0 comments on commit 0699aca

Please sign in to comment.