Permalink
Switch branches/tags
1.11 aeschli/bundled-app-insights aeschli/json-tests aeschli/tokenizersupport-initialization alex/binary-rpc alex/snapshot2 alex/35225 alexr00/problemMatcher alexr00/rerunTask avoid-fssync build-using-ts-3.0 chines-locale chrmarti/cloudshellts chrmarti/embeddedEditorBackground chrmarti/quickinputapi chrmarti/quickinputapioptions chrmarti/quickinputapiwip chrmarti/vsc-proxy chrmarti/51986 chrmarti/57850 chrmarti/59343 chrmarti/60243 chrmarti/62716 core-lang css-json-shrinkwrap dbaeumer/47386 dbaeumer/48032 dbaeumer/50588 dbaeumer/50799 dbaeumer/54111 dbaeumer/56721 dbaeumer/57148 dbaeumer/61543 dbaeumer/64918 dockfind electron-3.0.x electron-4.0.x err-telemetry error file-ext-tag-telemetry fix-64613 fix-indent fix-menu-leak for-christof hackathon/profile implementation-progress isidorn/buildTest isidorn/debugLogging isidorn/explorerNewTree isidorn/lazyFormatter isidorn/loadedScriptSchedulers isidorn/normalizePaths isidorn/openEditorsContext isidorn/replDynamicHeight isidorn/resourceTrimTrailingSlash isidorn/taskActiveEvent isidorn/zenModeRestore joao/build joao/clean-deps joao/compile-es6 joao/darwin-executable-name joao/data-tree-model joao/git-api joao/hh joao/inno-signtool joao/ipc-cancellation joao/ipc-rpc joao/keyvault joao/linux-integration-tests joao/list-dnd joao/list-selectable-rows joao/log-path joao/next joao/tree-filter joao/tree-view-state joao/tree joao/uninstaller joao/wip-tree joaomoreno-patch-1 joh/brackets joh/fix59538 joh/leak joh/log-appender joh/next joh/outline joh/perf-canary joh/promise-finally joh/search-cancel joh/webpack-json kieferrm/errortel kieferrm/mainDebug master misolori/a11y-themes misolori/activity-bar-update misolori/light-theme-icons-selection-dont-work misolori/light-theme-icons misolori/open-change-icons misolori/seti-update misolori/welcome-screen-keys mjbvz/fix-60315 mjbvz/remove-std-fork mjbvz/trigger-context octref/contributing octref/web-component octref/58555 octref/64993 optout-locale php-html-enter-rules prompt-lang-pack ramyar/copy-suggest-docs ramyar/reload-subtext ramyar/suggest-no-icons rebornix/ESM rebornix/FastTokenization rebornix/commentsgrouping rebornix/nativeWordOperation rebornix/review rebornix/search-in-parallel release/1.14 release/1.15 release/1.16 release/1.17 release/1.18 release/1.19 release/1.20 release/1.21 release/1.22 release/1.23 release/1.24 release/1.25 release/1.26 release/1.27 release/1.28 release/1.29 release/1.30 reuse-focuseditem revert-52782-electron-2.0.x revert-54854-revert-52782-electron-2.0.x rmacfarlane/debug-process rmacfarlane/debug rmacfarlane/delete-comments rmacfarlane/unsupported roblou/cachedSearchProvider roblou/caseInsensitiveGlobs roblou/ehSearch roblou/fileSearchChanges roblou/fileTextSearchSep roblou/findFilesUri roblou/fixCRLFmultiline roblou/fixSearchCancel roblou/promoteExtLogAPI roblou/searchAPIchanges roblou/settingsEditorAsTree roblou/settingsSearchIdChanges sandy081/fix62411 sandy081/openUri sandy081/treeItemDecorations sandy081/vnext sandy081/54315 sandy081/54746 sandy081/55879 sandy081/59603 settings-contrib settings-polish show-english standalone/0.1.x standalone/0.1.1 standalone/0.6.x standalone/0.7.x standalone/0.8.x standalone/0.10.x standalone/0.11.x standalone/0.12.x standalone/0.13.x standalone/0.14.x standalone/0.15.x triggerExpansionOnTab tsalinger/multipath-handling-quoted-backslash-in-linux tsalinger/multipath-reveal-children tyriar/conpty tyriar/dom_render tyriar/electron-1.8.2 tyriar/snap tyriar/term_ligatures tyriar/term_ligatures2 tyriar/term_tele tyriar/54093_buffering umd update-event versionBump win32-ia32-builds win32-sign
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
266 lines (242 sloc) 10.4 KB
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { List } from 'vs/base/browser/ui/list/listWidget';
import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { IListService } from 'vs/platform/list/browser/listService';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { IDebugService, IEnablement, CONTEXT_BREAKPOINTS_FOCUSED, CONTEXT_WATCH_EXPRESSIONS_FOCUSED, CONTEXT_VARIABLES_FOCUSED, EDITOR_CONTRIBUTION_ID, IDebugEditorContribution, CONTEXT_IN_DEBUG_MODE, CONTEXT_EXPRESSION_SELECTED, CONTEXT_BREAKPOINT_SELECTED } from 'vs/workbench/parts/debug/common/debug';
import { Expression, Variable, Breakpoint, FunctionBreakpoint } from 'vs/workbench/parts/debug/common/debugModel';
import { IExtensionsViewlet, VIEWLET_ID as EXTENSIONS_VIEWLET_ID } from 'vs/workbench/parts/extensions/common/extensions';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { ICodeEditor, isCodeEditor } from 'vs/editor/browser/editorBrowser';
import { MenuRegistry, MenuId } from 'vs/platform/actions/common/actions';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
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 { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
import { PanelFocusContext } from 'vs/workbench/browser/parts/panel/panelPart';
export const ADD_CONFIGURATION_ID = 'debug.addConfiguration';
export const TOGGLE_INLINE_BREAKPOINT_ID = 'editor.debug.action.toggleInlineBreakpoint';
export function registerCommands(): void {
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'debug.toggleBreakpoint',
weight: KeybindingWeight.WorkbenchContrib + 5,
when: ContextKeyExpr.and(CONTEXT_BREAKPOINTS_FOCUSED, InputFocusedContext.toNegated()),
primary: KeyCode.Space,
handler: (accessor) => {
const listService = accessor.get(IListService);
const debugService = accessor.get(IDebugService);
const list = listService.lastFocusedList;
if (list instanceof List) {
const focused = <IEnablement[]>list.getFocusedElements();
if (focused && focused.length) {
debugService.enableOrDisableBreakpoints(!focused[0].enabled, focused[0]);
}
}
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'debug.enableOrDisableBreakpoint',
weight: KeybindingWeight.WorkbenchContrib,
primary: undefined,
when: EditorContextKeys.editorTextFocus,
handler: (accessor) => {
const debugService = accessor.get(IDebugService);
const editorService = accessor.get(IEditorService);
const widget = editorService.activeTextEditorWidget;
if (isCodeEditor(widget)) {
const model = widget.getModel();
if (model) {
const position = widget.getPosition();
const bps = debugService.getModel().getBreakpoints({ uri: model.uri, lineNumber: position.lineNumber });
if (bps.length) {
debugService.enableOrDisableBreakpoints(!bps[0].enabled, bps[0]);
}
}
}
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'debug.renameWatchExpression',
weight: KeybindingWeight.WorkbenchContrib + 5,
when: CONTEXT_WATCH_EXPRESSIONS_FOCUSED,
primary: KeyCode.F2,
mac: { primary: KeyCode.Enter },
handler: (accessor) => {
const listService = accessor.get(IListService);
const debugService = accessor.get(IDebugService);
const focused = listService.lastFocusedList;
// Tree only
if (!(focused instanceof List)) {
const element = focused.getFocus();
if (element instanceof Expression) {
debugService.getViewModel().setSelectedExpression(element);
}
}
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'debug.setVariable',
weight: KeybindingWeight.WorkbenchContrib + 5,
when: CONTEXT_VARIABLES_FOCUSED,
primary: KeyCode.F2,
mac: { primary: KeyCode.Enter },
handler: (accessor) => {
const listService = accessor.get(IListService);
const debugService = accessor.get(IDebugService);
const focused = listService.lastFocusedList;
// Tree only
if (!(focused instanceof List)) {
const element = focused.getFocus();
if (element instanceof Variable) {
debugService.getViewModel().setSelectedExpression(element);
}
}
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'debug.removeWatchExpression',
weight: KeybindingWeight.WorkbenchContrib,
when: ContextKeyExpr.and(CONTEXT_WATCH_EXPRESSIONS_FOCUSED, CONTEXT_EXPRESSION_SELECTED.toNegated()),
primary: KeyCode.Delete,
mac: { primary: KeyMod.CtrlCmd | KeyCode.Backspace },
handler: (accessor) => {
const listService = accessor.get(IListService);
const debugService = accessor.get(IDebugService);
const focused = listService.lastFocusedList;
// Tree only
if (!(focused instanceof List)) {
const element = focused.getFocus();
if (element instanceof Expression) {
debugService.removeWatchExpressions(element.getId());
}
}
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'debug.removeBreakpoint',
weight: KeybindingWeight.WorkbenchContrib,
when: ContextKeyExpr.and(CONTEXT_BREAKPOINTS_FOCUSED, CONTEXT_BREAKPOINT_SELECTED.toNegated()),
primary: KeyCode.Delete,
mac: { primary: KeyMod.CtrlCmd | KeyCode.Backspace },
handler: (accessor) => {
const listService = accessor.get(IListService);
const debugService = accessor.get(IDebugService);
const list = listService.lastFocusedList;
// Tree only
if (list instanceof List) {
const focused = list.getFocusedElements();
const element = focused.length ? focused[0] : undefined;
if (element instanceof Breakpoint) {
debugService.removeBreakpoints(element.getId());
} else if (element instanceof FunctionBreakpoint) {
debugService.removeFunctionBreakpoints(element.getId());
}
}
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'debug.installAdditionalDebuggers',
weight: KeybindingWeight.WorkbenchContrib,
when: undefined,
primary: undefined,
handler: (accessor) => {
const viewletService = accessor.get(IViewletService);
return viewletService.openViewlet(EXTENSIONS_VIEWLET_ID, true)
.then(viewlet => viewlet as IExtensionsViewlet)
.then(viewlet => {
viewlet.search('tag:debuggers @sort:installs');
viewlet.focus();
});
}
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: ADD_CONFIGURATION_ID,
weight: KeybindingWeight.WorkbenchContrib,
when: undefined,
primary: undefined,
handler: (accessor, launchUri: string) => {
const manager = accessor.get(IDebugService).getConfigurationManager();
if (accessor.get(IWorkspaceContextService).getWorkbenchState() === WorkbenchState.EMPTY) {
accessor.get(INotificationService).info(nls.localize('noFolderDebugConfig', "Please first open a folder in order to do advanced debug configuration."));
return undefined;
}
const launch = manager.getLaunches().filter(l => l.uri.toString() === launchUri).pop() || manager.selectedConfiguration.launch;
return launch.openConfigFile(false, false).then(({ editor, created }) => {
if (editor && !created) {
const codeEditor = <ICodeEditor>editor.getControl();
if (codeEditor) {
return codeEditor.getContribution<IDebugEditorContribution>(EDITOR_CONTRIBUTION_ID).addLaunchConfiguration();
}
}
return undefined;
});
}
});
const inlineBreakpointHandler = (accessor: ServicesAccessor) => {
const debugService = accessor.get(IDebugService);
const editorService = accessor.get(IEditorService);
const widget = editorService.activeTextEditorWidget;
if (isCodeEditor(widget)) {
const position = widget.getPosition();
const modelUri = widget.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 undefined;
}
if (debugService.getConfigurationManager().canSetBreakpointsIn(widget.getModel())) {
return debugService.addBreakpoints(modelUri, [{ lineNumber: position.lineNumber, column: position.column > 1 ? position.column : undefined }], 'debugCommands.inlineBreakpointCommand');
}
}
return undefined;
};
KeybindingsRegistry.registerCommandAndKeybindingRule({
weight: KeybindingWeight.WorkbenchContrib,
primary: KeyMod.Shift | KeyCode.F9,
when: EditorContextKeys.editorTextFocus,
id: TOGGLE_INLINE_BREAKPOINT_ID,
handler: inlineBreakpointHandler
});
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
command: {
id: TOGGLE_INLINE_BREAKPOINT_ID,
title: { value: nls.localize('inlineBreakpoint', "Inline Breakpoint"), original: 'Debug: Inline Breakpoint' },
category: nls.localize('debug', "Debug")
}
});
MenuRegistry.appendMenuItem(MenuId.EditorContext, {
command: {
id: TOGGLE_INLINE_BREAKPOINT_ID,
title: nls.localize('addInlineBreakpoint', "Add Inline Breakpoint")
},
when: ContextKeyExpr.and(CONTEXT_IN_DEBUG_MODE, PanelFocusContext.toNegated(), EditorContextKeys.editorTextFocus),
group: 'debug',
order: 1
});
KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'debug.openBreakpointToSide',
weight: KeybindingWeight.WorkbenchContrib,
when: CONTEXT_BREAKPOINTS_FOCUSED,
primary: KeyMod.CtrlCmd | KeyCode.Enter,
secondary: [KeyMod.Alt | KeyCode.Enter],
handler: (accessor) => {
const listService = accessor.get(IListService);
const list = listService.lastFocusedList;
if (list instanceof List) {
const focus = list.getFocusedElements();
if (focus.length && focus[0] instanceof Breakpoint) {
return openBreakpointSource(focus[0], true, false, accessor.get(IDebugService), accessor.get(IEditorService));
}
}
return undefined;
}
});
}