From 6d7e511b5c372a7e65790ed16402ba79436aa59c Mon Sep 17 00:00:00 2001 From: MonadChains Date: Sat, 31 Dec 2022 01:57:03 +0100 Subject: [PATCH] Issue 163528/create edit breakpoint command (#163734) * Add edit breakpoint command * Match to closest breakpoint --- .../debug/browser/debugEditorActions.ts | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/vs/workbench/contrib/debug/browser/debugEditorActions.ts b/src/vs/workbench/contrib/debug/browser/debugEditorActions.ts index de72a8152f829..3e54dec51f56a 100644 --- a/src/vs/workbench/contrib/debug/browser/debugEditorActions.ts +++ b/src/vs/workbench/contrib/debug/browser/debugEditorActions.ts @@ -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 { + 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(BREAKPOINT_EDITOR_CONTRIBUTION_ID)?.showBreakpointWidget(closestBreakpoint.lineNumber, closestBreakpoint.column); + } +} + class OpenDisassemblyViewAction extends EditorAction2 { public static readonly ID = 'editor.debug.action.openDisassemblyView'; @@ -508,6 +553,7 @@ registerAction2(ToggleDisassemblyViewSourceCodeAction); registerEditorAction(ToggleBreakpointAction); registerEditorAction(ConditionalBreakpointAction); registerEditorAction(LogPointAction); +registerEditorAction(EditBreakpointAction); registerEditorAction(RunToCursorAction); registerEditorAction(StepIntoTargetsAction); registerEditorAction(SelectionToReplAction);