Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Go To Next/Previous Breakpoint editor actions #50285

Merged
merged 4 commits into from May 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

editor Model can be null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really checked in any other place in the file ;-)

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