From ac1df80c6705957eba4077fdbf7f331fb52bfe7e Mon Sep 17 00:00:00 2001 From: isidor Date: Fri, 18 Jan 2019 17:43:58 +0100 Subject: [PATCH] makde debuggers extension point contribution dynamic #66574 --- .../parts/debug/common/debugSchemas.ts | 1 + .../debugConfigurationManager.ts | 26 ++++++++++++++----- .../debug/electron-browser/debugService.ts | 2 +- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/vs/workbench/parts/debug/common/debugSchemas.ts b/src/vs/workbench/parts/debug/common/debugSchemas.ts index ef17e55eb79..67b573e33d4 100644 --- a/src/vs/workbench/parts/debug/common/debugSchemas.ts +++ b/src/vs/workbench/parts/debug/common/debugSchemas.ts @@ -13,6 +13,7 @@ import { inputsSchema } from 'vs/workbench/services/configurationResolver/common // debuggers extension point export const debuggersExtPoint = extensionsRegistry.ExtensionsRegistry.registerExtensionPoint({ extensionPoint: 'debuggers', + isDynamic: true, jsonSchema: { description: nls.localize('vscode.extension.contributes.debuggers', 'Contributes debug adapters.'), type: 'array', diff --git a/src/vs/workbench/parts/debug/electron-browser/debugConfigurationManager.ts b/src/vs/workbench/parts/debug/electron-browser/debugConfigurationManager.ts index d1b7d1447bd..87c69d51e3f 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugConfigurationManager.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugConfigurationManager.ts @@ -21,7 +21,7 @@ import { IFileService } from 'vs/platform/files/common/files'; import { IWorkspaceContextService, IWorkspaceFolder, WorkbenchState } from 'vs/platform/workspace/common/workspace'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { ICommandService } from 'vs/platform/commands/common/commands'; -import { IDebugConfigurationProvider, ICompound, IDebugConfiguration, IConfig, IGlobalConfig, IConfigurationManager, ILaunch, IDebugAdapterDescriptorFactory, IDebugAdapter, ITerminalSettings, ITerminalLauncher, IDebugSession, IAdapterDescriptor, CONTEXT_DEBUG_CONFIGURATION_TYPE, IDebugAdapterFactory, IDebugAdapterTrackerFactory } from 'vs/workbench/parts/debug/common/debug'; +import { IDebugConfigurationProvider, ICompound, IDebugConfiguration, IConfig, IGlobalConfig, IConfigurationManager, ILaunch, IDebugAdapterDescriptorFactory, IDebugAdapter, ITerminalSettings, ITerminalLauncher, IDebugSession, IAdapterDescriptor, CONTEXT_DEBUG_CONFIGURATION_TYPE, IDebugAdapterFactory, IDebugAdapterTrackerFactory, IDebugService } from 'vs/workbench/parts/debug/common/debug'; import { Debugger } from 'vs/workbench/parts/debug/node/debugger'; import { IEditorService, ACTIVE_GROUP, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService'; import { isCodeEditor } from 'vs/editor/browser/editorBrowser'; @@ -33,6 +33,7 @@ import { IJSONContributionRegistry, Extensions as JSONExtensions } from 'vs/plat import { launchSchema, debuggersExtPoint, breakpointsExtPoint } from 'vs/workbench/parts/debug/common/debugSchemas'; import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput'; import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey'; +import { onUnexpectedError } from 'vs/base/common/errors'; const jsonRegistry = Registry.as(JSONExtensions.JSONContribution); jsonRegistry.registerSchema(launchSchemaId, launchSchema); @@ -56,6 +57,7 @@ export class ConfigurationManager implements IConfigurationManager { private debugConfigurationTypeContext: IContextKey; constructor( + private debugService: IDebugService, @IWorkspaceContextService private readonly contextService: IWorkspaceContextService, @IEditorService private readonly editorService: IEditorService, @IConfigurationService private readonly configurationService: IConfigurationService, @@ -235,11 +237,11 @@ export class ConfigurationManager implements IConfigurationManager { } private registerListeners(lifecycleService: ILifecycleService): void { - debuggersExtPoint.setHandler((extensions) => { - extensions.forEach(extension => { - extension.value.forEach(rawAdapter => { + debuggersExtPoint.setHandler((extensions, delta) => { + delta.added.forEach(added => { + added.value.forEach(rawAdapter => { if (!rawAdapter.type || (typeof rawAdapter.type !== 'string')) { - extension.collector.error(nls.localize('debugNoType', "Debugger 'type' can not be omitted and must be of type 'string'.")); + added.collector.error(nls.localize('debugNoType', "Debugger 'type' can not be omitted and must be of type 'string'.")); } if (rawAdapter.enableBreakpointsFor) { rawAdapter.enableBreakpointsFor.languageIds.forEach(modeId => { @@ -249,9 +251,19 @@ export class ConfigurationManager implements IConfigurationManager { const duplicate = this.getDebugger(rawAdapter.type); if (duplicate) { - duplicate.merge(rawAdapter, extension.description); + duplicate.merge(rawAdapter, added.description); } else { - this.debuggers.push(this.instantiationService.createInstance(Debugger, this, rawAdapter, extension.description)); + this.debuggers.push(this.instantiationService.createInstance(Debugger, this, rawAdapter, added.description)); + } + }); + }); + delta.removed.forEach(removed => { + const removedTypes = removed.value.map(rawAdapter => rawAdapter.type); + this.debuggers = this.debuggers.filter(d => removedTypes.indexOf(d.type) === -1); + this.debugService.getModel().getSessions().forEach(s => { + // Stop sessions if their debugger has been removed + if (removedTypes.indexOf(s.configuration.type) >= 0) { + this.debugService.stopSession(s).then(undefined, onUnexpectedError); } }); }); diff --git a/src/vs/workbench/parts/debug/electron-browser/debugService.ts b/src/vs/workbench/parts/debug/electron-browser/debugService.ts index 2e17633e4a1..8af829fa6e7 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugService.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugService.ts @@ -119,7 +119,7 @@ export class DebugService implements IDebugService { this._onWillNewSession = new Emitter(); this._onDidEndSession = new Emitter(); - this.configurationManager = this.instantiationService.createInstance(ConfigurationManager); + this.configurationManager = this.instantiationService.createInstance(ConfigurationManager, this); this.toDispose.push(this.configurationManager); this.debugType = CONTEXT_DEBUG_TYPE.bindTo(contextKeyService);