Skip to content

Commit 9bada78

Browse files
authored
Merge pull request microsoft#50285 from Krzysztof-Cieslak/goToNextPreviousBreakpoint
Implement Go To Next/Previous Breakpoint editor actions
2 parents 13cc56a + cabd09a commit 9bada78

3 files changed

Lines changed: 67 additions & 2 deletions

File tree

src/vs/workbench/parts/debug/browser/breakpointsView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ class FunctionBreakpointInputRenderer implements IRenderer<IFunctionBreakpoint,
519519
}
520520
}
521521

522-
export function openBreakpointSource(breakpoint: Breakpoint, sideBySide: boolean, preserveFocus: boolean, debugService: IDebugService, editorService: IEditorService): TPromise<IEditor> {
522+
export function openBreakpointSource(breakpoint: IBreakpoint, sideBySide: boolean, preserveFocus: boolean, debugService: IDebugService, editorService: IEditorService): TPromise<IEditor> {
523523
if (breakpoint.uri.scheme === DEBUG_SCHEME && debugService.state === State.Inactive) {
524524
return TPromise.as(null);
525525
}

src/vs/workbench/parts/debug/browser/debugEditorActions.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { IDebugService, CONTEXT_IN_DEBUG_MODE, CONTEXT_NOT_IN_DEBUG_REPL, CONTEX
1414
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
1515
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
1616
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
17+
import { IEditorService } from 'vs/platform/editor/common/editor';
18+
import { openBreakpointSource } from 'vs/workbench/parts/debug/browser/breakpointsView';
1719

1820
class ToggleBreakpointAction extends EditorAction {
1921
constructor() {
@@ -209,10 +211,73 @@ class ShowDebugHoverAction extends EditorAction {
209211
}
210212
}
211213

214+
class GoToBreakpointAction extends EditorAction {
215+
constructor(private isNext, opts) {
216+
super(opts);
217+
}
218+
219+
public run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void | TPromise<void, any> {
220+
const debugService = accessor.get(IDebugService);
221+
const editorService = accessor.get(IEditorService);
222+
const currentUri = editor.getModel().uri;
223+
const currentLine = editor.getPosition().lineNumber;
224+
//Breakpoints returned from `getBreakpoints` are already sorted.
225+
const allEnabledBreakpoints = debugService.getModel().getBreakpoints({ enabledOnly: true });
226+
227+
//Try to find breakpoint in current file
228+
let moveBreakpoint =
229+
this.isNext
230+
? allEnabledBreakpoints.filter(bp => bp.uri.toString() === currentUri.toString() && bp.lineNumber > currentLine)[0]
231+
: allEnabledBreakpoints.filter(bp => bp.uri.toString() === currentUri.toString() && bp.lineNumber < currentLine)[0];
232+
233+
//Try to find breakpoints in following files
234+
if (!moveBreakpoint) {
235+
moveBreakpoint =
236+
this.isNext
237+
? allEnabledBreakpoints.filter(bp => bp.uri.toString() > currentUri.toString())[0]
238+
: allEnabledBreakpoints.filter(bp => bp.uri.toString() < currentUri.toString())[0];
239+
}
240+
241+
//Move to first possible breakpoint
242+
if (!moveBreakpoint) {
243+
moveBreakpoint = allEnabledBreakpoints[0];
244+
}
245+
246+
if (moveBreakpoint) {
247+
openBreakpointSource(moveBreakpoint, false, true, debugService, editorService);
248+
}
249+
return TPromise.as(null);
250+
}
251+
}
252+
253+
class GoToNextBreakpointAction extends GoToBreakpointAction {
254+
constructor() {
255+
super(true, {
256+
id: 'editor.debug.action.goToNextBreakpoint',
257+
label: nls.localize('goToNextBreakpoint', "Debug: Go To Next Breakpoint"),
258+
alias: 'Debug: Go To Next Breakpoint',
259+
precondition: null
260+
});
261+
}
262+
}
263+
264+
class GoToPreviousBreakpointAction extends GoToBreakpointAction {
265+
constructor() {
266+
super(false, {
267+
id: 'editor.debug.action.goToPreviousBreakpoint',
268+
label: nls.localize('goToPreviousBreakpoint', "Debug: Go To Previous Breakpoint"),
269+
alias: 'Debug: Go To Previous Breakpoint',
270+
precondition: null
271+
});
272+
}
273+
}
274+
212275
registerEditorAction(ToggleBreakpointAction);
213276
registerEditorAction(ConditionalBreakpointAction);
214277
registerEditorAction(LogPointAction);
215278
registerEditorAction(RunToCursorAction);
216279
registerEditorAction(SelectionToReplAction);
217280
registerEditorAction(SelectionToWatchExpressionsAction);
218281
registerEditorAction(ShowDebugHoverAction);
282+
registerEditorAction(GoToNextBreakpointAction);
283+
registerEditorAction(GoToPreviousBreakpointAction);

src/vs/workbench/parts/debug/common/debug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ export interface IViewModel extends ITreeElement {
311311

312312
export interface IModel extends ITreeElement {
313313
getSessions(): ReadonlyArray<ISession>;
314-
getBreakpoints(filter?: { uri?: uri, lineNumber?: number, column?: number }): ReadonlyArray<IBreakpoint>;
314+
getBreakpoints(filter?: { uri?: uri, lineNumber?: number, column?: number, enabledOnly?: boolean }): ReadonlyArray<IBreakpoint>;
315315
areBreakpointsActivated(): boolean;
316316
getFunctionBreakpoints(): ReadonlyArray<IFunctionBreakpoint>;
317317
getExceptionBreakpoints(): ReadonlyArray<IExceptionBreakpoint>;

0 commit comments

Comments
 (0)