Skip to content

Commit

Permalink
debug: column breakpoint -> inline breakpoint
Browse files Browse the repository at this point in the history
fixes #49503
  • Loading branch information
isidorn committed May 10, 2018
1 parent 6a1833f commit bf3a9a9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/vs/code/electron-main/menus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ export class CodeMenu {
const toggleBreakpoint = this.createMenuItem(nls.localize({ key: 'miToggleBreakpoint', comment: ['&& denotes a mnemonic'] }, "Toggle &&Breakpoint"), 'editor.debug.action.toggleBreakpoint');
const breakpointsMenu = new Menu();
breakpointsMenu.append(this.createMenuItem(nls.localize({ key: 'miConditionalBreakpoint', comment: ['&& denotes a mnemonic'] }, "&&Conditional Breakpoint..."), 'editor.debug.action.conditionalBreakpoint'));
breakpointsMenu.append(this.createMenuItem(nls.localize({ key: 'miColumnBreakpoint', comment: ['&& denotes a mnemonic'] }, "C&&olumn Breakpoint"), 'editor.debug.action.toggleColumnBreakpoint'));
breakpointsMenu.append(this.createMenuItem(nls.localize({ key: 'miInlineBreakpoint', comment: ['&& denotes a mnemonic'] }, "Inline Breakp&&oint"), 'editor.debug.action.toggleInlineBreakpoint'));
breakpointsMenu.append(this.createMenuItem(nls.localize({ key: 'miFunctionBreakpoint', comment: ['&& denotes a mnemonic'] }, "&&Function Breakpoint..."), 'workbench.debug.viewlet.action.addFunctionBreakpointAction'));
breakpointsMenu.append(this.createMenuItem(nls.localize({ key: 'miLogPoint', comment: ['&& denotes a mnemonic'] }, "&&Logpoint..."), 'editor.debug.action.toggleLogPoint'));
const newBreakpoints = new MenuItem({ label: this.mnemonicLabel(nls.localize({ key: 'miNewBreakpoint', comment: ['&& denotes a mnemonic'] }, "&&New Breakpoint")), submenu: breakpointsMenu });
Expand Down
60 changes: 33 additions & 27 deletions src/vs/workbench/parts/debug/browser/debugCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { openBreakpointSource } from 'vs/workbench/parts/debug/browser/breakpointsView';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { InputFocusedContext } from 'vs/platform/workbench/common/contextkeys';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';

export function registerCommands(): void {

Expand Down Expand Up @@ -197,46 +198,51 @@ export function registerCommands(): void {
}
});

const COLUMN_BREAKPOINT_COMMAND_ID = 'editor.debug.action.toggleColumnBreakpoint';
const INLINE_BREAKPOINT_COMMAND_ID = 'editor.debug.action.toggleInlineBreakpoint';
const inlineBreakpointHandler = (accessor) => {
const debugService = accessor.get(IDebugService);
const editorService = accessor.get(IWorkbenchEditorService);
const editor = editorService.getActiveEditor();
const control = editor && <ICodeEditor>editor.getControl();
if (control) {
const position = control.getPosition();
const modelUri = control.getModel().uri;
const bp = debugService.getModel().getBreakpoints({ lineNumber: position.lineNumber, uri: modelUri })
.filter(bp => (bp.column === position.column || !bp.column && position.column <= 1)).pop();

if (bp) {
return TPromise.as(null);
}
if (debugService.getConfigurationManager().canSetBreakpointsIn(control.getModel())) {
return debugService.addBreakpoints(modelUri, [{ lineNumber: position.lineNumber, column: position.column > 1 ? position.column : undefined }]);
}
}

return TPromise.as(null);
};
KeybindingsRegistry.registerCommandAndKeybindingRule({
weight: KeybindingsRegistry.WEIGHT.workbenchContrib(),
primary: KeyMod.Shift | KeyCode.F9,
when: EditorContextKeys.editorTextFocus,
id: COLUMN_BREAKPOINT_COMMAND_ID,
handler: (accessor) => {
const debugService = accessor.get(IDebugService);
const editorService = accessor.get(IWorkbenchEditorService);
const editor = editorService.getActiveEditor();
const control = editor && <ICodeEditor>editor.getControl();
if (control) {
const position = control.getPosition();
const modelUri = control.getModel().uri;
const bp = debugService.getModel().getBreakpoints({ lineNumber: position.lineNumber, uri: modelUri })
.filter(bp => (bp.column === position.column || !bp.column && position.column <= 1)).pop();

if (bp) {
return TPromise.as(null);
}
if (debugService.getConfigurationManager().canSetBreakpointsIn(control.getModel())) {
return debugService.addBreakpoints(modelUri, [{ lineNumber: position.lineNumber, column: position.column > 1 ? position.column : undefined }]);
}
}

return TPromise.as(null);
}
id: INLINE_BREAKPOINT_COMMAND_ID,
handler: inlineBreakpointHandler
});
CommandsRegistry.registerCommand({
id: 'editor.debug.action.toggleColumnBreakpoint',
handler: inlineBreakpointHandler
});

MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
command: {
id: COLUMN_BREAKPOINT_COMMAND_ID,
title: nls.localize('columnBreakpoint', "Column Breakpoint"),
id: INLINE_BREAKPOINT_COMMAND_ID,
title: nls.localize('inlineBreakpoint', "Inline Breakpoint"),
category: nls.localize('debug', "Debug")
}
});
MenuRegistry.appendMenuItem(MenuId.EditorContext, {
command: {
id: COLUMN_BREAKPOINT_COMMAND_ID,
title: nls.localize('addColumnBreakpoint', "Add Column Breakpoint")
id: INLINE_BREAKPOINT_COMMAND_ID,
title: nls.localize('addInlineBreakpoint', "Add Inline Breakpoint")
},
when: ContextKeyExpr.and(CONTEXT_IN_DEBUG_MODE, CONTEXT_NOT_IN_DEBUG_REPL, EditorContextKeys.writable),
group: 'debug',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,16 @@ export class DebugEditorContribution implements IDebugEditorContribution {
} else if (breakpoints.length > 1) {
const sorted = breakpoints.slice().sort((first, second) => first.column - second.column);
actions.push(new ContextSubMenu(nls.localize('removeBreakpoints', "Remove Breakpoints"), sorted.map(bp => new Action(
'removeColumnBreakpoint',
bp.column ? nls.localize('removeBreakpointOnColumn', "Remove Breakpoint on Column {0}", bp.column) : nls.localize('removeLineBreakpoint', "Remove Line Breakpoint"),
'removeInlineBreakpoint',
bp.column ? nls.localize('removeInlineBreakpointOnColumn', "Remove Inline Breakpoint on Column {0}", bp.column) : nls.localize('removeLineBreakpoint', "Remove Line Breakpoint"),
null,
true,
() => this.debugService.removeBreakpoints(bp.getId())
))));

actions.push(new ContextSubMenu(nls.localize('editBreakpoints', "Edit Breakpoints"), sorted.map(bp =>
new Action('editBreakpoint',
bp.column ? nls.localize('editBreakpointOnColumn', "Edit Breakpoint on Column {0}", bp.column) : nls.localize('editLineBrekapoint', "Edit Line Breakpoint"),
bp.column ? nls.localize('editInlineBreakpointOnColumn', "Edit Inline Breakpoint on Column {0}", bp.column) : nls.localize('editLineBrekapoint', "Edit Line Breakpoint"),
null,
true,
() => TPromise.as(this.editor.getContribution<IDebugEditorContribution>(EDITOR_CONTRIBUTION_ID).showBreakpointWidget(bp.lineNumber, bp.column))
Expand All @@ -135,8 +135,8 @@ export class DebugEditorContribution implements IDebugEditorContribution {

actions.push(new ContextSubMenu(nls.localize('enableDisableBreakpoints', "Enable/Disable Breakpoints"), sorted.map(bp => new Action(
bp.enabled ? 'disableColumnBreakpoint' : 'enableColumnBreakpoint',
bp.enabled ? (bp.column ? nls.localize('disableColumnBreakpoint', "Disable Breakpoint on Column {0}", bp.column) : nls.localize('disableBreakpointOnLine', "Disable Line Breakpoint"))
: (bp.column ? nls.localize('enableBreakpoints', "Enable Breakpoint on Column {0}", bp.column) : nls.localize('enableBreakpointOnLine', "Enable Line Breakpoint")),
bp.enabled ? (bp.column ? nls.localize('disableInlineColumnBreakpoint', "Disable Inline Breakpoint on Column {0}", bp.column) : nls.localize('disableBreakpointOnLine', "Disable Line Breakpoint"))
: (bp.column ? nls.localize('enableBreakpoints', "Enable Inline Breakpoint on Column {0}", bp.column) : nls.localize('enableBreakpointOnLine', "Enable Line Breakpoint")),
null,
true,
() => this.debugService.enableOrDisableBreakpoints(!bp.enabled, bp)
Expand Down

0 comments on commit bf3a9a9

Please sign in to comment.