Skip to content

Commit 1451fab

Browse files
committed
add dynamic debug config API
1 parent b8639cb commit 1451fab

9 files changed

Lines changed: 73 additions & 16 deletions

File tree

src/vs/vscode.d.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10109,13 +10109,29 @@ declare module 'vscode' {
1010910109
}
1011010110

1011110111
/**
10112-
* A debug configuration provider allows to add the initial debug configurations to a newly created launch.json
10113-
* and to resolve a launch configuration before it is used to start a new debug session.
10112+
* VS Code can call the `provideDebugConfigurations` method of a `DebugConfigurationProvider` in two situations (aka 'scopes'):
10113+
* to provide the initial debug configurations for a newly create launch.json or to provide debug configurations dynamically based on context.
10114+
* A scope value is used when registering a `DebugConfigurationProvider` with #debug.registerDebugConfigurationProvider.
10115+
*/
10116+
export enum DebugConfigurationProviderScope {
10117+
/**
10118+
* The 'initial' scope denotes a context where all debug configurations for a newly created launch.json are needed.
10119+
*/
10120+
Initial = 1,
10121+
/**
10122+
* The 'dynamic' scope denotes a context where all debug configurations for the current context are needed.
10123+
*/
10124+
Dynamic = 2
10125+
}
10126+
10127+
/**
10128+
* A debug configuration provider allows to add debug configurations to the debug service
10129+
* and to resolve launch configurations before they are used to start a debug session.
1011410130
* A debug configuration provider is registered via #debug.registerDebugConfigurationProvider.
1011510131
*/
1011610132
export interface DebugConfigurationProvider {
1011710133
/**
10118-
* Provides initial [debug configuration](#DebugConfiguration). If more than one debug configuration provider is
10134+
* Provides [debug configuration](#DebugConfiguration) to the debug service. If more than one debug configuration provider is
1011910135
* registered for the same type, debug configurations are concatenated in arbitrary order.
1012010136
*
1012110137
* @param folder The workspace folder for which the configurations are used or `undefined` for a folderless setup.
@@ -10526,9 +10542,10 @@ declare module 'vscode' {
1052610542
*
1052710543
* @param type The debug type for which the provider is registered.
1052810544
* @param provider The [debug configuration provider](#DebugConfigurationProvider) to register.
10545+
* @param scope The [scope](#DebugConfigurationProviderScope) for which the 'provideDebugConfiguration' method of the provider is registered. An error is thrown if the provider has no 'provideDebugConfiguration' method or if it has one of the 'resolveDebugConfiguration' methods.
1052910546
* @return A [disposable](#Disposable) that unregisters this provider when being disposed.
1053010547
*/
10531-
export function registerDebugConfigurationProvider(debugType: string, provider: DebugConfigurationProvider): Disposable;
10548+
export function registerDebugConfigurationProvider(debugType: string, provider: DebugConfigurationProvider, scope?: DebugConfigurationProviderScope): Disposable;
1053210549

1053310550
/**
1053410551
* Register a [debug adapter descriptor factory](#DebugAdapterDescriptorFactory) for a specific debug type.

src/vs/workbench/api/browser/mainThreadDebugService.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import severity from 'vs/base/common/severity';
1515
import { AbstractDebugAdapter } from 'vs/workbench/contrib/debug/common/abstractDebugAdapter';
1616
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
1717
import { convertToVSCPaths, convertToDAPaths } from 'vs/workbench/contrib/debug/common/debugUtils';
18+
import { DebugConfigurationProviderScope } from 'vs/workbench/api/common/extHostTypes';
1819

1920
@extHostNamedCustomer(MainContext.MainThreadDebugService)
2021
export class MainThreadDebugService implements MainThreadDebugServiceShape, IDebugAdapterFactory {
@@ -154,10 +155,11 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb
154155
return Promise.resolve();
155156
}
156157

157-
public $registerDebugConfigurationProvider(debugType: string, hasProvide: boolean, hasResolve: boolean, hasResolve2: boolean, hasProvideDebugAdapter: boolean, handle: number): Promise<void> {
158+
public $registerDebugConfigurationProvider(debugType: string, providerScope: DebugConfigurationProviderScope, hasProvide: boolean, hasResolve: boolean, hasResolve2: boolean, hasProvideDebugAdapter: boolean, handle: number): Promise<void> {
158159

159160
const provider = <IDebugConfigurationProvider>{
160-
type: debugType
161+
type: debugType,
162+
scope: providerScope
161163
};
162164
if (hasProvide) {
163165
provider.provideDebugConfigurations = (folder, token) => {
@@ -271,7 +273,6 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb
271273
this.getDebugAdapter(handle).acceptMessage(convertToVSCPaths(message, false));
272274
}
273275

274-
275276
public $acceptDAError(handle: number, name: string, message: string, stack: string) {
276277
this.getDebugAdapter(handle).fireError(handle, new Error(`${name}: ${message}\n${stack}`));
277278
}

src/vs/workbench/api/common/extHost.api.impl.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,8 +846,8 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
846846
onDidChangeBreakpoints(listener, thisArgs?, disposables?) {
847847
return extHostDebugService.onDidChangeBreakpoints(listener, thisArgs, disposables);
848848
},
849-
registerDebugConfigurationProvider(debugType: string, provider: vscode.DebugConfigurationProvider) {
850-
return extHostDebugService.registerDebugConfigurationProvider(debugType, provider);
849+
registerDebugConfigurationProvider(debugType: string, provider: vscode.DebugConfigurationProvider, scope?: vscode.DebugConfigurationProviderScope) {
850+
return extHostDebugService.registerDebugConfigurationProvider(debugType, provider, scope || vscode.DebugConfigurationProviderScope.Initial);
851851
},
852852
registerDebugAdapterDescriptorFactory(debugType: string, factory: vscode.DebugAdapterDescriptorFactory) {
853853
return extHostDebugService.registerDebugAdapterDescriptorFactory(extension, debugType, factory);
@@ -1032,6 +1032,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
10321032
CallHierarchyIncomingCall: extHostTypes.CallHierarchyIncomingCall,
10331033
CallHierarchyItem: extHostTypes.CallHierarchyItem,
10341034
DebugConsoleMode: extHostTypes.DebugConsoleMode,
1035+
DebugConfigurationProviderScope: extHostTypes.DebugConfigurationProviderScope,
10351036
Decoration: extHostTypes.Decoration,
10361037
UIKind: UIKind,
10371038
ColorThemeKind: extHostTypes.ColorThemeKind,

src/vs/workbench/api/common/extHost.protocol.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import { INotebookMimeTypeSelector, IOutput, INotebookDisplayOrder, NotebookCell
5555
import { CallHierarchyItem } from 'vs/workbench/contrib/callHierarchy/common/callHierarchy';
5656
import { Dto } from 'vs/base/common/types';
5757
import { ISerializableEnvironmentVariableCollection } from 'vs/workbench/contrib/terminal/common/environmentVariable';
58+
import { DebugConfigurationProviderScope } from 'vs/workbench/api/common/extHostTypes';
5859

5960
export interface IEnvironment {
6061
isExtensionDevelopmentDebug: boolean;
@@ -845,7 +846,7 @@ export interface MainThreadDebugServiceShape extends IDisposable {
845846
$acceptDAMessage(handle: number, message: DebugProtocol.ProtocolMessage): void;
846847
$acceptDAError(handle: number, name: string, message: string, stack: string | undefined): void;
847848
$acceptDAExit(handle: number, code: number | undefined, signal: string | undefined): void;
848-
$registerDebugConfigurationProvider(type: string, hasProvideMethod: boolean, hasResolveMethod: boolean, hasResolve2Method: boolean, hasProvideDaMethod: boolean, handle: number): Promise<void>;
849+
$registerDebugConfigurationProvider(type: string, scope: DebugConfigurationProviderScope, hasProvideMethod: boolean, hasResolveMethod: boolean, hasResolve2Method: boolean, hasProvideDaMethod: boolean, handle: number): Promise<void>;
849850
$registerDebugAdapterDescriptorFactory(type: string, handle: number): Promise<void>;
850851
$unregisterDebugConfigurationProvider(handle: number): void;
851852
$unregisterDebugAdapterDescriptorFactory(handle: number): void;

src/vs/workbench/api/common/extHostDebugService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export interface IExtHostDebugService extends ExtHostDebugServiceShape {
5151
addBreakpoints(breakpoints0: vscode.Breakpoint[]): Promise<void>;
5252
removeBreakpoints(breakpoints0: vscode.Breakpoint[]): Promise<void>;
5353
startDebugging(folder: vscode.WorkspaceFolder | undefined, nameOrConfig: string | vscode.DebugConfiguration, options: vscode.DebugSessionOptions): Promise<boolean>;
54-
registerDebugConfigurationProvider(type: string, provider: vscode.DebugConfigurationProvider): vscode.Disposable;
54+
registerDebugConfigurationProvider(type: string, provider: vscode.DebugConfigurationProvider, scope: vscode.DebugConfigurationProviderScope): vscode.Disposable;
5555
registerDebugAdapterDescriptorFactory(extension: IExtensionDescription, type: string, factory: vscode.DebugAdapterDescriptorFactory): vscode.Disposable;
5656
registerDebugAdapterTrackerFactory(type: string, factory: vscode.DebugAdapterTrackerFactory): vscode.Disposable;
5757
asDebugSourceUri(source: vscode.DebugProtocolSource, session?: vscode.DebugSession): vscode.Uri;
@@ -299,7 +299,7 @@ export class ExtHostDebugServiceBase implements IExtHostDebugService, ExtHostDeb
299299
});
300300
}
301301

302-
public registerDebugConfigurationProvider(type: string, provider: vscode.DebugConfigurationProvider): vscode.Disposable {
302+
public registerDebugConfigurationProvider(type: string, provider: vscode.DebugConfigurationProvider, scope: vscode.DebugConfigurationProviderScope): vscode.Disposable {
303303

304304
if (!provider) {
305305
return new Disposable(() => { });
@@ -312,7 +312,7 @@ export class ExtHostDebugServiceBase implements IExtHostDebugService, ExtHostDeb
312312
const handle = this._configProviderHandleCounter++;
313313
this._configProviders.push({ type, handle, provider });
314314

315-
this._debugServiceProxy.$registerDebugConfigurationProvider(type,
315+
this._debugServiceProxy.$registerDebugConfigurationProvider(type, scope,
316316
!!provider.provideDebugConfigurations,
317317
!!provider.resolveDebugConfiguration,
318318
!!provider.resolveDebugConfigurationWithSubstitutedVariables,

src/vs/workbench/api/common/extHostTypes.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2652,6 +2652,22 @@ export enum DebugConsoleMode {
26522652
MergeWithParent = 1
26532653
}
26542654

2655+
/**
2656+
* VS Code can call the `provideDebugConfigurations` method of a `DebugConfigurationProvider` in two situations (aka 'scopes'):
2657+
* to provide the initial debug configurations for a newly create launch.json or to provide debug configurations dynamically based on context.
2658+
* A scope value is used when registering a `DebugConfigurationProvider` with `debug.registerDebugConfigurationProvider`.
2659+
*/
2660+
export enum DebugConfigurationProviderScope {
2661+
/**
2662+
* The 'initial' scope denotes a context where all debug configurations for a newly created launch.json are needed.
2663+
*/
2664+
Initial = 1,
2665+
/**
2666+
* The 'dynamic' scope denotes a context where all debug configurations for the current context are needed.
2667+
*/
2668+
Dynamic = 2
2669+
}
2670+
26552671
//#endregion
26562672

26572673
@es5ClassCompat

src/vs/workbench/contrib/debug/browser/debugConfigurationManager.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { sequence } from 'vs/base/common/async';
3838
import { IHistoryService } from 'vs/workbench/services/history/common/history';
3939
import { first } from 'vs/base/common/arrays';
4040
import { getVisibleAndSorted } from 'vs/workbench/contrib/debug/common/debugUtils';
41+
import { DebugConfigurationProviderScope } from 'vs/workbench/api/common/extHostTypes';
4142

4243
const jsonRegistry = Registry.as<IJSONContributionRegistry>(JSONExtensions.JSONContribution);
4344
jsonRegistry.registerSchema(launchSchemaId, launchSchema);
@@ -193,9 +194,15 @@ export class ConfigurationManager implements IConfigurationManager {
193194
}
194195
}
195196

196-
hasDebugConfigurationProvider(debugType: string): boolean {
197+
/**
198+
* if scope is not specified,a value of DebugConfigurationProviderScope.Initialization is assumed.
199+
*/
200+
hasDebugConfigurationProvider(debugType: string, scope?: DebugConfigurationProviderScope): boolean {
201+
if (scope === undefined) {
202+
scope = DebugConfigurationProviderScope.Initial;
203+
}
197204
// check if there are providers for the given type that contribute a provideDebugConfigurations method
198-
const providers = this.configProviders.filter(p => p.provideDebugConfigurations && (p.type === debugType));
205+
const providers = this.configProviders.filter(p => p.provideDebugConfigurations && (p.type === debugType) && (p.scope === scope));
199206
return providers.length > 0;
200207
}
201208

@@ -234,7 +241,14 @@ export class ConfigurationManager implements IConfigurationManager {
234241

235242
async provideDebugConfigurations(folderUri: uri | undefined, type: string, token: CancellationToken): Promise<any[]> {
236243
await this.activateDebuggers('onDebugInitialConfigurations');
237-
const results = await Promise.all(this.configProviders.filter(p => p.type === type && p.provideDebugConfigurations).map(p => p.provideDebugConfigurations!(folderUri, token)));
244+
const results = await Promise.all(this.configProviders.filter(p => p.type === type && p.scope === DebugConfigurationProviderScope.Initial && p.provideDebugConfigurations).map(p => p.provideDebugConfigurations!(folderUri, token)));
245+
246+
return results.reduce((first, second) => first.concat(second), []);
247+
}
248+
249+
async provideDynamicDebugConfigurations(folderUri: uri | undefined, type: string, token: CancellationToken): Promise<any[]> {
250+
await this.activateDebuggers('onDebugDynamicConfigurations');
251+
const results = await Promise.all(this.configProviders.filter(p => p.type === type && p.scope === DebugConfigurationProviderScope.Dynamic && p.provideDebugConfigurations).map(p => p.provideDebugConfigurations!(folderUri, token)));
238252

239253
return results.reduce((first, second) => first.concat(second), []);
240254
}

src/vs/workbench/contrib/debug/common/debug.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { TaskIdentifier } from 'vs/workbench/contrib/tasks/common/tasks';
2323
import { TelemetryService } from 'vs/platform/telemetry/common/telemetryService';
2424
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
2525
import { CancellationToken } from 'vs/base/common/cancellation';
26+
import { DebugConfigurationProviderScope } from 'vs/workbench/api/common/extHostTypes';
2627

2728
export const VIEWLET_ID = 'workbench.view.debug';
2829

@@ -602,6 +603,7 @@ export interface IDebuggerContribution extends IPlatformSpecificAdapterContribut
602603

603604
export interface IDebugConfigurationProvider {
604605
readonly type: string;
606+
readonly scope: DebugConfigurationProviderScope;
605607
resolveDebugConfiguration?(folderUri: uri | undefined, debugConfiguration: IConfig, token: CancellationToken): Promise<IConfig | null | undefined>;
606608
resolveDebugConfigurationWithSubstitutedVariables?(folderUri: uri | undefined, debugConfiguration: IConfig, token: CancellationToken): Promise<IConfig | null | undefined>;
607609
provideDebugConfigurations?(folderUri: uri | undefined, token: CancellationToken): Promise<IConfig[]>;

src/vs/workbench/services/extensions/common/extensionsRegistry.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ export const schema: IJSONSchema = {
249249
description: nls.localize('vscode.extension.activationEvents.onDebugInitialConfigurations', 'An activation event emitted whenever a "launch.json" needs to be created (and all provideDebugConfigurations methods need to be called).'),
250250
body: 'onDebugInitialConfigurations'
251251
},
252+
{
253+
label: 'onDebugDynamicConfigurations',
254+
description: nls.localize('vscode.extension.activationEvents.onDebugDynamicConfigurations', 'An activation event emitted whenever a list of all debug configurations needs to be created (and all provideDebugConfigurations methods for the "dynamic" scope need to be called).'),
255+
body: 'onDebugDynamicConfigurations'
256+
},
252257
{
253258
label: 'onDebugResolve',
254259
description: nls.localize('vscode.extension.activationEvents.onDebugResolve', 'An activation event emitted whenever a debug session with the specific type is about to be launched (and a corresponding resolveDebugConfiguration method needs to be called).'),

0 commit comments

Comments
 (0)