From 57db1cf687c3b438d08647d463534feb69f9dfa2 Mon Sep 17 00:00:00 2001 From: isidor Date: Tue, 19 Apr 2016 15:23:01 +0200 Subject: [PATCH] debug polish: addBreakpoints instead of toggle --- .../parts/debug/browser/breakpointWidget.ts | 8 ++-- .../debug/browser/debugEditorContribution.ts | 11 +++++- .../parts/debug/browser/debugViewer.ts | 4 +- src/vs/workbench/parts/debug/common/debug.ts | 4 +- .../debug/electron-browser/debugActions.ts | 38 +++++++++---------- .../debug/electron-browser/debugService.ts | 18 ++++----- .../debug/test/common/mockDebugService.ts | 2 +- 7 files changed, 43 insertions(+), 42 deletions(-) diff --git a/src/vs/workbench/parts/debug/browser/breakpointWidget.ts b/src/vs/workbench/parts/debug/browser/breakpointWidget.ts index 1bc0df70604..d3bf0ac60eb 100644 --- a/src/vs/workbench/parts/debug/browser/breakpointWidget.ts +++ b/src/vs/workbench/parts/debug/browser/breakpointWidget.ts @@ -88,11 +88,13 @@ export class BreakpointWidget extends ZoneWidget { }; // if there is already a breakpoint on this location - remove it. - if (this.debugService.getModel().getBreakpoints().some(bp => bp.lineNumber === this.lineNumber && bp.source.uri.toString() === uri.toString())) { - this.debugService.toggleBreakpoint(raw).done(null, errors.onUnexpectedError); + const oldBreakpoint = this.debugService.getModel().getBreakpoints() + .filter(bp => bp.lineNumber === this.lineNumber && bp.source.uri.toString() === uri.toString()).pop(); + if (oldBreakpoint) { + this.debugService.removeBreakpoints(oldBreakpoint.getId()).done(null, errors.onUnexpectedError); } - this.debugService.toggleBreakpoint(raw).done(null, errors.onUnexpectedError); + this.debugService.addBreakpoints([raw]).done(null, errors.onUnexpectedError); } this.dispose(); diff --git a/src/vs/workbench/parts/debug/browser/debugEditorContribution.ts b/src/vs/workbench/parts/debug/browser/debugEditorContribution.ts index f0771a2a2d0..184a9a70bb2 100644 --- a/src/vs/workbench/parts/debug/browser/debugEditorContribution.ts +++ b/src/vs/workbench/parts/debug/browser/debugEditorContribution.ts @@ -64,7 +64,7 @@ export class DebugEditorContribution implements debug.IDebugEditorContribution { nls.localize('addBreakpoint', "Add Breakpoint"), null, true, - () => this.debugService.toggleBreakpoint({ uri, lineNumber }) + () => this.debugService.addBreakpoints([{ uri, lineNumber }]) )); actions.push(this.instantiationService.createInstance(debugactions.AddConditionalBreakpointAction, debugactions.AddConditionalBreakpointAction.ID, debugactions.AddConditionalBreakpointAction.LABEL, this.editor, lineNumber)); } @@ -94,7 +94,14 @@ export class DebugEditorContribution implements debug.IDebugEditorContribution { getActionsContext: () => breakpoint }); } else { - this.debugService.toggleBreakpoint({ uri, lineNumber }); + const breakpoint = this.debugService.getModel().getBreakpoints() + .filter(bp => bp.source.uri.toString() === uri.toString() && bp.lineNumber === lineNumber).pop(); + + if (breakpoint) { + this.debugService.removeBreakpoints(breakpoint.getId()); + } else { + this.debugService.addBreakpoints([{ uri, lineNumber }]); + } } })); diff --git a/src/vs/workbench/parts/debug/browser/debugViewer.ts b/src/vs/workbench/parts/debug/browser/debugViewer.ts index cd4297cda68..fca42a91ead 100644 --- a/src/vs/workbench/parts/debug/browser/debugViewer.ts +++ b/src/vs/workbench/parts/debug/browser/debugViewer.ts @@ -998,9 +998,7 @@ export class BreakpointsController extends BaseDebugController { protected onDelete(tree: tree.ITree, event: IKeyboardEvent): boolean { const element = tree.getFocus(); if (element instanceof model.Breakpoint) { - const bp = element; - this.debugService.toggleBreakpoint({ uri: bp.source.uri, lineNumber: bp.lineNumber }).done(null, errors.onUnexpectedError); - + this.debugService.removeBreakpoints(( element).getId()).done(null, errors.onUnexpectedError); return true; } else if (element instanceof model.FunctionBreakpoint) { const fbp = element; diff --git a/src/vs/workbench/parts/debug/common/debug.ts b/src/vs/workbench/parts/debug/common/debug.ts index 9253fa784de..249163f25e0 100644 --- a/src/vs/workbench/parts/debug/common/debug.ts +++ b/src/vs/workbench/parts/debug/common/debug.ts @@ -119,7 +119,7 @@ export interface IEnablement extends ITreeElement { export interface IRawBreakpoint { uri: uri; lineNumber: number; - enabled: boolean; + enabled?: boolean; condition?: string; } @@ -305,7 +305,7 @@ export interface IDebugService { * General breakpoints manipulation. */ setBreakpointsForModel(modelUri: uri, rawData: IRawBreakpoint[]): void; - toggleBreakpoint(IRawBreakpoint): TPromise; + addBreakpoints(rawBreakpoints: IRawBreakpoint[]): TPromise; enableOrDisableAllBreakpoints(enabled: boolean): TPromise; toggleEnablement(element: IEnablement): TPromise; setBreakpointsActivated(activated: boolean): TPromise; diff --git a/src/vs/workbench/parts/debug/electron-browser/debugActions.ts b/src/vs/workbench/parts/debug/electron-browser/debugActions.ts index ac6742b76e3..7d627c70375 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugActions.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugActions.ts @@ -270,7 +270,7 @@ export class RemoveBreakpointAction extends AbstractDebugAction { } public run(breakpoint: debug.IBreakpoint): TPromise { - return breakpoint instanceof model.Breakpoint ? this.debugService.toggleBreakpoint({ uri: breakpoint.source.uri, lineNumber: breakpoint.lineNumber }) + return breakpoint instanceof model.Breakpoint ? this.debugService.removeBreakpoints(breakpoint.getId()) : this.debugService.removeFunctionBreakpoints(breakpoint.getId()); } } @@ -465,15 +465,15 @@ export class ToggleBreakpointAction extends EditorAction { } public run(): TPromise { - if (this.debugService.state !== debug.State.Disabled) { - const lineNumber = this.editor.getPosition().lineNumber; - const modelUrl = this.editor.getModel().getAssociatedResource(); - if (this.debugService.getConfigurationManager().canSetBreakpointsIn(this.editor.getModel())) { - return this.debugService.toggleBreakpoint({ uri: modelUrl, lineNumber: lineNumber }); - } - } + const lineNumber = this.editor.getPosition().lineNumber; + const modelUrl = this.editor.getModel().getAssociatedResource(); + if (this.debugService.getConfigurationManager().canSetBreakpointsIn(this.editor.getModel())) { + const bp = this.debugService.getModel().getBreakpoints() + .filter(bp => bp.lineNumber === lineNumber && bp.source.uri.toString() === modelUrl.toString()).pop(); - return TPromise.as(null); + return bp ? this.debugService.removeBreakpoints(bp.getId()) + : this.debugService.addBreakpoints([{ uri: modelUrl, lineNumber: lineNumber }]); + } } } @@ -490,11 +490,9 @@ export class EditorConditionalBreakpointAction extends EditorAction { } public run(): TPromise { - if (this.debugService.state !== debug.State.Disabled) { - const lineNumber = this.editor.getPosition().lineNumber; - if (this.debugService.getConfigurationManager().canSetBreakpointsIn(this.editor.getModel())) { - BreakpointWidget.createInstance(this.editor, lineNumber, this.instantiationService); - } + const lineNumber = this.editor.getPosition().lineNumber; + if (this.debugService.getConfigurationManager().canSetBreakpointsIn(this.editor.getModel())) { + BreakpointWidget.createInstance(this.editor, lineNumber, this.instantiationService); } return TPromise.as(null); @@ -533,18 +531,18 @@ export class RunToCursorAction extends EditorAction { this.debugService = debugService; } - public run(): TPromise { + public run(): TPromise { const lineNumber = this.editor.getPosition().lineNumber; const uri = this.editor.getModel().getAssociatedResource(); this.debugService.getActiveSession().addOneTimeListener(debug.SessionEvents.STOPPED, () => { - this.debugService.toggleBreakpoint({ uri, lineNumber }); + const toRemove = this.debugService.getModel().getBreakpoints() + .filter(bp => bp.lineNumber === lineNumber && bp.source.uri.toString() === uri.toString()).pop(); + this.debugService.removeBreakpoints(toRemove.getId()); }); - return this.debugService.toggleBreakpoint({ uri, lineNumber }).then(() => { - return this.debugService.getActiveSession().continue({ threadId: this.debugService.getViewModel().getFocusedThreadId() }).then(response => { - return response.success; - }); + return this.debugService.addBreakpoints([{ uri, lineNumber }]).then(() => { + this.debugService.getActiveSession().continue({ threadId: this.debugService.getViewModel().getFocusedThreadId() }); }); } diff --git a/src/vs/workbench/parts/debug/electron-browser/debugService.ts b/src/vs/workbench/parts/debug/electron-browser/debugService.ts index 5b56bc05ef8..a7455ccec87 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugService.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugService.ts @@ -432,17 +432,6 @@ export class DebugService implements debug.IDebugService { this.model.addBreakpoints(rawData); } - public toggleBreakpoint(rawBreakpoint: debug.IRawBreakpoint): TPromise { - const breakpoint = this.model.getBreakpoints().filter(bp => bp.lineNumber === rawBreakpoint.lineNumber && bp.source.uri.toString() === rawBreakpoint.uri.toString()).pop(); - if (breakpoint) { - this.model.removeBreakpoints([breakpoint]); - } else { - this.model.addBreakpoints([rawBreakpoint]); - } - - return this.sendBreakpoints(rawBreakpoint.uri); - } - public enableOrDisableAllBreakpoints(enabled: boolean): TPromise{ this.model.enableOrDisableAllBreakpoints(enabled); return this.sendAllBreakpoints(); @@ -460,6 +449,13 @@ export class DebugService implements debug.IDebugService { return this.sendExceptionBreakpoints(); } + public addBreakpoints(rawBreakpoints: debug.IRawBreakpoint[]): TPromise { + this.model.addBreakpoints(rawBreakpoints); + const uris = arrays.distinct(rawBreakpoints, raw => raw.uri.toString()).map(raw => raw.uri); + + return TPromise.join(uris.map(uri => this.sendBreakpoints(uri))); + } + public removeBreakpoints(id?: string): TPromise { const toRemove = this.model.getBreakpoints().filter(bp => !id || bp.getId() === id); const urisToClear = arrays.distinct(toRemove, bp => bp.source.uri.toString()).map(bp => bp.source.uri); diff --git a/src/vs/workbench/parts/debug/test/common/mockDebugService.ts b/src/vs/workbench/parts/debug/test/common/mockDebugService.ts index 0e16c3aac06..c61235f8d1d 100644 --- a/src/vs/workbench/parts/debug/test/common/mockDebugService.ts +++ b/src/vs/workbench/parts/debug/test/common/mockDebugService.ts @@ -39,7 +39,7 @@ export class MockDebugService implements debug.IDebugService { public setBreakpointsForModel(modelUri: uri, rawData: debug.IRawBreakpoint[]): void {} - public toggleBreakpoint(IRawBreakpoint): TPromise { + public addBreakpoints(rawBreakpoints: debug.IRawBreakpoint[]): TPromise { return TPromise.as(null); } -- GitLab