Skip to content

Commit

Permalink
Merge pull request #50285 from Krzysztof-Cieslak/goToNextPreviousBrea…
Browse files Browse the repository at this point in the history
…kpoint

Implement Go To Next/Previous Breakpoint editor actions
  • Loading branch information
isidorn committed May 28, 2018
2 parents 13cc56a + cabd09a commit 9bada78
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/debug/browser/breakpointsView.ts
Expand Up @@ -519,7 +519,7 @@ class FunctionBreakpointInputRenderer implements IRenderer<IFunctionBreakpoint,
}
}

export function openBreakpointSource(breakpoint: Breakpoint, sideBySide: boolean, preserveFocus: boolean, debugService: IDebugService, editorService: IEditorService): TPromise<IEditor> {
export function openBreakpointSource(breakpoint: IBreakpoint, sideBySide: boolean, preserveFocus: boolean, debugService: IDebugService, editorService: IEditorService): TPromise<IEditor> {
if (breakpoint.uri.scheme === DEBUG_SCHEME && debugService.state === State.Inactive) {
return TPromise.as(null);
}
Expand Down
65 changes: 65 additions & 0 deletions src/vs/workbench/parts/debug/browser/debugEditorActions.ts
Expand Up @@ -14,6 +14,8 @@ import { IDebugService, CONTEXT_IN_DEBUG_MODE, CONTEXT_NOT_IN_DEBUG_REPL, CONTEX
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { IEditorService } from 'vs/platform/editor/common/editor';
import { openBreakpointSource } from 'vs/workbench/parts/debug/browser/breakpointsView';

class ToggleBreakpointAction extends EditorAction {
constructor() {
Expand Down Expand Up @@ -209,10 +211,73 @@ class ShowDebugHoverAction extends EditorAction {
}
}

class GoToBreakpointAction extends EditorAction {
constructor(private isNext, opts) {
super(opts);
}

public run(accessor: ServicesAccessor, editor: ICodeEditor, args: any): void | TPromise<void, any> {
const debugService = accessor.get(IDebugService);
const editorService = accessor.get(IEditorService);
const currentUri = editor.getModel().uri;
const currentLine = editor.getPosition().lineNumber;
//Breakpoints returned from `getBreakpoints` are already sorted.
const allEnabledBreakpoints = debugService.getModel().getBreakpoints({ enabledOnly: true });

//Try to find breakpoint in current file
let moveBreakpoint =
this.isNext
? allEnabledBreakpoints.filter(bp => bp.uri.toString() === currentUri.toString() && bp.lineNumber > currentLine)[0]
: allEnabledBreakpoints.filter(bp => bp.uri.toString() === currentUri.toString() && bp.lineNumber < currentLine)[0];

//Try to find breakpoints in following files
if (!moveBreakpoint) {
moveBreakpoint =
this.isNext
? allEnabledBreakpoints.filter(bp => bp.uri.toString() > currentUri.toString())[0]
: allEnabledBreakpoints.filter(bp => bp.uri.toString() < currentUri.toString())[0];
}

//Move to first possible breakpoint
if (!moveBreakpoint) {
moveBreakpoint = allEnabledBreakpoints[0];
}

if (moveBreakpoint) {
openBreakpointSource(moveBreakpoint, false, true, debugService, editorService);
}
return TPromise.as(null);
}
}

class GoToNextBreakpointAction extends GoToBreakpointAction {
constructor() {
super(true, {
id: 'editor.debug.action.goToNextBreakpoint',
label: nls.localize('goToNextBreakpoint', "Debug: Go To Next Breakpoint"),
alias: 'Debug: Go To Next Breakpoint',
precondition: null
});
}
}

class GoToPreviousBreakpointAction extends GoToBreakpointAction {
constructor() {
super(false, {
id: 'editor.debug.action.goToPreviousBreakpoint',
label: nls.localize('goToPreviousBreakpoint', "Debug: Go To Previous Breakpoint"),
alias: 'Debug: Go To Previous Breakpoint',
precondition: null
});
}
}

registerEditorAction(ToggleBreakpointAction);
registerEditorAction(ConditionalBreakpointAction);
registerEditorAction(LogPointAction);
registerEditorAction(RunToCursorAction);
registerEditorAction(SelectionToReplAction);
registerEditorAction(SelectionToWatchExpressionsAction);
registerEditorAction(ShowDebugHoverAction);
registerEditorAction(GoToNextBreakpointAction);
registerEditorAction(GoToPreviousBreakpointAction);
2 changes: 1 addition & 1 deletion src/vs/workbench/parts/debug/common/debug.ts
Expand Up @@ -311,7 +311,7 @@ export interface IViewModel extends ITreeElement {

export interface IModel extends ITreeElement {
getSessions(): ReadonlyArray<ISession>;
getBreakpoints(filter?: { uri?: uri, lineNumber?: number, column?: number }): ReadonlyArray<IBreakpoint>;
getBreakpoints(filter?: { uri?: uri, lineNumber?: number, column?: number, enabledOnly?: boolean }): ReadonlyArray<IBreakpoint>;
areBreakpointsActivated(): boolean;
getFunctionBreakpoints(): ReadonlyArray<IFunctionBreakpoint>;
getExceptionBreakpoints(): ReadonlyArray<IExceptionBreakpoint>;
Expand Down

0 comments on commit 9bada78

Please sign in to comment.