提交 0a1d595a 编写于 作者: A Alex Dima

Use CommonExtensionService for the web

上级 c053e698
......@@ -20,7 +20,6 @@ import { IExtensionHostDebugParams, IDebugParams } from 'vs/platform/environment
import { IExtensionGalleryService, IQueryOptions, IGalleryExtension, InstallOperation, StatisticType, ITranslation, IGalleryExtensionVersion, IExtensionIdentifier, IReportedExtension, IExtensionManagementService, ILocalExtension, IGalleryMetadata, IExtensionTipsService, ExtensionRecommendationReason, IExtensionRecommendation, IExtensionEnablementService, EnablementState } from 'vs/platform/extensionManagement/common/extensionManagement';
import { IPager } from 'vs/base/common/paging';
import { IExtensionManifest, ExtensionType, ExtensionIdentifier, IExtension } from 'vs/platform/extensions/common/extensions';
import { NullExtensionService, IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { IURLHandler, IURLService } from 'vs/platform/url/common/url';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { ICommandService } from 'vs/platform/commands/common/commands';
......@@ -365,10 +364,10 @@ export class SimpleExtensionEnablementService implements IExtensionEnablementSer
readonly onEnablementChanged = Event.None;
readonly allUserExtensionsDisabled = true;
readonly allUserExtensionsDisabled = false;
getEnablementState(extension: IExtension): EnablementState {
return EnablementState.Disabled;
return EnablementState.Enabled;
}
canChangeEnablement(extension: IExtension): boolean {
......@@ -380,7 +379,7 @@ export class SimpleExtensionEnablementService implements IExtensionEnablementSer
}
isEnabled(extension: IExtension): boolean {
return false;
return true;
}
}
......@@ -484,14 +483,6 @@ registerSingleton(IExtensionManagementService, SimpleExtensionManagementService)
//#endregion
//#region Extensions
export class SimpleExtensionService extends NullExtensionService { }
registerSingleton(IExtensionService, SimpleExtensionService);
//#endregion
//#region Extension URL Handler
export const IExtensionUrlHandler = createDecorator<IExtensionUrlHandler>('inactiveExtensionUrlHandler');
......
......@@ -3,6 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { IExtensionEnablementService, IExtensionManagementService } from 'vs/platform/extensionManagement/common/extensionManagement';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
......@@ -10,33 +11,23 @@ import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteA
import { IRemoteAuthorityResolverService } from 'vs/platform/remote/common/remoteAuthorityResolver';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IWindowService } from 'vs/platform/windows/common/windows';
import { IExtensionService, IExtensionHostStarter } from 'vs/workbench/services/extensions/common/extensions';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { IFileService } from 'vs/platform/files/common/files';
import { IProductService } from 'vs/platform/product/common/product';
import { AbstractExtensionService, IExtensionScanner } from 'vs/workbench/services/extensions/common/abstractExtensionService';
import { CommonExtensionService } from 'vs/workbench/services/extensions/common/abstractExtensionService';
import { browserWebSocketFactory } from 'vs/platform/remote/browser/browserWebSocketFactory';
import { Translations, ILog } from 'vs/workbench/services/extensions/common/extensionPoints';
import { Event } from 'vs/base/common/event';
import { IMessagePassingProtocol } from 'vs/base/parts/ipc/common/ipc';
import { ExtensionHostProcessManager } from 'vs/workbench/services/extensions/common/extensionHostProcessManager';
import { RemoteExtensionHostClient, IInitDataProvider } from 'vs/workbench/services/extensions/common/remoteExtensionHostClient';
import { IRemoteAgentEnvironment } from 'vs/platform/remote/common/remoteAgentEnvironment';
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
class NullExtensionScanner implements IExtensionScanner {
readonly scannedExtensions: Promise<IExtensionDescription[]> = Promise.resolve([]);
readonly translationConfig: Promise<Translations>;
export class ExtensionService extends CommonExtensionService implements IExtensionService {
public async scanSingleExtension(path: string, isBuiltin: boolean, log: ILog): Promise<IExtensionDescription | null> {
return null;
}
public async startScanningExtensions(log: ILog): Promise<void> {
}
}
private _remoteExtensionsEnvironmentData: IRemoteAgentEnvironment | null;
export class ExtensionService extends AbstractExtensionService implements IExtensionService {
constructor(
@IInstantiationService instantiationService: IInstantiationService,
@INotificationService notificationService: INotificationService,
......@@ -53,8 +44,6 @@ export class ExtensionService extends AbstractExtensionService implements IExten
@IProductService productService: IProductService
) {
super(
new NullExtensionScanner(),
browserWebSocketFactory,
instantiationService,
notificationService,
environmentService,
......@@ -69,25 +58,55 @@ export class ExtensionService extends AbstractExtensionService implements IExten
fileService,
productService,
);
}
protected _createLocalExtHostProcessWorker(autoStart: boolean, extensions: Promise<IExtensionDescription[]>): IExtensionHostStarter {
return new class implements IExtensionHostStarter {
onExit = Event.None;
start(): Promise<IMessagePassingProtocol> | null {
return new Promise<IMessagePassingProtocol>((c, e) => {
this._remoteExtensionsEnvironmentData = null;
this._initialize();
}
private _createProvider(remoteAuthority: string): IInitDataProvider {
return {
remoteAuthority: remoteAuthority,
getInitData: () => {
return this.whenInstalledExtensionsRegistered().then(() => {
return this._remoteExtensionsEnvironmentData!;
});
}
getInspectPort(): number | undefined {
throw new Error('Method not implemented.');
}
dispose(): void {
throw new Error('Method not implemented.');
}
};
}
protected _createExtensionHosts(isInitialStart: boolean, initialActivationEvents: string[]): ExtensionHostProcessManager[] {
const result: ExtensionHostProcessManager[] = [];
const remoteAgentConnection = this._remoteAgentService.getConnection()!;
const remoteExtHostProcessWorker = this._instantiationService.createInstance(RemoteExtensionHostClient, this.getExtensions(), this._createProvider(remoteAgentConnection.remoteAuthority), browserWebSocketFactory);
const remoteExtHostProcessManager = this._instantiationService.createInstance(ExtensionHostProcessManager, false, remoteExtHostProcessWorker, remoteAgentConnection.remoteAuthority, initialActivationEvents);
result.push(remoteExtHostProcessManager);
return result;
}
protected async _scanAndHandleExtensions(): Promise<void> {
// fetch the remote environment
const remoteEnv = (await this._remoteAgentService.getEnvironment())!;
// enable or disable proposed API per extension
this._checkEnableProposedApi(remoteEnv.extensions);
// remove disabled extensions
remoteEnv.extensions = remoteEnv.extensions.filter(extension => this._isEnabled(extension));
// save for remote extension's init data
this._remoteExtensionsEnvironmentData = remoteEnv;
// this._handleExtensionPoints((<IExtensionDescription[]>[]).concat(remoteEnv.extensions).concat(localExtensions));
const result = this._registry.deltaExtensions(remoteEnv.extensions, []);
if (result.removedDueToLooping.length > 0) {
this._logOrShowMessage(Severity.Error, nls.localize('looping', "The following extensions contain dependency loops and have been disabled: {0}", result.removedDueToLooping.map(e => `'${e.identifier.value}'`).join(', ')));
}
this._doHandleExtensionPoints(this._registry.getAllExtensionDescriptions());
}
public _onExtensionHostExit(code: number): void {
// Expected development extension termination: When the extension host goes down we also shutdown the window
if (!this._isExtensionDevTestFromCli) {
......@@ -103,4 +122,3 @@ export class ExtensionService extends AbstractExtensionService implements IExten
}
registerSingleton(IExtensionService, ExtensionService);
......@@ -138,27 +138,14 @@ export abstract class CommonExtensionService extends Disposable implements IExte
const devOpts = parseExtensionDevOptions(this._environmentService);
this._isExtensionDevHost = devOpts.isExtensionDevHost;
this._isExtensionDevTestFromCli = devOpts.isExtensionDevTestFromCli;
this._startDelayed(this._lifecycleService);
}
private _startDelayed(lifecycleService: ILifecycleService): void {
// delay extension host creation and extension scanning
// until the workbench is running. we cannot defer the
// extension host more (LifecyclePhase.Restored) because
// some editors require the extension host to restore
// and this would result in a deadlock
// see https://github.com/Microsoft/vscode/issues/41322
lifecycleService.when(LifecyclePhase.Ready).then(() => {
// reschedule to ensure this runs after restoring viewlets, panels, and editors
runWhenIdle(async () => {
perf.mark('willLoadExtensions');
this._startExtensionHostProcess(true, []);
this.whenInstalledExtensionsRegistered().then(() => perf.mark('didLoadExtensions'));
await this._scanAndHandleExtensions();
this._releaseBarrier();
}, 50 /*max delay*/);
});
protected async _initialize(): Promise<void> {
perf.mark('willLoadExtensions');
this._startExtensionHostProcess(true, []);
this.whenInstalledExtensionsRegistered().then(() => perf.mark('didLoadExtensions'));
await this._scanAndHandleExtensions();
this._releaseBarrier();
}
private _releaseBarrier(): void {
......@@ -192,28 +179,28 @@ export abstract class CommonExtensionService extends Disposable implements IExte
const processManagers = this._createExtensionHosts(isInitialStart, initialActivationEvents);
processManagers.forEach((processManager) => {
processManager.onDidExit(([code, signal]) => this._onExtensionHostCrashOrExit(code, signal, processManager.isLocal));
processManager.onDidExit(([code, signal]) => this._onExtensionHostCrashOrExit(processManager, code, signal));
processManager.onDidChangeResponsiveState((responsiveState) => { this._onDidChangeResponsiveChange.fire({ isResponsive: responsiveState === ResponsiveState.Responsive }); });
this._extensionHostProcessManagers.push(processManager);
});
}
private _onExtensionHostCrashOrExit(code: number, signal: string | null, showNotification: boolean): void {
private _onExtensionHostCrashOrExit(extensionHost: ExtensionHostProcessManager, code: number, signal: string | null): void {
// Unexpected termination
if (!this._isExtensionDevHost) {
this._onExtensionHostCrashed(code, signal, showNotification);
this._onExtensionHostCrashed(extensionHost, code, signal);
return;
}
this._onExtensionHostExit(code);
}
private _onExtensionHostCrashed(code: number, signal: string | null, showNotification: boolean): void {
private _onExtensionHostCrashed(extensionHost: ExtensionHostProcessManager, code: number, signal: string | null): void {
console.error('Extension host terminated unexpectedly. Code: ', code, ' Signal: ', signal);
this._stopExtensionHostProcess();
if (showNotification) {
if (extensionHost.isLocal) {
if (code === 55) {
this._notificationService.prompt(
Severity.Error,
......@@ -351,9 +338,6 @@ export abstract class CommonExtensionService extends Disposable implements IExte
}
public getInspectPort(): number {
if (this._extensionHostProcessManagers.length > 0) {
return this._extensionHostProcessManagers[0].getInspectPort();
}
return 0;
}
......@@ -533,7 +517,7 @@ export abstract class CommonExtensionService extends Disposable implements IExte
export abstract class AbstractExtensionService extends CommonExtensionService implements IExtensionService {
private _remoteExtensionsEnvironmentData: Map<string, IRemoteAgentEnvironment>;
private readonly _remoteExtensionsEnvironmentData: Map<string, IRemoteAgentEnvironment>;
protected readonly _extensionHostLogsLocation: URI;
private readonly _extensionScanner: IExtensionScanner;
......@@ -608,6 +592,19 @@ export abstract class AbstractExtensionService extends CommonExtensionService im
this._handleDeltaExtensions(new DeltaExtensionsQueueItem([], [event.identifier.id]));
}
}));
// delay extension host creation and extension scanning
// until the workbench is running. we cannot defer the
// extension host more (LifecyclePhase.Restored) because
// some editors require the extension host to restore
// and this would result in a deadlock
// see https://github.com/Microsoft/vscode/issues/41322
this._lifecycleService.when(LifecyclePhase.Ready).then(() => {
// reschedule to ensure this runs after restoring viewlets, panels, and editors
runWhenIdle(async () => {
this._initialize();
}, 50 /*max delay*/);
});
}
//#region deltaExtensions
......@@ -918,11 +915,6 @@ export abstract class AbstractExtensionService extends CommonExtensionService im
// fetch the remote environment
const remoteEnv = (await this._remoteAgentService.getEnvironment())!;
// revive URIs
remoteEnv.extensions.forEach((extension) => {
(<any>extension).extensionLocation = URI.revive(extension.extensionLocation);
});
// enable or disable proposed API per extension
this._checkEnableProposedApi(remoteEnv.extensions);
......@@ -965,6 +957,13 @@ export abstract class AbstractExtensionService extends CommonExtensionService im
this._doHandleExtensionPoints(this._registry.getAllExtensionDescriptions());
}
public getInspectPort(): number {
if (this._extensionHostProcessManagers.length > 0) {
return this._extensionHostProcessManagers[0].getInspectPort();
}
return 0;
}
public abstract _onExtensionHostExit(code: number): void;
protected abstract _createLocalExtHostProcessWorker(autoStart: boolean, extensions: Promise<IExtensionDescription[]>): IExtensionHostStarter;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册