Skip to content

Commit

Permalink
Issue 163528/create edit breakpoint command (microsoft#163734)
Browse files Browse the repository at this point in the history
* Add edit breakpoint command

* Match to closest breakpoint
  • Loading branch information
MonadChains authored Dec 31, 2022
1 parent 818b05e commit 6d7e511
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/vs/workbench/contrib/debug/browser/debugEditorActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,51 @@ class LogPointAction extends EditorAction {
}
}

class EditBreakpointAction extends EditorAction {
constructor() {
super({
id: 'editor.debug.action.editBreakpoint',
label: nls.localize('EditBreakpointEditorAction', "Debug: Edit Breakpoint"),
alias: 'Debug: Edit Existing Breakpoint',
precondition: CONTEXT_DEBUGGERS_AVAILABLE,
menuOpts: {
menuId: MenuId.MenubarNewBreakpointMenu,
title: nls.localize({ key: 'miEditBreakpoint', comment: ['&& denotes a mnemonic'] }, "&&Edit Breakpoint"),
group: '1_breakpoints',
order: 1,
when: CONTEXT_DEBUGGERS_AVAILABLE
}
});
}

async run(accessor: ServicesAccessor, editor: ICodeEditor): Promise<void> {
const debugService = accessor.get(IDebugService);

const position = editor.getPosition();
const debugModel = debugService.getModel();
if (!(editor.hasModel() && position)) {
return;
}

const lineBreakpoints = debugModel.getBreakpoints({ lineNumber: position.lineNumber });
if (lineBreakpoints.length === 0) {
return;
}

const breakpointDistances = lineBreakpoints.map(b => {
if (!b.column) {
return position.column;
}

return Math.abs(b.column - position.column);
});
const closestBreakpointIndex = breakpointDistances.indexOf(Math.min(...breakpointDistances));
const closestBreakpoint = lineBreakpoints[closestBreakpointIndex];

editor.getContribution<IBreakpointEditorContribution>(BREAKPOINT_EDITOR_CONTRIBUTION_ID)?.showBreakpointWidget(closestBreakpoint.lineNumber, closestBreakpoint.column);
}
}

class OpenDisassemblyViewAction extends EditorAction2 {

public static readonly ID = 'editor.debug.action.openDisassemblyView';
Expand Down Expand Up @@ -508,6 +553,7 @@ registerAction2(ToggleDisassemblyViewSourceCodeAction);
registerEditorAction(ToggleBreakpointAction);
registerEditorAction(ConditionalBreakpointAction);
registerEditorAction(LogPointAction);
registerEditorAction(EditBreakpointAction);
registerEditorAction(RunToCursorAction);
registerEditorAction(StepIntoTargetsAction);
registerEditorAction(SelectionToReplAction);
Expand Down

0 comments on commit 6d7e511

Please sign in to comment.