提交 132ddb4e 编写于 作者: A Andre Weinand

cleanup debugConfigurationProviders properly

上级 87f69fec
......@@ -25,6 +25,7 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb
private _breakpointEventsActive: boolean;
private _debugAdapters: Map<number, ExtensionHostDebugAdapter>;
private _debugAdaptersHandleCounter = 1;
private _debugConfigurationProviders: Map<number, IDebugConfigurationProvider>;
constructor(
extHostContext: IExtHostContext,
......@@ -46,7 +47,8 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb
this._proxy.$acceptDebugSessionActiveChanged(this.getSessionDto(session));
}));
this._debugAdapters = new Map<number, ExtensionHostDebugAdapter>();
this._debugAdapters = new Map();
this._debugConfigurationProviders = new Map();
}
public dispose(): void {
......@@ -166,13 +168,18 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb
return Promise.resolve(this._proxy.$provideDebugAdapter(handle, this.getSessionDto(session), folder, config));
};
}
this.debugService.getConfigurationManager().registerDebugConfigurationProvider(handle, provider);
this._debugConfigurationProviders.set(handle, provider);
this._toDispose.push(this.debugService.getConfigurationManager().registerDebugConfigurationProvider(provider));
return Promise.resolve(undefined);
}
public $unregisterDebugConfigurationProvider(handle: number): Thenable<void> {
this.debugService.getConfigurationManager().unregisterDebugConfigurationProvider(handle);
const provider = this._debugConfigurationProviders.get(handle);
if (provider) {
this._debugConfigurationProviders.delete(handle);
this.debugService.getConfigurationManager().unregisterDebugConfigurationProvider(provider);
}
return TPromise.wrap<void>(undefined);
}
......
......@@ -518,7 +518,6 @@ export interface IDebuggerContribution extends IPlatformSpecificAdapterContribut
export interface IDebugConfigurationProvider {
readonly type: string;
handle: number;
resolveDebugConfiguration?(folderUri: uri | undefined, debugConfiguration: IConfig): Promise<IConfig>;
provideDebugConfigurations?(folderUri: uri | undefined): Promise<IConfig[]>;
provideDebugAdapter?(session: IDebugSession, folderUri: uri | undefined, config: IConfig): Promise<IAdapterDescriptor>;
......@@ -570,9 +569,10 @@ export interface IConfigurationManager {
onDidSelectConfiguration: Event<void>;
needsToRunInExtHost(debugType: string): boolean;
hasDebugConfigurationProvider(debugType: string): boolean;
registerDebugConfigurationProvider(handle: number, debugConfigurationProvider: IDebugConfigurationProvider): void;
unregisterDebugConfigurationProvider(handle: number): void;
registerDebugConfigurationProvider(debugConfigurationProvider: IDebugConfigurationProvider): IDisposable;
unregisterDebugConfigurationProvider(debugConfigurationProvider: IDebugConfigurationProvider): void;
resolveConfigurationByProviders(folderUri: uri | undefined, type: string | undefined, debugConfiguration: any): Thenable<any>;
provideDebugAdapter(session: IDebugSession, folderUri: uri | undefined, config: IConfig): Promise<IAdapterDescriptor | undefined>;
......
......@@ -79,31 +79,36 @@ export class ConfigurationManager implements IConfigurationManager {
}
}
public registerDebugConfigurationProvider(handle: number, debugConfigurationProvider: IDebugConfigurationProvider): void {
if (!debugConfigurationProvider) {
return;
}
public registerDebugConfigurationProvider(debugConfigurationProvider: IDebugConfigurationProvider): IDisposable {
debugConfigurationProvider.handle = handle;
this.providers = this.providers.filter(p => p.handle !== handle);
this.providers.push(debugConfigurationProvider);
const dbg = this.getDebugger(debugConfigurationProvider.type);
// Check if the provider contributes provideDebugConfigurations method
if (dbg && debugConfigurationProvider.provideDebugConfigurations) {
dbg.hasConfigurationProvider = true;
return {
dispose: () => {
this.unregisterDebugConfigurationProvider(debugConfigurationProvider);
}
};
}
public unregisterDebugConfigurationProvider(debugConfigurationProvider: IDebugConfigurationProvider): void {
const ix = this.providers.indexOf(debugConfigurationProvider);
if (ix >= 0) {
this.providers.splice(ix, 1);
}
}
public hasDebugConfigurationProvider(debugType: string): boolean {
// check if there are providers for the given type that contribute a provideDebugConfigurations method
const providers = this.providers.filter(p => p.provideDebugConfigurations && (p.type === debugType));
return providers.length > 0;
}
public needsToRunInExtHost(debugType: string): boolean {
// if the given debugType matches any registered provider that has a provideTracker method, we need to run the DA in the EH
const providers = this.providers.filter(p => p.hasTracker && (p.type === debugType || p.type === '*'));
return providers.length > 0;
}
public unregisterDebugConfigurationProvider(handle: number): void {
this.providers = this.providers.filter(p => p.handle !== handle);
}
public resolveConfigurationByProviders(folderUri: uri | undefined, type: string | undefined, debugConfiguration: IConfig): Thenable<IConfig> {
return this.activateDebuggers(`onDebugResolve:${type}`).then(() => {
// pipe the config through the promises sequentially. append at the end the '*' types
......@@ -358,7 +363,7 @@ export class ConfigurationManager implements IConfigurationManager {
}
if (!candidates) {
candidates = this.activateDebuggers('onDebugInitialConfigurations').then(() => this.debuggers.filter(a => a.hasInitialConfiguration() || a.hasConfigurationProvider));
candidates = this.activateDebuggers('onDebugInitialConfigurations').then(() => this.debuggers.filter(dbg => dbg.hasInitialConfiguration() || dbg.hasConfigurationProvider()));
}
return candidates.then(debuggers => {
......
......@@ -40,7 +40,6 @@ export class Debugger implements IDebugger {
this.mergedExtensionDescriptions = [extensionDescription];
}
public hasConfigurationProvider = false;
public createDebugAdapter(session: IDebugSession, root: IWorkspaceFolder, config: IConfig, outputService: IOutputService): Promise<IDebugAdapter> {
if (this.inExtHost()) {
......@@ -149,6 +148,10 @@ export class Debugger implements IDebugger {
return !!this.debuggerContribution.initialConfigurations;
}
public hasConfigurationProvider() {
this.configurationManager.hasDebugConfigurationProvider(this.type);
}
public getInitialConfigurationContent(initialConfigs?: IConfig[]): Promise<string> {
// at this point we got some configs from the package.json and/or from registered DebugConfigurationProviders
let initialConfigurations = this.debuggerContribution.initialConfigurations || [];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册