diff --git a/src/vs/workbench/parts/debug/browser/breakpointWidget.ts b/src/vs/workbench/parts/debug/browser/breakpointWidget.ts index 1bc0df706049f6f8bb54647980484d8b285ded4d..d3bf0ac60eb1d9423d2ccbba7cb2a6ea6aeaa61c 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 f0771a2a2d09f27c63486b348da5d66a4545cc01..184a9a70bb240dff31adccc8dc91adb826a8cf2f 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 cd4297cda68c2cfb608b8033e814357806323803..fca42a91eadcfa738905a20e5ad3d9841f9de6ae 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 9253fa784deb7efbfef20eca48ca9b0bcb020a88..249163f25e086e5b5d0f913f496c2415305cc340 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 ac6742b76e3d2b1ce22e0d9dc3125409a45ae4cc..7d627c7037516fb71be3d6f8e6315dde3adac213 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 5b56bc05ef8b718eaac79a16ea139c04d46e15c8..a7455ccec8780e53262341214d3720f643c597bb 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 0e16c3aac06d6304a54e0c39eb4418ab706e9962..c61235f8d1d42116da990d18c97f7e221c8be95c 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); }