Update DAP dts and implement new 'startDebugging' request (#164530)

This commit is contained in:
Rob Lourens 2022-10-24 19:44:04 -07:00 committed by GitHub
parent 586f252740
commit a803dc359a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 281 additions and 239 deletions

View file

@ -288,7 +288,7 @@ export class DebugSession implements IDebugSession {
try {
const debugAdapter = await dbgr.createDebugAdapter(this);
this.raw = this.instantiationService.createInstance(RawDebugSession, debugAdapter, dbgr, this.id);
this.raw = this.instantiationService.createInstance(RawDebugSession, debugAdapter, dbgr, this.id, this.configuration.name);
await this.raw.start();
this.registerListeners();

View file

@ -83,6 +83,7 @@ export class RawDebugSession implements IDisposable {
debugAdapter: IDebugAdapter,
public readonly dbgr: IDebugger,
private readonly sessionId: string,
private readonly name: string,
@IExtensionHostDebugService private readonly extensionHostDebugService: IExtensionHostDebugService,
@IOpenerService private readonly openerService: IOpenerService,
@INotificationService private readonly notificationService: INotificationService,
@ -168,7 +169,7 @@ export class RawDebugSession implements IDisposable {
this._onDidEvent.fire(event);
});
this.debugAdapter.onRequest(request => this.dispatchRequest(request, dbgr));
this.debugAdapter.onRequest(request => this.dispatchRequest(request));
}
get onDidExitAdapter(): Event<AdapterEndEvent> {
@ -608,7 +609,7 @@ export class RawDebugSession implements IDisposable {
}
}
private async dispatchRequest(request: DebugProtocol.Request, dbgr: IDebugger): Promise<void> {
private async dispatchRequest(request: DebugProtocol.Request): Promise<void> {
const response: DebugProtocol.Response = {
type: 'response',
@ -647,7 +648,7 @@ export class RawDebugSession implements IDisposable {
break;
case 'runInTerminal':
try {
const shellProcessId = await dbgr.runInTerminal(request.arguments as DebugProtocol.RunInTerminalRequestArguments, this.sessionId);
const shellProcessId = await this.dbgr.runInTerminal(request.arguments as DebugProtocol.RunInTerminalRequestArguments, this.sessionId);
const resp = response as DebugProtocol.RunInTerminalResponse;
resp.body = {};
if (typeof shellProcessId === 'number') {
@ -660,6 +661,28 @@ export class RawDebugSession implements IDisposable {
safeSendResponse(response);
}
break;
case 'startDebugging':
try {
const args = (request.arguments as DebugProtocol.StartDebuggingRequestArguments);
const config: IConfig = {
...args.configuration,
...{
request: args.request,
type: this.dbgr.type,
name: this.name
}
};
const success = await this.dbgr.startDebugging(config, this.sessionId);
if (!success) {
response.success = false;
response.message = 'Failed to start debugging';
safeSendResponse(response);
}
} catch (err) {
response.success = false;
response.message = err.message;
safeSendResponse(response);
}
default:
response.success = false;
response.message = `unknown request '${request.command}'`;

View file

@ -155,8 +155,10 @@ export interface IExpression extends IExpressionContainer {
}
export interface IDebugger {
readonly type: string;
createDebugAdapter(session: IDebugSession): Promise<IDebugAdapter>;
runInTerminal(args: DebugProtocol.RunInTerminalRequestArguments, sessionId: string): Promise<number | undefined>;
startDebugging(args: IConfig, parentSessionId: string): Promise<boolean>;
getCustomTelemetryEndpoint(): ITelemetryEndpoint | undefined;
}

File diff suppressed because it is too large Load diff

View file

@ -99,20 +99,23 @@ export class Debugger implements IDebugger, IDebuggerMetadata {
}
}
createDebugAdapter(session: IDebugSession): Promise<IDebugAdapter> {
return this.adapterManager.activateDebuggers('onDebugAdapterProtocolTracker', this.type).then(_ => {
const da = this.adapterManager.createDebugAdapter(session);
if (da) {
return Promise.resolve(da);
}
throw new Error(nls.localize('cannot.find.da', "Cannot find debug adapter for type '{0}'.", this.type));
});
async startDebugging(configuration: IConfig, parentSessionId: string): Promise<boolean> {
const parentSession = this.debugService.getModel().getSession(parentSessionId);
return await this.debugService.startDebugging(undefined, configuration, { parentSession }, undefined);
}
substituteVariables(folder: IWorkspaceFolder | undefined, config: IConfig): Promise<IConfig> {
return this.adapterManager.substituteVariables(this.type, folder, config).then(config => {
return this.configurationResolverService.resolveWithInteractionReplace(folder, config, 'launch', this.variables, config.__configurationTarget);
});
async createDebugAdapter(session: IDebugSession): Promise<IDebugAdapter> {
await this.adapterManager.activateDebuggers('onDebugAdapterProtocolTracker', this.type);
const da = this.adapterManager.createDebugAdapter(session);
if (da) {
return Promise.resolve(da);
}
throw new Error(nls.localize('cannot.find.da', "Cannot find debug adapter for type '{0}'.", this.type));
}
async substituteVariables(folder: IWorkspaceFolder | undefined, config: IConfig): Promise<IConfig> {
const substitutedConfig = await this.adapterManager.substituteVariables(this.type, folder, config);
return await this.configurationResolverService.resolveWithInteractionReplace(folder, substitutedConfig, 'launch', this.variables, substitutedConfig.__configurationTarget);
}
runInTerminal(args: DebugProtocol.RunInTerminalRequestArguments, sessionId: string): Promise<number | undefined> {

View file

@ -176,7 +176,7 @@ suite('Debug - REPL', () => {
model.addSession(session);
const adapter = new MockDebugAdapter();
const raw = new RawDebugSession(adapter, undefined!, '', undefined!, undefined!, undefined!, undefined!);
const raw = new RawDebugSession(adapter, undefined!, '', '', undefined!, undefined!, undefined!, undefined!,);
session.initializeForTest(raw);
await session.addReplExpression(undefined, 'before.1');