Skip to content

Commit

Permalink
Enable workspace extensions (#210466)
Browse files Browse the repository at this point in the history
* Enable workspace extensions

* fix
  • Loading branch information
sandy081 authored Apr 16, 2024
1 parent 5ccc2db commit 55f2a29
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 58 deletions.
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@
"[github-issues]": {
"editor.wordWrap": "on"
},
"extensions.experimental.supportWorkspaceExtensions": true,
"css.format.spaceAroundSelectorSeparator": true,
"inlineChat.mode": "live",
"typescript.enablePromptUseWorkspaceTsdk": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,13 @@ export class WorkspaceRecommendations extends ExtensionRecommendations {
this._register(this.fileService.watch(this.uriIdentityService.extUri.joinPath(folder.uri, WORKSPACE_EXTENSIONS_FOLDER)));
}

if (this.workbenchExtensionManagementService.isWorkspaceExtensionsSupported()) {
this._register(this.fileService.onDidFilesChange(e => {
if (this.contextService.getWorkspace().folders.some(folder =>
e.affects(this.uriIdentityService.extUri.joinPath(folder.uri, WORKSPACE_EXTENSIONS_FOLDER), FileChangeType.ADDED, FileChangeType.DELETED))
) {
this.onDidChangeWorkspaceExtensionsScheduler.schedule();
}
}));
}
this._register(this.fileService.onDidFilesChange(e => {
if (this.contextService.getWorkspace().folders.some(folder =>
e.affects(this.uriIdentityService.extUri.joinPath(folder.uri, WORKSPACE_EXTENSIONS_FOLDER), FileChangeType.ADDED, FileChangeType.DELETED))
) {
this.onDidChangeWorkspaceExtensionsScheduler.schedule();
}
}));
}

private async onDidChangeWorkspaceExtensionsFolders(): Promise<void> {
Expand All @@ -75,9 +73,6 @@ export class WorkspaceRecommendations extends ExtensionRecommendations {
}

private async fetchWorkspaceExtensions(): Promise<URI[]> {
if (!this.workbenchExtensionManagementService.isWorkspaceExtensionsSupported()) {
return [];
}
const workspaceExtensions: URI[] = [];
for (const workspaceFolder of this.contextService.getWorkspace().folders) {
const extensionsLocaiton = this.uriIdentityService.extUri.joinPath(workspaceFolder.uri, WORKSPACE_EXTENSIONS_FOLDER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ suite('ExtensionRecommendationsService Test', () => {
async canInstall() { return true; },
async getExtensionsControlManifest() { return { malicious: [], deprecated: {}, search: [] }; },
async getTargetPlatform() { return getTargetPlatform(platform, arch); },
isWorkspaceExtensionsSupported() { return false; },
});
instantiationService.stub(IExtensionService, {
onDidChangeExtensions: Event.None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export interface IWorkbenchExtensionManagementService extends IProfileAwareExten
onDidChangeProfile: Event<DidChangeProfileForServerEvent>;
onDidEnableExtensions: Event<IExtension[]>;

isWorkspaceExtensionsSupported(): boolean;
getExtensions(locations: URI[]): Promise<IResourceExtension[]>;
getInstalledWorkspaceExtensions(includeInvalid: boolean): Promise<ILocalExtension[]>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ILocalExtension, IGalleryExtension, IExtensionIdentifier, IExtensionsControlManifest, IExtensionGalleryService, InstallOptions, UninstallOptions, InstallExtensionResult, ExtensionManagementError, ExtensionManagementErrorCode, Metadata, InstallOperation, EXTENSION_INSTALL_SYNC_CONTEXT, InstallExtensionInfo,
IProductVersion
} from 'vs/platform/extensionManagement/common/extensionManagement';
import { DidChangeProfileForServerEvent, DidUninstallExtensionOnServerEvent, extensionsConfigurationNodeBase, IExtensionManagementServer, IExtensionManagementServerService, InstallExtensionOnServerEvent, IResourceExtension, IWorkbenchExtensionManagementService, UninstallExtensionOnServerEvent } from 'vs/workbench/services/extensionManagement/common/extensionManagement';
import { DidChangeProfileForServerEvent, DidUninstallExtensionOnServerEvent, IExtensionManagementServer, IExtensionManagementServerService, InstallExtensionOnServerEvent, IResourceExtension, IWorkbenchExtensionManagementService, UninstallExtensionOnServerEvent } from 'vs/workbench/services/extensionManagement/common/extensionManagement';
import { ExtensionType, isLanguagePackExtension, IExtensionManifest, getWorkspaceSupportTypeMessage, TargetPlatform } from 'vs/platform/extensions/common/extensions';
import { URI } from 'vs/base/common/uri';
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
Expand Down Expand Up @@ -38,8 +38,6 @@ import { IExtensionsScannerService, IScannedExtension } from 'vs/platform/extens
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { Registry } from 'vs/platform/registry/common/platform';
import { ConfigurationScope, Extensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';

export class ExtensionManagementService extends Disposable implements IWorkbenchExtensionManagementService {

Expand All @@ -64,7 +62,7 @@ export class ExtensionManagementService extends Disposable implements IWorkbench

protected readonly servers: IExtensionManagementServer[] = [];

private readonly workspaceExtensionManagementService?: WorkspaceExtensionsManagementService;
private readonly workspaceExtensionManagementService: WorkspaceExtensionsManagementService;

constructor(
@IExtensionManagementServerService protected readonly extensionManagementServerService: IExtensionManagementServerService,
Expand All @@ -85,27 +83,8 @@ export class ExtensionManagementService extends Disposable implements IWorkbench
) {
super();

if (productService.quality !== 'stable') {
Registry.as<IConfigurationRegistry>(Extensions.Configuration)
.registerConfiguration({
...extensionsConfigurationNodeBase,
properties: {
'extensions.experimental.supportWorkspaceExtensions': {
type: 'boolean',
description: localize('extensions.experimental.supportWorkspaceExtensions', "Enables support for workspace specific local extensions."),
default: false,
scope: ConfigurationScope.APPLICATION
}
}
});
}

if (this.productService.quality !== 'stable' && this.configurationService.getValue('extensions.experimental.supportWorkspaceExtensions') === true) {
this.workspaceExtensionManagementService = this._register(this.instantiationService.createInstance(WorkspaceExtensionsManagementService));
this.onDidEnableExtensions = this.workspaceExtensionManagementService.onDidChangeInvalidExtensions;
} else {
this.onDidEnableExtensions = Event.None;
}
this.workspaceExtensionManagementService = this._register(this.instantiationService.createInstance(WorkspaceExtensionsManagementService));
this.onDidEnableExtensions = this.workspaceExtensionManagementService.onDidChangeInvalidExtensions;

if (this.extensionManagementServerService.localExtensionManagementServer) {
this.servers.push(this.extensionManagementServerService.localExtensionManagementServer);
Expand Down Expand Up @@ -149,10 +128,6 @@ export class ExtensionManagementService extends Disposable implements IWorkbench
}
}

isWorkspaceExtensionsSupported(): boolean {
return !!this.workspaceExtensionManagementService;
}

async getInstalled(type?: ExtensionType, profileLocation?: URI, productVersion?: IProductVersion): Promise<ILocalExtension[]> {
const result: ILocalExtension[] = [];
await Promise.all(this.servers.map(async server => {
Expand Down Expand Up @@ -430,13 +405,10 @@ export class ExtensionManagementService extends Disposable implements IWorkbench
}

async getExtensions(locations: URI[]): Promise<IResourceExtension[]> {
if (!this.workspaceExtensionManagementService) {
return [];
}
const scannedExtensions = await this.extensionsScannerService.scanMultipleExtensions(locations, ExtensionType.User, { includeInvalid: true });
const result: IResourceExtension[] = [];
await Promise.all(scannedExtensions.map(async scannedExtension => {
const workspaceExtension = await this.workspaceExtensionManagementService?.toLocalWorkspaceExtension(scannedExtension);
const workspaceExtension = await this.workspaceExtensionManagementService.toLocalWorkspaceExtension(scannedExtension);
if (workspaceExtension) {
result.push({
identifier: workspaceExtension.identifier,
Expand All @@ -451,18 +423,14 @@ export class ExtensionManagementService extends Disposable implements IWorkbench
}

async getInstalledWorkspaceExtensions(includeInvalid: boolean): Promise<ILocalExtension[]> {
return this.workspaceExtensionManagementService?.getInstalled(includeInvalid) ?? [];
return this.workspaceExtensionManagementService.getInstalled(includeInvalid);
}

async installResourceExtension(extension: IResourceExtension, installOptions: InstallOptions): Promise<ILocalExtension> {
if (!installOptions.isWorkspaceScoped) {
return this.installFromLocation(extension.location);
}

if (!this.workspaceExtensionManagementService) {
throw new Error('Workspace Extensions are not supported');
}

this.logService.info(`Installing the extension ${extension.identifier.id} from ${extension.location.toString()} in workspace`);
const server = this.getWorkspaceExtensionsServer();
this._onInstallExtension.fire({
Expand Down Expand Up @@ -510,10 +478,6 @@ export class ExtensionManagementService extends Disposable implements IWorkbench
throw new Error('The extension is not a workspace extension');
}

if (!this.workspaceExtensionManagementService) {
throw new Error('Workspace Extensions are not supported');
}

this.logService.info(`Uninstalling the workspace extension ${extension.identifier.id} from ${extension.location.toString()}`);
const server = this.getWorkspaceExtensionsServer();
this._onUninstallExtension.fire({
Expand Down
1 change: 0 additions & 1 deletion src/vs/workbench/test/browser/workbenchTestServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2189,7 +2189,6 @@ export class TestWorkbenchExtensionManagementService implements IWorkbenchExtens
getInstalledWorkspaceExtensions(): Promise<ILocalExtension[]> { throw new Error('Method not implemented.'); }
installResourceExtension(): Promise<ILocalExtension> { throw new Error('Method not implemented.'); }
getExtensions(): Promise<IResourceExtension[]> { throw new Error('Method not implemented.'); }
isWorkspaceExtensionsSupported(): boolean { throw new Error('Method not implemented.'); }
}

export class TestUserDataProfileService implements IUserDataProfileService {
Expand Down

0 comments on commit 55f2a29

Please sign in to comment.