From a08885ecd075d066b80c08e4e34f8a9377acddfc Mon Sep 17 00:00:00 2001 From: isidor Date: Tue, 19 Apr 2016 10:16:41 +0200 Subject: [PATCH] debug: polish IRawDebugSession --- .../debug/browser/debugEditorModelManager.ts | 2 +- .../parts/debug/browser/debugHover.ts | 2 +- src/vs/workbench/parts/debug/common/debug.ts | 16 ++++++++++--- .../debug/electron-browser/debugActions.ts | 8 +++---- .../debug/electron-browser/debugService.ts | 14 +++++------ .../parts/debug/node/rawDebugSession.ts | 23 +++++++++++-------- .../debug/test/common/mockDebugService.ts | 10 ++++---- 7 files changed, 46 insertions(+), 29 deletions(-) diff --git a/src/vs/workbench/parts/debug/browser/debugEditorModelManager.ts b/src/vs/workbench/parts/debug/browser/debugEditorModelManager.ts index 0fb0077ad7e..c346a956f2b 100644 --- a/src/vs/workbench/parts/debug/browser/debugEditorModelManager.ts +++ b/src/vs/workbench/parts/debug/browser/debugEditorModelManager.ts @@ -282,7 +282,7 @@ export class DebugEditorModelManager implements IWorkbenchContribution { } return result ? result : - !session || session.capabilities.supportsConditionalBreakpoints ? { + !session || session.configuration.capabilities.supportsConditionalBreakpoints ? { glyphMarginClassName: 'debug-breakpoint-conditional-glyph', hoverMessage: breakpoint.condition, stickiness: editorcommon.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges diff --git a/src/vs/workbench/parts/debug/browser/debugHover.ts b/src/vs/workbench/parts/debug/browser/debugHover.ts index 17a0948c125..98eb9d9783e 100644 --- a/src/vs/workbench/parts/debug/browser/debugHover.ts +++ b/src/vs/workbench/parts/debug/browser/debugHover.ts @@ -126,7 +126,7 @@ export class DebugHoverWidget implements editorbrowser.IContentWidget { private getExpression(namesToFind: string[]): TPromise { const session = this.debugService.getActiveSession(); const focusedStackFrame = this.debugService.getViewModel().getFocusedStackFrame(); - if (session.capabilities.supportsEvaluateForHovers) { + if (session.configuration.capabilities.supportsEvaluateForHovers) { return evaluateExpression(session, focusedStackFrame, new Expression(namesToFind.join('.'), true), 'hover'); } diff --git a/src/vs/workbench/parts/debug/common/debug.ts b/src/vs/workbench/parts/debug/common/debug.ts index ac6174d25c0..cdfc3957fa1 100644 --- a/src/vs/workbench/parts/debug/common/debug.ts +++ b/src/vs/workbench/parts/debug/common/debug.ts @@ -56,8 +56,19 @@ export interface IExpression extends ITreeElement, IExpressionContainer { } export interface IThread extends ITreeElement { + /** + * Id of the thread generated by the debug adapter backend. + */ threadId: number; + + /** + * Name of the thread. + */ name: string; + + /** + * Information about the current thread stop event. Null if thread is not stopped. + */ stoppedDetails: IRawStoppedDetails; /** @@ -237,9 +248,8 @@ export interface IRawAdapter extends IRawEnvAdapter { } export interface IRawDebugSession extends ee.EventEmitter { - getType(): string; - isAttach: boolean; - capabilities: DebugProtocol.Capabilites; + configuration: { type: string, isAttach: boolean, capabilities: DebugProtocol.Capabilites }; + disconnect(restart?: boolean, force?: boolean): TPromise; next(args: DebugProtocol.NextArguments): TPromise; diff --git a/src/vs/workbench/parts/debug/electron-browser/debugActions.ts b/src/vs/workbench/parts/debug/electron-browser/debugActions.ts index ea3378b2eef..345311ed939 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugActions.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugActions.ts @@ -137,7 +137,7 @@ export class RestartDebugAction extends AbstractDebugAction { this.toDispose.push(this.debugService.onDidChangeState(() => { const session = this.debugService.getActiveSession(); if (session) { - this.updateLabel(session.isAttach ? RestartDebugAction.RECONNECT_LABEL : RestartDebugAction.LABEL); + this.updateLabel(session.configuration.isAttach ? RestartDebugAction.RECONNECT_LABEL : RestartDebugAction.LABEL); } })); } @@ -212,7 +212,7 @@ export class StopDebugAction extends AbstractDebugAction { this.toDispose.push(this.debugService.onDidChangeState(() => { const session = this.debugService.getActiveSession(); if (session) { - this.updateLabel(session.isAttach ? StopDebugAction.DISCONNECT_LABEL : StopDebugAction.LABEL); + this.updateLabel(session.configuration.isAttach ? StopDebugAction.DISCONNECT_LABEL : StopDebugAction.LABEL); } })); } @@ -493,7 +493,7 @@ export class CopyValueAction extends AbstractDebugAction { if (this.value instanceof model.Variable) { const frameId = this.debugService.getViewModel().getFocusedStackFrame().frameId; const session = this.debugService.getActiveSession(); - return session.evaluate({ expression: model.getFullExpressionName(this.value, session.getType()), frameId }).then(result => { + return session.evaluate({ expression: model.getFullExpressionName(this.value, session.configuration.type), frameId }).then(result => { clipboard.writeText(result.body.result); }, err => clipboard.writeText(this.value.value)); } @@ -644,7 +644,7 @@ export class AddToWatchExpressionsAction extends AbstractDebugAction { } public run(): TPromise { - return this.debugService.addWatchExpression(model.getFullExpressionName(this.expression, this.debugService.getActiveSession().getType())); + return this.debugService.addWatchExpression(model.getFullExpressionName(this.expression, this.debugService.getActiveSession().configuration.type)); } } diff --git a/src/vs/workbench/parts/debug/electron-browser/debugService.ts b/src/vs/workbench/parts/debug/electron-browser/debugService.ts index deeb1ee11b3..ec8fadb61d5 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugService.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugService.ts @@ -151,7 +151,7 @@ export class DebugService implements debug.IDebugService { // from this point on we require an active session let session = this.getActiveSession(); - if (!session || session.getType() !== 'extensionHost') { + if (!session || session.configuration.type !== 'extensionHost') { return; // we are only intersted if we have an active debug session for extensionHost } @@ -232,7 +232,7 @@ export class DebugService implements debug.IDebugService { this.toDisposeOnSessionEnd.push(this.session.addListener2(debug.SessionEvents.INITIALIZED, (event: DebugProtocol.InitializedEvent) => { aria.status(nls.localize('debuggingStarted', "Debugging started.")); this.sendAllBreakpoints().then(() => { - if (this.session.capabilities.supportsConfigurationDoneRequest) { + if (this.session.configuration.capabilities.supportsConfigurationDoneRequest) { this.session.configurationDone().done(null, errors.onUnexpectedError); } }); @@ -327,7 +327,7 @@ export class DebugService implements debug.IDebugService { this.toDisposeOnSessionEnd.push(this.session.addListener2(debug.SessionEvents.SERVER_EXIT, event => { // 'Run without debugging' mode VSCode must terminate the extension host. More details: #3905 - if (this.session.getType() === 'extensionHost' && this.state === debug.State.RunningNoDebug) { + if (this.session.configuration.type === 'extensionHost' && this.state === debug.State.RunningNoDebug) { ipc.send('vscode:closeExtensionHostWindow', this.contextService.getWorkspace().resource.fsPath); } if (this.session && this.session.getId() === event.sessionId) { @@ -604,7 +604,7 @@ export class DebugService implements debug.IDebugService { return TPromise.wrapError(new Error(nls.localize('debugAdapterCrash', "Debug adapter process has terminated unexpectedly"))); } - this.model.setExceptionBreakpoints(this.session.capabilities.exceptionBreakpointFilters); + this.model.setExceptionBreakpoints(this.session.configuration.capabilities.exceptionBreakpointFilters); return configuration.request === 'attach' ? this.session.attach(configuration) : this.session.launch(configuration); }).then((result: DebugProtocol.Response) => { if (changeViewState) { @@ -682,7 +682,7 @@ export class DebugService implements debug.IDebugService { private rawAttach(port: number): TPromise { if (this.session) { - if (!this.session.isAttach) { + if (!this.session.configuration.isAttach) { return this.session.attach({ port }); } @@ -719,7 +719,7 @@ export class DebugService implements debug.IDebugService { if (this.session) { const bpsExist = this.model.getBreakpoints().length > 0; this.telemetryService.publicLog('debugSessionStop', { - type: this.session.getType(), + type: this.session.configuration.type, success: this.session.emittedStopped || !bpsExist, sessionLengthInSeconds: this.session.getLengthInSeconds(), breakpointCount: this.model.getBreakpoints().length, @@ -875,7 +875,7 @@ export class DebugService implements debug.IDebugService { } private sendFunctionBreakpoints(): TPromise { - if (!this.session || !this.session.readyForBreakpoints || !this.session.capabilities.supportsFunctionBreakpoints) { + if (!this.session || !this.session.readyForBreakpoints || !this.session.configuration.capabilities.supportsFunctionBreakpoints) { return TPromise.as(null); } diff --git a/src/vs/workbench/parts/debug/node/rawDebugSession.ts b/src/vs/workbench/parts/debug/node/rawDebugSession.ts index 318efc2b930..c1d9393d99c 100644 --- a/src/vs/workbench/parts/debug/node/rawDebugSession.ts +++ b/src/vs/workbench/parts/debug/node/rawDebugSession.ts @@ -22,15 +22,17 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { shell } from 'electron'; export class RawDebugSession extends v8.V8Protocol implements debug.IRawDebugSession { + + public restarted: boolean; + private serverProcess: cp.ChildProcess; private socket: net.Socket = null; private cachedInitServer: TPromise; private startTime: number; private stopServerPending: boolean; private sentPromises: TPromise[]; - public isAttach: boolean; - public restarted: boolean; - public capabilities: DebugProtocol.Capabilites; + private isAttach: boolean; + private capabilities: DebugProtocol.Capabilites; constructor( private messageService: IMessageService, @@ -40,7 +42,6 @@ export class RawDebugSession extends v8.V8Protocol implements debug.IRawDebugSes private telemtryAdapter: AIAdapter ) { super(); - this.capabilities = {}; this.sentPromises = []; } @@ -87,9 +88,17 @@ export class RawDebugSession extends v8.V8Protocol implements debug.IRawDebugSes }); } + public get configuration(): { type: string, isAttach: boolean, capabilities: DebugProtocol.Capabilites } { + return { + type: this.adapter.type, + isAttach: this.isAttach, + capabilities: this.capabilities || {} + }; + } + public initialize(args: DebugProtocol.InitializeRequestArguments): TPromise { return this.send('initialize', args).then(response => { - this.capabilities = response.body || this.capabilities; + this.capabilities = response.body; return response; }); } @@ -206,10 +215,6 @@ export class RawDebugSession extends v8.V8Protocol implements debug.IRawDebugSes return (new Date().getTime() - this.startTime) / 1000; } - public getType(): string { - return this.adapter.type; - } - private connectServer(port: number): TPromise { return new TPromise((c, e) => { this.socket = net.createConnection(port, '127.0.0.1', () => { diff --git a/src/vs/workbench/parts/debug/test/common/mockDebugService.ts b/src/vs/workbench/parts/debug/test/common/mockDebugService.ts index 9975b52d85a..f3ae8b5ec88 100644 --- a/src/vs/workbench/parts/debug/test/common/mockDebugService.ts +++ b/src/vs/workbench/parts/debug/test/common/mockDebugService.ts @@ -126,11 +126,13 @@ export class MockDebugService implements debug.IDebugService { class MockRawSession extends ee.EventEmitter implements debug.IRawDebugSession { - public isAttach: boolean = false; - public capabilities: DebugProtocol.Capabilites; - public getType(): string { - return null; + public get configuration(): { type: string, isAttach: boolean, capabilities: DebugProtocol.Capabilites } { + return { + type: 'mock', + isAttach: false, + capabilities: {} + }; } public disconnect(restart?: boolean, force?: boolean): TPromise { -- GitLab