From f31a1f4bcfa05b14d8e49a123377e689cd0d9eb1 Mon Sep 17 00:00:00 2001 From: isidor Date: Tue, 19 Apr 2016 16:11:23 +0200 Subject: [PATCH] debug api polish: comments and remove toggleEnablement --- .../parts/debug/browser/debugViewer.ts | 4 +- src/vs/workbench/parts/debug/common/debug.ts | 56 +++++++++++++++++-- .../parts/debug/common/debugModel.ts | 14 ++--- .../debug/electron-browser/debugActions.ts | 6 +- .../debug/electron-browser/debugService.ts | 23 ++++---- .../debug/test/common/debugModel.test.ts | 2 +- .../debug/test/common/mockDebugService.ts | 10 +--- 7 files changed, 76 insertions(+), 39 deletions(-) diff --git a/src/vs/workbench/parts/debug/browser/debugViewer.ts b/src/vs/workbench/parts/debug/browser/debugViewer.ts index fca42a91ead..e9ade70b25e 100644 --- a/src/vs/workbench/parts/debug/browser/debugViewer.ts +++ b/src/vs/workbench/parts/debug/browser/debugViewer.ts @@ -905,7 +905,7 @@ export class BreakpointsRenderer implements tree.IRenderer { public renderElement(tree: tree.ITree, element: any, templateId: string, templateData: any): void { templateData.toDisposeBeforeRender = lifecycle.dispose(templateData.toDisposeBeforeRender); templateData.toDisposeBeforeRender.push(dom.addStandardDisposableListener(templateData.checkbox, 'change', (e) => { - this.debugService.toggleEnablement(element); + this.debugService.enableOrDisableBreakpoints(!element.enabled, element); })); if (templateId === BreakpointsRenderer.EXCEPTION_BREAKPOINT_TEMPLATE_ID) { @@ -989,7 +989,7 @@ export class BreakpointsController extends BaseDebugController { protected onSpace(tree: tree.ITree, event: IKeyboardEvent): boolean { super.onSpace(tree, event); const element = tree.getFocus(); - this.debugService.toggleEnablement(element).done(null, errors.onUnexpectedError); + this.debugService.enableOrDisableBreakpoints(!element.enabled, element).done(null, errors.onUnexpectedError); return true; } diff --git a/src/vs/workbench/parts/debug/common/debug.ts b/src/vs/workbench/parts/debug/common/debug.ts index 5fb131c56f8..83991b911ca 100644 --- a/src/vs/workbench/parts/debug/common/debug.ts +++ b/src/vs/workbench/parts/debug/common/debug.ts @@ -302,34 +302,78 @@ export interface IDebugService { setFocusedStackFrameAndEvaluate(focusedStackFrame: IStackFrame): TPromise; /** - * General breakpoints manipulation. + * Adds new breakpoints to the model. Notifies debug adapter of breakpoint changes. */ addBreakpoints(rawBreakpoints: IRawBreakpoint[]): TPromise; - enableOrDisableAllBreakpoints(enabled: boolean): TPromise; - toggleEnablement(element: IEnablement): TPromise; + + /** + * Enables or disables all breakpoints. If breakpoint is passed only enables or disables the passed breakpoint. + * Notifies debug adapter of breakpoint changes. + */ + enableOrDisableBreakpoints(enable: boolean, breakpoint?: IEnablement): TPromise; + + /** + * Sets the global activated property for all breakpoints. + * Notifies debug adapter of breakpoint changes. + */ setBreakpointsActivated(activated: boolean): TPromise; + + /** + * Removes all breakpoints. If id is passed only removes the breakpoint associated with that id. + * Notifies debug adapter of breakpoint changes. + */ removeBreakpoints(id?: string): TPromise; /** - * Function breakpoints manipulation. + * Adds a new no name function breakpoint. The function breakpoint should be renamed once user enters the name. */ addFunctionBreakpoint(): void; + + /** + * Renames an already existing function breakpoint. + * Notifies debug adapter of breakpoint changes. + */ renameFunctionBreakpoint(id: string, newFunctionName: string): TPromise; + + /** + * Removes all function breakpoints. If id is passed only removes the function breakpoint with the passed id. + * Notifies debug adapter of breakpoint changes. + */ removeFunctionBreakpoints(id?: string): TPromise; /** - * Repl expressions manipulation. + * Adds a new expression to the repl. */ addReplExpression(name: string): TPromise; + + /** + * Removes all repl expressions. + */ removeReplExpressions(): void; + + /** + * Adds a new log to the repl. Either a string value or a dictionary (used to inspect complex objects printed to the repl). + */ logToRepl(value: string | { [key: string]: any }, severity?: severity): void; + + /** + * Appends new output to the repl. + */ appendReplOutput(value: string, severity?: severity): void; /** - * Watch expressions manipulation. + * Adds a new watch expression and evaluates it against the debug adapter. */ addWatchExpression(name?: string): TPromise; + + /** + * Renames a watch expression and evaluates it against the debug adapter. + */ renameWatchExpression(id: string, newName: string): TPromise; + + /** + * Removes all watch expressions. If id is passed only removes the watch expression with the passed id. + */ removeWatchExpressions(id?: string): void; /** diff --git a/src/vs/workbench/parts/debug/common/debugModel.ts b/src/vs/workbench/parts/debug/common/debugModel.ts index 1a78fe39804..f2d8d54c6d6 100644 --- a/src/vs/workbench/parts/debug/common/debugModel.ts +++ b/src/vs/workbench/parts/debug/common/debugModel.ts @@ -517,8 +517,8 @@ export class Model implements debug.IModel { this._onDidChangeBreakpoints.fire(); } - public toggleEnablement(element: debug.IEnablement): void { - element.enabled = !element.enabled; + public setEnablement(element: debug.IEnablement, enable: boolean): void { + element.enabled = enable; if (element instanceof Breakpoint && !element.enabled) { var breakpoint = element; breakpoint.lineNumber = breakpoint.desiredLineNumber; @@ -528,16 +528,16 @@ export class Model implements debug.IModel { this._onDidChangeBreakpoints.fire(); } - public enableOrDisableAllBreakpoints(enabled: boolean): void { + public enableOrDisableAllBreakpoints(enable: boolean): void { this.breakpoints.forEach(bp => { - bp.enabled = enabled; - if (!enabled) { + bp.enabled = enable; + if (!enable) { bp.lineNumber = bp.desiredLineNumber; bp.verified = false; } }); - this.exceptionBreakpoints.forEach(ebp => ebp.enabled = enabled); - this.functionBreakpoints.forEach(fbp => fbp.enabled = enabled); + this.exceptionBreakpoints.forEach(ebp => ebp.enabled = enable); + this.functionBreakpoints.forEach(fbp => fbp.enabled = enable); this._onDidChangeBreakpoints.fire(); } diff --git a/src/vs/workbench/parts/debug/electron-browser/debugActions.ts b/src/vs/workbench/parts/debug/electron-browser/debugActions.ts index 7d627c70375..05864acbccf 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugActions.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugActions.ts @@ -303,7 +303,7 @@ export class ToggleEnablementAction extends AbstractDebugAction { } public run(element: debug.IEnablement): TPromise { - return this.debugService.toggleEnablement(element); + return this.debugService.enableOrDisableBreakpoints(!element.enabled, element); } } @@ -317,7 +317,7 @@ export class EnableAllBreakpointsAction extends AbstractDebugAction { } public run(): TPromise { - return this.debugService.enableOrDisableAllBreakpoints(true); + return this.debugService.enableOrDisableBreakpoints(true); } protected isEnabled(state: debug.State): boolean { @@ -336,7 +336,7 @@ export class DisableAllBreakpointsAction extends AbstractDebugAction { } public run(): TPromise { - return this.debugService.enableOrDisableAllBreakpoints(false); + return this.debugService.enableOrDisableBreakpoints(false); } protected isEnabled(state: debug.State): boolean { diff --git a/src/vs/workbench/parts/debug/electron-browser/debugService.ts b/src/vs/workbench/parts/debug/electron-browser/debugService.ts index 457f2d6608e..4628644d4ef 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugService.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugService.ts @@ -426,21 +426,20 @@ export class DebugService implements debug.IDebugService { } } - public enableOrDisableAllBreakpoints(enabled: boolean): TPromise{ - this.model.enableOrDisableAllBreakpoints(enabled); - return this.sendAllBreakpoints(); - } + public enableOrDisableBreakpoints(enable: boolean, breakpoint?: debug.IEnablement): TPromise{ + if (breakpoint) { + this.model.setEnablement(breakpoint, enable); + if (breakpoint instanceof model.Breakpoint) { + return this.sendBreakpoints(( breakpoint).source.uri); + } else if (breakpoint instanceof model.FunctionBreakpoint) { + return this.sendFunctionBreakpoints(); + } - public toggleEnablement(element: debug.IEnablement): TPromise { - this.model.toggleEnablement(element); - if (element instanceof model.Breakpoint) { - const breakpoint = element; - return this.sendBreakpoints(breakpoint.source.uri); - } else if (element instanceof model.FunctionBreakpoint) { - return this.sendFunctionBreakpoints(); + return this.sendExceptionBreakpoints(); } - return this.sendExceptionBreakpoints(); + this.model.enableOrDisableAllBreakpoints(enable); + return this.sendAllBreakpoints(); } public addBreakpoints(rawBreakpoints: debug.IRawBreakpoint[]): TPromise { diff --git a/src/vs/workbench/parts/debug/test/common/debugModel.test.ts b/src/vs/workbench/parts/debug/test/common/debugModel.test.ts index c49644e2a2d..ab05b4d3ed6 100644 --- a/src/vs/workbench/parts/debug/test/common/debugModel.test.ts +++ b/src/vs/workbench/parts/debug/test/common/debugModel.test.ts @@ -69,7 +69,7 @@ suite('Debug - Model', () => { model.getBreakpoints().forEach(bp => { assert.equal(bp.enabled, false); }); - model.toggleEnablement(bp); + model.setEnablement(bp, true); assert.equal(bp.enabled, true); model.removeBreakpoints(model.getBreakpoints().filter(bp => bp.source.uri.toString() === modelUri1.toString())); diff --git a/src/vs/workbench/parts/debug/test/common/mockDebugService.ts b/src/vs/workbench/parts/debug/test/common/mockDebugService.ts index 352476895eb..e4d5b2f9b87 100644 --- a/src/vs/workbench/parts/debug/test/common/mockDebugService.ts +++ b/src/vs/workbench/parts/debug/test/common/mockDebugService.ts @@ -41,11 +41,7 @@ export class MockDebugService implements debug.IDebugService { return TPromise.as(null); } - public enableOrDisableAllBreakpoints(enabled: boolean): TPromise { - return TPromise.as(null); - } - - public toggleEnablement(element: debug.IEnablement): TPromise { + public enableOrDisableBreakpoints(enabled: boolean): TPromise { return TPromise.as(null); } @@ -73,9 +69,7 @@ export class MockDebugService implements debug.IDebugService { public removeReplExpressions(): void {} - public logToRepl(value: string, severity?: severity): void; - public logToRepl(value: { [key: string]: any }, severity?: severity): void; - public logToRepl(value: any, severity?: severity): void {} + public logToRepl(value: string | { [key: string]: any }, severity?: severity): void {} public appendReplOutput(value: string, severity?: severity): void {} -- GitLab