Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #211832 #211913

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading