mirror of
https://github.com/Microsoft/vscode
synced 2024-10-12 14:30:13 +00:00
debt: cleanup DebugService and DebugSession
This commit is contained in:
parent
8da822159d
commit
5bb7401522
|
@ -112,12 +112,12 @@ export interface IRawDebugSession {
|
||||||
|
|
||||||
capabilities: DebugProtocol.Capabilities;
|
capabilities: DebugProtocol.Capabilities;
|
||||||
disconnected: boolean;
|
disconnected: boolean;
|
||||||
|
|
||||||
readyForBreakpoints: boolean;
|
readyForBreakpoints: boolean;
|
||||||
emittedStopped: boolean;
|
emittedStopped: boolean;
|
||||||
sessionLengthInSeconds: number;
|
sessionLengthInSeconds: number;
|
||||||
|
|
||||||
launch(args: DebugProtocol.LaunchRequestArguments): TPromise<DebugProtocol.LaunchResponse>;
|
launchOrAttach(args: IConfig): TPromise<DebugProtocol.Response>;
|
||||||
attach(args: DebugProtocol.AttachRequestArguments): TPromise<DebugProtocol.AttachResponse>;
|
|
||||||
terminate(restart?: boolean): TPromise<DebugProtocol.TerminateResponse>;
|
terminate(restart?: boolean): TPromise<DebugProtocol.TerminateResponse>;
|
||||||
disconnect(restart?: boolean): TPromise<any>;
|
disconnect(restart?: boolean): TPromise<any>;
|
||||||
|
|
||||||
|
|
|
@ -410,7 +410,7 @@ export class DebugService implements IDebugService {
|
||||||
const dbgr = this.configurationManager.getDebugger(session.configuration.type);
|
const dbgr = this.configurationManager.getDebugger(session.configuration.type);
|
||||||
|
|
||||||
return session.initialize(dbgr).then(() => {
|
return session.initialize(dbgr).then(() => {
|
||||||
session.raw.attach(session.configuration).then(result => {
|
session.raw.launchOrAttach(session.configuration).then(result => {
|
||||||
this.focusStackFrame(undefined, undefined, session);
|
this.focusStackFrame(undefined, undefined, session);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -440,11 +440,7 @@ export class DebugService implements IDebugService {
|
||||||
resolved.__sessionId = session.getId();
|
resolved.__sessionId = session.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (resolved.request === 'attach' ? raw.attach(resolved) : raw.launch(resolved)).then(result => {
|
return raw.launchOrAttach(resolved).then(result => {
|
||||||
|
|
||||||
if (raw.disconnected) {
|
|
||||||
return TPromise.as(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.focusStackFrame(undefined, undefined, session);
|
this.focusStackFrame(undefined, undefined, session);
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ import { IOutputService } from 'vs/workbench/parts/output/common/output';
|
||||||
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
|
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
|
||||||
import { formatPII } from 'vs/workbench/parts/debug/common/debugUtils';
|
import { formatPII } from 'vs/workbench/parts/debug/common/debugUtils';
|
||||||
import { SocketDebugAdapter } from 'vs/workbench/parts/debug/node/debugAdapter';
|
import { SocketDebugAdapter } from 'vs/workbench/parts/debug/node/debugAdapter';
|
||||||
import { IRawDebugSession, IDebugAdapter } from 'vs/workbench/parts/debug/common/debug';
|
import { IRawDebugSession, IDebugAdapter, IConfig } from 'vs/workbench/parts/debug/common/debug';
|
||||||
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
|
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
|
||||||
|
|
||||||
export class RawDebugSession implements IRawDebugSession {
|
export class RawDebugSession implements IRawDebugSession {
|
||||||
|
@ -150,35 +150,37 @@ export class RawDebugSession implements IRawDebugSession {
|
||||||
//---- DAP requests
|
//---- DAP requests
|
||||||
|
|
||||||
public initialize(args: DebugProtocol.InitializeRequestArguments): TPromise<DebugProtocol.InitializeResponse> {
|
public initialize(args: DebugProtocol.InitializeRequestArguments): TPromise<DebugProtocol.InitializeResponse> {
|
||||||
return this.send('initialize', args).then(response => this.readCapabilities(response));
|
return this.send('initialize', args).then(response => {
|
||||||
|
this.readCapabilities(response);
|
||||||
|
return response;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public launch(args: DebugProtocol.LaunchRequestArguments): TPromise<DebugProtocol.LaunchResponse> {
|
public launchOrAttach(config: IConfig): TPromise<DebugProtocol.Response> {
|
||||||
return this.send('launch', args).then(response => this.readCapabilities(response));
|
this.isAttached = config.request === 'attach';
|
||||||
}
|
return this.send(this.isAttached ? 'attach' : 'launch', config).then(response => {
|
||||||
|
this.readCapabilities(response);
|
||||||
public attach(args: DebugProtocol.AttachRequestArguments): TPromise<DebugProtocol.AttachResponse> {
|
return response;
|
||||||
this.isAttached = true;
|
});
|
||||||
return this.send('attach', args).then(response => this.readCapabilities(response));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public next(args: DebugProtocol.NextArguments): TPromise<DebugProtocol.NextResponse> {
|
public next(args: DebugProtocol.NextArguments): TPromise<DebugProtocol.NextResponse> {
|
||||||
return this.send('next', args).then(response => {
|
return this.send('next', args).then(response => {
|
||||||
this.fireFakeContinued(args.threadId);
|
this.fireSimulatedContinuedEvent(args.threadId);
|
||||||
return response;
|
return response;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public stepIn(args: DebugProtocol.StepInArguments): TPromise<DebugProtocol.StepInResponse> {
|
public stepIn(args: DebugProtocol.StepInArguments): TPromise<DebugProtocol.StepInResponse> {
|
||||||
return this.send('stepIn', args).then(response => {
|
return this.send('stepIn', args).then(response => {
|
||||||
this.fireFakeContinued(args.threadId);
|
this.fireSimulatedContinuedEvent(args.threadId);
|
||||||
return response;
|
return response;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public stepOut(args: DebugProtocol.StepOutArguments): TPromise<DebugProtocol.StepOutResponse> {
|
public stepOut(args: DebugProtocol.StepOutArguments): TPromise<DebugProtocol.StepOutResponse> {
|
||||||
return this.send('stepOut', args).then(response => {
|
return this.send('stepOut', args).then(response => {
|
||||||
this.fireFakeContinued(args.threadId);
|
this.fireSimulatedContinuedEvent(args.threadId);
|
||||||
return response;
|
return response;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -188,7 +190,7 @@ export class RawDebugSession implements IRawDebugSession {
|
||||||
if (response && response.body && response.body.allThreadsContinued !== undefined) {
|
if (response && response.body && response.body.allThreadsContinued !== undefined) {
|
||||||
this.allThreadsContinued = response.body.allThreadsContinued;
|
this.allThreadsContinued = response.body.allThreadsContinued;
|
||||||
}
|
}
|
||||||
this.fireFakeContinued(args.threadId, this.allThreadsContinued);
|
this.fireSimulatedContinuedEvent(args.threadId, this.allThreadsContinued);
|
||||||
return response;
|
return response;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -207,7 +209,7 @@ export class RawDebugSession implements IRawDebugSession {
|
||||||
|
|
||||||
public restartFrame(args: DebugProtocol.RestartFrameArguments, threadId: number): TPromise<DebugProtocol.RestartFrameResponse> {
|
public restartFrame(args: DebugProtocol.RestartFrameArguments, threadId: number): TPromise<DebugProtocol.RestartFrameResponse> {
|
||||||
return this.send('restartFrame', args).then(response => {
|
return this.send('restartFrame', args).then(response => {
|
||||||
this.fireFakeContinued(threadId);
|
this.fireSimulatedContinuedEvent(threadId);
|
||||||
return response;
|
return response;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -276,7 +278,7 @@ export class RawDebugSession implements IRawDebugSession {
|
||||||
public stepBack(args: DebugProtocol.StepBackArguments): TPromise<DebugProtocol.StepBackResponse> {
|
public stepBack(args: DebugProtocol.StepBackArguments): TPromise<DebugProtocol.StepBackResponse> {
|
||||||
return this.send('stepBack', args).then(response => {
|
return this.send('stepBack', args).then(response => {
|
||||||
if (response.body === undefined) {
|
if (response.body === undefined) {
|
||||||
this.fireFakeContinued(args.threadId);
|
this.fireSimulatedContinuedEvent(args.threadId);
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
});
|
});
|
||||||
|
@ -285,7 +287,7 @@ export class RawDebugSession implements IRawDebugSession {
|
||||||
public reverseContinue(args: DebugProtocol.ReverseContinueArguments): TPromise<DebugProtocol.ReverseContinueResponse> {
|
public reverseContinue(args: DebugProtocol.ReverseContinueArguments): TPromise<DebugProtocol.ReverseContinueResponse> {
|
||||||
return this.send('reverseContinue', args).then(response => {
|
return this.send('reverseContinue', args).then(response => {
|
||||||
if (response.body === undefined) {
|
if (response.body === undefined) {
|
||||||
this.fireFakeContinued(args.threadId);
|
this.fireSimulatedContinuedEvent(args.threadId);
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
});
|
});
|
||||||
|
@ -340,7 +342,6 @@ export class RawDebugSession implements IRawDebugSession {
|
||||||
this.cachedInitDebugAdapterP = startSessionP.then(() => {
|
this.cachedInitDebugAdapterP = startSessionP.then(() => {
|
||||||
this.startTime = new Date().getTime();
|
this.startTime = new Date().getTime();
|
||||||
}, err => {
|
}, err => {
|
||||||
this.cachedInitDebugAdapterP = null;
|
|
||||||
return TPromise.wrapError(err);
|
return TPromise.wrapError(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -396,7 +397,6 @@ export class RawDebugSession implements IRawDebugSession {
|
||||||
|
|
||||||
private onDebugAdapterExit(code: number): void {
|
private onDebugAdapterExit(code: number): void {
|
||||||
this.debugAdapter = null;
|
this.debugAdapter = null;
|
||||||
this.cachedInitDebugAdapterP = null;
|
|
||||||
if (!this.disconnected && code !== 0) {
|
if (!this.disconnected && code !== 0) {
|
||||||
this._onDidExitAdapter.fire(new Error(`exit code: ${code}`));
|
this._onDidExitAdapter.fire(new Error(`exit code: ${code}`));
|
||||||
} else {
|
} else {
|
||||||
|
@ -415,17 +415,17 @@ export class RawDebugSession implements IRawDebugSession {
|
||||||
success: true
|
success: true
|
||||||
};
|
};
|
||||||
|
|
||||||
const sendResponse = (response) => this.debugAdapter && this.debugAdapter.sendResponse(response);
|
const safeSendResponse = (response) => this.debugAdapter && this.debugAdapter.sendResponse(response);
|
||||||
|
|
||||||
switch (request.command) {
|
switch (request.command) {
|
||||||
case 'runInTerminal':
|
case 'runInTerminal':
|
||||||
this._debugger.runInTerminal(<DebugProtocol.RunInTerminalRequestArguments>request.arguments).then(_ => {
|
this._debugger.runInTerminal(<DebugProtocol.RunInTerminalRequestArguments>request.arguments).then(_ => {
|
||||||
response.body = {};
|
response.body = {};
|
||||||
sendResponse(response);
|
safeSendResponse(response);
|
||||||
}, err => {
|
}, err => {
|
||||||
response.success = false;
|
response.success = false;
|
||||||
response.message = err.message;
|
response.message = err.message;
|
||||||
sendResponse(response);
|
safeSendResponse(response);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 'handshake':
|
case 'handshake':
|
||||||
|
@ -436,17 +436,17 @@ export class RawDebugSession implements IRawDebugSession {
|
||||||
response.body = {
|
response.body = {
|
||||||
signature: sig
|
signature: sig
|
||||||
};
|
};
|
||||||
sendResponse(response);
|
safeSendResponse(response);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
response.success = false;
|
response.success = false;
|
||||||
response.message = e.message;
|
response.message = e.message;
|
||||||
sendResponse(response);
|
safeSendResponse(response);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
response.success = false;
|
response.success = false;
|
||||||
response.message = `unknown request '${request.command}'`;
|
response.message = `unknown request '${request.command}'`;
|
||||||
sendResponse(response);
|
safeSendResponse(response);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -510,14 +510,13 @@ export class RawDebugSession implements IRawDebugSession {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private readCapabilities(response: DebugProtocol.Response): DebugProtocol.Response {
|
private readCapabilities(response: DebugProtocol.Response): void {
|
||||||
if (response) {
|
if (response) {
|
||||||
this._capabilities = objects.mixin(this._capabilities, response.body);
|
this._capabilities = objects.mixin(this._capabilities, response.body);
|
||||||
}
|
}
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fireFakeContinued(threadId: number, allThreadsContinued = false): void {
|
private fireSimulatedContinuedEvent(threadId: number, allThreadsContinued = false): void {
|
||||||
this._onDidContinued.fire({
|
this._onDidContinued.fire({
|
||||||
type: 'event',
|
type: 'event',
|
||||||
event: 'continued',
|
event: 'continued',
|
||||||
|
@ -533,7 +532,6 @@ export class RawDebugSession implements IRawDebugSession {
|
||||||
|
|
||||||
if (/* this.socket !== null */ this.debugAdapter instanceof SocketDebugAdapter) {
|
if (/* this.socket !== null */ this.debugAdapter instanceof SocketDebugAdapter) {
|
||||||
this.debugAdapter.stopSession();
|
this.debugAdapter.stopSession();
|
||||||
this.cachedInitDebugAdapterP = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this._onDidExitAdapter.fire(error);
|
this._onDidExitAdapter.fire(error);
|
||||||
|
|
|
@ -223,11 +223,7 @@ export class MockRawSession implements IRawDebugSession {
|
||||||
return TPromise.as(null);
|
return TPromise.as(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public launch(args: DebugProtocol.LaunchRequestArguments): TPromise<DebugProtocol.LaunchResponse> {
|
public launchOrAttach(args: IConfig): TPromise<DebugProtocol.Response> {
|
||||||
return TPromise.as(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public attach(args: DebugProtocol.AttachRequestArguments): TPromise<DebugProtocol.AttachResponse> {
|
|
||||||
return TPromise.as(null);
|
return TPromise.as(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue