提交 57db1cf6 编写于 作者: I isidor

debug polish: addBreakpoints instead of toggle

上级 7a0b01b2
...@@ -88,11 +88,13 @@ export class BreakpointWidget extends ZoneWidget { ...@@ -88,11 +88,13 @@ export class BreakpointWidget extends ZoneWidget {
}; };
// if there is already a breakpoint on this location - remove it. // 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())) { const oldBreakpoint = this.debugService.getModel().getBreakpoints()
this.debugService.toggleBreakpoint(raw).done(null, errors.onUnexpectedError); .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(); this.dispose();
......
...@@ -64,7 +64,7 @@ export class DebugEditorContribution implements debug.IDebugEditorContribution { ...@@ -64,7 +64,7 @@ export class DebugEditorContribution implements debug.IDebugEditorContribution {
nls.localize('addBreakpoint', "Add Breakpoint"), nls.localize('addBreakpoint', "Add Breakpoint"),
null, null,
true, 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)); 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 { ...@@ -94,7 +94,14 @@ export class DebugEditorContribution implements debug.IDebugEditorContribution {
getActionsContext: () => breakpoint getActionsContext: () => breakpoint
}); });
} else { } 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 }]);
}
} }
})); }));
......
...@@ -998,9 +998,7 @@ export class BreakpointsController extends BaseDebugController { ...@@ -998,9 +998,7 @@ export class BreakpointsController extends BaseDebugController {
protected onDelete(tree: tree.ITree, event: IKeyboardEvent): boolean { protected onDelete(tree: tree.ITree, event: IKeyboardEvent): boolean {
const element = tree.getFocus(); const element = tree.getFocus();
if (element instanceof model.Breakpoint) { if (element instanceof model.Breakpoint) {
const bp = <model.Breakpoint> element; this.debugService.removeBreakpoints((<model.Breakpoint> element).getId()).done(null, errors.onUnexpectedError);
this.debugService.toggleBreakpoint({ uri: bp.source.uri, lineNumber: bp.lineNumber }).done(null, errors.onUnexpectedError);
return true; return true;
} else if (element instanceof model.FunctionBreakpoint) { } else if (element instanceof model.FunctionBreakpoint) {
const fbp = <model.FunctionBreakpoint> element; const fbp = <model.FunctionBreakpoint> element;
......
...@@ -119,7 +119,7 @@ export interface IEnablement extends ITreeElement { ...@@ -119,7 +119,7 @@ export interface IEnablement extends ITreeElement {
export interface IRawBreakpoint { export interface IRawBreakpoint {
uri: uri; uri: uri;
lineNumber: number; lineNumber: number;
enabled: boolean; enabled?: boolean;
condition?: string; condition?: string;
} }
...@@ -305,7 +305,7 @@ export interface IDebugService { ...@@ -305,7 +305,7 @@ export interface IDebugService {
* General breakpoints manipulation. * General breakpoints manipulation.
*/ */
setBreakpointsForModel(modelUri: uri, rawData: IRawBreakpoint[]): void; setBreakpointsForModel(modelUri: uri, rawData: IRawBreakpoint[]): void;
toggleBreakpoint(IRawBreakpoint): TPromise<void>; addBreakpoints(rawBreakpoints: IRawBreakpoint[]): TPromise<void[]>;
enableOrDisableAllBreakpoints(enabled: boolean): TPromise<void>; enableOrDisableAllBreakpoints(enabled: boolean): TPromise<void>;
toggleEnablement(element: IEnablement): TPromise<void>; toggleEnablement(element: IEnablement): TPromise<void>;
setBreakpointsActivated(activated: boolean): TPromise<void>; setBreakpointsActivated(activated: boolean): TPromise<void>;
......
...@@ -270,7 +270,7 @@ export class RemoveBreakpointAction extends AbstractDebugAction { ...@@ -270,7 +270,7 @@ export class RemoveBreakpointAction extends AbstractDebugAction {
} }
public run(breakpoint: debug.IBreakpoint): TPromise<any> { public run(breakpoint: debug.IBreakpoint): TPromise<any> {
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()); : this.debugService.removeFunctionBreakpoints(breakpoint.getId());
} }
} }
...@@ -465,15 +465,15 @@ export class ToggleBreakpointAction extends EditorAction { ...@@ -465,15 +465,15 @@ export class ToggleBreakpointAction extends EditorAction {
} }
public run(): TPromise<any> { public run(): TPromise<any> {
if (this.debugService.state !== debug.State.Disabled) { const lineNumber = this.editor.getPosition().lineNumber;
const lineNumber = this.editor.getPosition().lineNumber; const modelUrl = this.editor.getModel().getAssociatedResource();
const modelUrl = this.editor.getModel().getAssociatedResource(); if (this.debugService.getConfigurationManager().canSetBreakpointsIn(this.editor.getModel())) {
if (this.debugService.getConfigurationManager().canSetBreakpointsIn(this.editor.getModel())) { const bp = this.debugService.getModel().getBreakpoints()
return this.debugService.toggleBreakpoint({ uri: modelUrl, lineNumber: lineNumber }); .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 { ...@@ -490,11 +490,9 @@ export class EditorConditionalBreakpointAction extends EditorAction {
} }
public run(): TPromise<any> { public run(): TPromise<any> {
if (this.debugService.state !== debug.State.Disabled) { const lineNumber = this.editor.getPosition().lineNumber;
const lineNumber = this.editor.getPosition().lineNumber; if (this.debugService.getConfigurationManager().canSetBreakpointsIn(this.editor.getModel())) {
if (this.debugService.getConfigurationManager().canSetBreakpointsIn(this.editor.getModel())) { BreakpointWidget.createInstance(<editorbrowser.ICodeEditor>this.editor, lineNumber, this.instantiationService);
BreakpointWidget.createInstance(<editorbrowser.ICodeEditor>this.editor, lineNumber, this.instantiationService);
}
} }
return TPromise.as(null); return TPromise.as(null);
...@@ -533,18 +531,18 @@ export class RunToCursorAction extends EditorAction { ...@@ -533,18 +531,18 @@ export class RunToCursorAction extends EditorAction {
this.debugService = debugService; this.debugService = debugService;
} }
public run(): TPromise<boolean> { public run(): TPromise<void> {
const lineNumber = this.editor.getPosition().lineNumber; const lineNumber = this.editor.getPosition().lineNumber;
const uri = this.editor.getModel().getAssociatedResource(); const uri = this.editor.getModel().getAssociatedResource();
this.debugService.getActiveSession().addOneTimeListener(debug.SessionEvents.STOPPED, () => { 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.addBreakpoints([{ uri, lineNumber }]).then(() => {
return this.debugService.getActiveSession().continue({ threadId: this.debugService.getViewModel().getFocusedThreadId() }).then(response => { this.debugService.getActiveSession().continue({ threadId: this.debugService.getViewModel().getFocusedThreadId() });
return response.success;
});
}); });
} }
......
...@@ -432,17 +432,6 @@ export class DebugService implements debug.IDebugService { ...@@ -432,17 +432,6 @@ export class DebugService implements debug.IDebugService {
this.model.addBreakpoints(rawData); this.model.addBreakpoints(rawData);
} }
public toggleBreakpoint(rawBreakpoint: debug.IRawBreakpoint): TPromise<void> {
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<void>{ public enableOrDisableAllBreakpoints(enabled: boolean): TPromise<void>{
this.model.enableOrDisableAllBreakpoints(enabled); this.model.enableOrDisableAllBreakpoints(enabled);
return this.sendAllBreakpoints(); return this.sendAllBreakpoints();
...@@ -460,6 +449,13 @@ export class DebugService implements debug.IDebugService { ...@@ -460,6 +449,13 @@ export class DebugService implements debug.IDebugService {
return this.sendExceptionBreakpoints(); return this.sendExceptionBreakpoints();
} }
public addBreakpoints(rawBreakpoints: debug.IRawBreakpoint[]): TPromise<void[]> {
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<any> { public removeBreakpoints(id?: string): TPromise<any> {
const toRemove = this.model.getBreakpoints().filter(bp => !id || bp.getId() === id); 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); const urisToClear = arrays.distinct(toRemove, bp => bp.source.uri.toString()).map(bp => bp.source.uri);
......
...@@ -39,7 +39,7 @@ export class MockDebugService implements debug.IDebugService { ...@@ -39,7 +39,7 @@ export class MockDebugService implements debug.IDebugService {
public setBreakpointsForModel(modelUri: uri, rawData: debug.IRawBreakpoint[]): void {} public setBreakpointsForModel(modelUri: uri, rawData: debug.IRawBreakpoint[]): void {}
public toggleBreakpoint(IRawBreakpoint): TPromise<void> { public addBreakpoints(rawBreakpoints: debug.IRawBreakpoint[]): TPromise<void[]> {
return TPromise.as(null); return TPromise.as(null);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册