Skip to content

Commit 080f9ce

Browse files
authored
Add quick access for debug consoles (microsoft#152505)
* Add quick access for debug consoles Fixes microsoft#151771 * Remove circular dependency * replace string literals * Address PR feedback
1 parent 324f237 commit 080f9ce

File tree

4 files changed

+100
-7
lines changed

4 files changed

+100
-7
lines changed

src/vs/workbench/contrib/debug/browser/debug.contribution.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
} from 'vs/workbench/contrib/debug/common/debug';
2121
import { DebugToolBar } from 'vs/workbench/contrib/debug/browser/debugToolBar';
2222
import { DebugService } from 'vs/workbench/contrib/debug/browser/debugService';
23-
import { ADD_CONFIGURATION_ID, TOGGLE_INLINE_BREAKPOINT_ID, COPY_STACK_TRACE_ID, RESTART_SESSION_ID, TERMINATE_THREAD_ID, STEP_OVER_ID, STEP_INTO_ID, STEP_OUT_ID, PAUSE_ID, DISCONNECT_ID, STOP_ID, RESTART_FRAME_ID, CONTINUE_ID, FOCUS_REPL_ID, JUMP_TO_CURSOR_ID, RESTART_LABEL, STEP_INTO_LABEL, STEP_OVER_LABEL, STEP_OUT_LABEL, PAUSE_LABEL, DISCONNECT_LABEL, STOP_LABEL, CONTINUE_LABEL, DEBUG_START_LABEL, DEBUG_START_COMMAND_ID, DEBUG_RUN_LABEL, DEBUG_RUN_COMMAND_ID, EDIT_EXPRESSION_COMMAND_ID, REMOVE_EXPRESSION_COMMAND_ID, SELECT_AND_START_ID, SELECT_AND_START_LABEL, SET_EXPRESSION_COMMAND_ID, DISCONNECT_AND_SUSPEND_ID, DISCONNECT_AND_SUSPEND_LABEL, NEXT_DEBUG_CONSOLE_ID, NEXT_DEBUG_CONSOLE_LABEL, PREV_DEBUG_CONSOLE_ID, PREV_DEBUG_CONSOLE_LABEL } from 'vs/workbench/contrib/debug/browser/debugCommands';
23+
import { ADD_CONFIGURATION_ID, TOGGLE_INLINE_BREAKPOINT_ID, COPY_STACK_TRACE_ID, RESTART_SESSION_ID, TERMINATE_THREAD_ID, STEP_OVER_ID, STEP_INTO_ID, STEP_OUT_ID, PAUSE_ID, DISCONNECT_ID, STOP_ID, RESTART_FRAME_ID, CONTINUE_ID, FOCUS_REPL_ID, JUMP_TO_CURSOR_ID, RESTART_LABEL, STEP_INTO_LABEL, STEP_OVER_LABEL, STEP_OUT_LABEL, PAUSE_LABEL, DISCONNECT_LABEL, STOP_LABEL, CONTINUE_LABEL, DEBUG_START_LABEL, DEBUG_START_COMMAND_ID, DEBUG_RUN_LABEL, DEBUG_RUN_COMMAND_ID, EDIT_EXPRESSION_COMMAND_ID, REMOVE_EXPRESSION_COMMAND_ID, SELECT_AND_START_ID, SELECT_AND_START_LABEL, SET_EXPRESSION_COMMAND_ID, DISCONNECT_AND_SUSPEND_ID, DISCONNECT_AND_SUSPEND_LABEL, NEXT_DEBUG_CONSOLE_ID, NEXT_DEBUG_CONSOLE_LABEL, PREV_DEBUG_CONSOLE_ID, PREV_DEBUG_CONSOLE_LABEL, SELECT_DEBUG_CONSOLE_ID, SELECT_DEBUG_CONSOLE_LABEL, DEBUG_CONSOLE_QUICK_ACCESS_PREFIX, DEBUG_QUICK_ACCESS_PREFIX } from 'vs/workbench/contrib/debug/browser/debugCommands';
2424
import { StatusBarColorProvider } from 'vs/workbench/contrib/debug/browser/statusbarColorProvider';
2525
import { IViewsRegistry, Extensions as ViewExtensions, IViewContainersRegistry, ViewContainerLocation, ViewContainer } from 'vs/workbench/common/views';
2626
import { isMacintosh, isWeb } from 'vs/base/common/platform';
@@ -57,6 +57,7 @@ import { DisassemblyViewInput } from 'vs/workbench/contrib/debug/common/disassem
5757
import { DebugLifecycle } from 'vs/workbench/contrib/debug/common/debugLifecycle';
5858
import { Icon } from 'vs/platform/action/common/action';
5959
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
60+
import { DebugConsoleQuickAccess } from 'vs/workbench/contrib/debug/browser/debugConsoleQuickAccess';
6061

6162
const debugCategory = nls.localize('debugCategory', "Debug");
6263
registerColors();
@@ -77,12 +78,21 @@ Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).regi
7778
// Register Quick Access
7879
Registry.as<IQuickAccessRegistry>(QuickAccessExtensions.Quickaccess).registerQuickAccessProvider({
7980
ctor: StartDebugQuickAccessProvider,
80-
prefix: StartDebugQuickAccessProvider.PREFIX,
81+
prefix: DEBUG_QUICK_ACCESS_PREFIX,
8182
contextKey: 'inLaunchConfigurationsPicker',
8283
placeholder: nls.localize('startDebugPlaceholder', "Type the name of a launch configuration to run."),
8384
helpEntries: [{ description: nls.localize('startDebuggingHelp', "Start Debugging"), commandId: SELECT_AND_START_ID }]
8485
});
8586

87+
// Register quick access for debug console
88+
Registry.as<IQuickAccessRegistry>(QuickAccessExtensions.Quickaccess).registerQuickAccessProvider({
89+
ctor: DebugConsoleQuickAccess,
90+
prefix: DEBUG_CONSOLE_QUICK_ACCESS_PREFIX,
91+
contextKey: 'inDebugConsolePicker',
92+
placeholder: nls.localize('tasksQuickAccessPlaceholder', "Type the name of a debug console to open."),
93+
helpEntries: [{ description: nls.localize('tasksQuickAccessHelp', "Show All Debug Consoles"), commandId: SELECT_DEBUG_CONSOLE_ID }]
94+
});
95+
8696

8797
registerEditorContribution('editor.contrib.callStack', CallStackEditorContribution);
8898
registerEditorContribution(BREAKPOINT_EDITOR_CONTRIBUTION_ID, BreakpointEditorContribution);
@@ -122,6 +132,7 @@ registerDebugCommandPaletteItem(DEBUG_RUN_COMMAND_ID, DEBUG_RUN_LABEL, ContextKe
122132
registerDebugCommandPaletteItem(SELECT_AND_START_ID, SELECT_AND_START_LABEL, ContextKeyExpr.and(CONTEXT_DEBUGGERS_AVAILABLE, CONTEXT_DEBUG_STATE.notEqualsTo(getStateLabel(State.Initializing))));
123133
registerDebugCommandPaletteItem(NEXT_DEBUG_CONSOLE_ID, NEXT_DEBUG_CONSOLE_LABEL);
124134
registerDebugCommandPaletteItem(PREV_DEBUG_CONSOLE_ID, PREV_DEBUG_CONSOLE_LABEL);
135+
registerDebugCommandPaletteItem(SELECT_DEBUG_CONSOLE_ID, SELECT_DEBUG_CONSOLE_LABEL);
125136

126137

127138
// Debug callstack context menu

src/vs/workbench/contrib/debug/browser/debugCommands.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export const FOCUS_REPL_ID = 'workbench.debug.action.focusRepl';
5252
export const JUMP_TO_CURSOR_ID = 'debug.jumpToCursor';
5353
export const FOCUS_SESSION_ID = 'workbench.action.debug.focusProcess';
5454
export const SELECT_AND_START_ID = 'workbench.action.debug.selectandstart';
55+
export const SELECT_DEBUG_CONSOLE_ID = 'workbench.action.debug.selectDebugConsole';
5556
export const DEBUG_CONFIGURE_COMMAND_ID = 'workbench.action.debug.configure';
5657
export const DEBUG_START_COMMAND_ID = 'workbench.action.debug.start';
5758
export const DEBUG_RUN_COMMAND_ID = 'workbench.action.debug.run';
@@ -77,6 +78,10 @@ export const DEBUG_START_LABEL = nls.localize('startDebug', "Start Debugging");
7778
export const DEBUG_RUN_LABEL = nls.localize('startWithoutDebugging', "Start Without Debugging");
7879
export const NEXT_DEBUG_CONSOLE_LABEL = nls.localize('nextDebugConsole', "Focus Next Debug Console");
7980
export const PREV_DEBUG_CONSOLE_LABEL = nls.localize('prevDebugConsole', "Focus Previous Debug Console");
81+
export const SELECT_DEBUG_CONSOLE_LABEL = nls.localize('selectDebugConsole', "Select Debug Console");
82+
83+
export const DEBUG_QUICK_ACCESS_PREFIX = 'debug ';
84+
export const DEBUG_CONSOLE_QUICK_ACCESS_PREFIX = 'debug consoles ';
8085

8186
interface CallStackContext {
8287
sessionId: string;
@@ -471,7 +476,15 @@ CommandsRegistry.registerCommand({
471476
id: SELECT_AND_START_ID,
472477
handler: async (accessor: ServicesAccessor) => {
473478
const quickInputService = accessor.get(IQuickInputService);
474-
quickInputService.quickAccess.show('debug ');
479+
quickInputService.quickAccess.show(DEBUG_QUICK_ACCESS_PREFIX);
480+
}
481+
});
482+
483+
CommandsRegistry.registerCommand({
484+
id: SELECT_DEBUG_CONSOLE_ID,
485+
handler: async (accessor: ServicesAccessor) => {
486+
const quickInputService = accessor.get(IQuickInputService);
487+
quickInputService.quickAccess.show(DEBUG_CONSOLE_QUICK_ACCESS_PREFIX);
475488
}
476489
});
477490

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
import { CancellationToken } from 'vs/base/common/cancellation';
6+
import { Codicon } from 'vs/base/common/codicons';
7+
import { matchesFuzzy } from 'vs/base/common/filters';
8+
import { DisposableStore } from 'vs/base/common/lifecycle';
9+
import { localize } from 'vs/nls';
10+
import { ICommandService } from 'vs/platform/commands/common/commands';
11+
import { FastAndSlowPicks, IPickerQuickAccessItem, PickerQuickAccessProvider, Picks } from 'vs/platform/quickinput/browser/pickerQuickAccess';
12+
import { IQuickPickSeparator } from 'vs/platform/quickinput/common/quickInput';
13+
import { IViewsService } from 'vs/workbench/common/views';
14+
import { DEBUG_CONSOLE_QUICK_ACCESS_PREFIX, SELECT_AND_START_ID } from 'vs/workbench/contrib/debug/browser/debugCommands';
15+
import { getStateLabel, IDebugService, IDebugSession, REPL_VIEW_ID } from 'vs/workbench/contrib/debug/common/debug';
16+
17+
export class DebugConsoleQuickAccess extends PickerQuickAccessProvider<IPickerQuickAccessItem> {
18+
19+
constructor(
20+
@IDebugService private readonly _debugService: IDebugService,
21+
@IViewsService private readonly _viewsService: IViewsService,
22+
@ICommandService private readonly _commandService: ICommandService,
23+
) {
24+
super(DEBUG_CONSOLE_QUICK_ACCESS_PREFIX, { canAcceptInBackground: true });
25+
}
26+
27+
protected _getPicks(filter: string, disposables: DisposableStore, token: CancellationToken): Picks<IPickerQuickAccessItem> | Promise<Picks<IPickerQuickAccessItem>> | FastAndSlowPicks<IPickerQuickAccessItem> | null {
28+
const debugConsolePicks: Array<IPickerQuickAccessItem | IQuickPickSeparator> = [];
29+
30+
this._debugService.getModel().getSessions(true).filter(s => s.hasSeparateRepl()).forEach((session, index) => {
31+
const pick = this._createPick(session, index, filter);
32+
if (pick) {
33+
debugConsolePicks.push(pick);
34+
}
35+
});
36+
37+
38+
if (debugConsolePicks.length > 0) {
39+
debugConsolePicks.push({ type: 'separator' });
40+
}
41+
42+
const createTerminalLabel = localize("workbench.action.debug.startDebug", "Start a New Debug Session");
43+
debugConsolePicks.push({
44+
label: `$(plus) ${createTerminalLabel}`,
45+
ariaLabel: createTerminalLabel,
46+
accept: () => this._commandService.executeCommand(SELECT_AND_START_ID)
47+
});
48+
return debugConsolePicks;
49+
}
50+
51+
private _createPick(session: IDebugSession, sessionIndex: number, filter: string): IPickerQuickAccessItem | undefined {
52+
const iconId = Codicon.debugConsole.id;
53+
const label = `$(${iconId}) ${session.name}`;
54+
55+
const highlights = matchesFuzzy(filter, label, true);
56+
if (highlights) {
57+
return {
58+
label,
59+
description: getStateLabel(session.state),
60+
highlights: { label: highlights },
61+
accept: (keyMod, event) => {
62+
this._debugService.focusStackFrame(undefined, undefined, session, { explicit: true });
63+
if (!this._viewsService.isViewVisible(REPL_VIEW_ID)) {
64+
this._viewsService.openView(REPL_VIEW_ID, true);
65+
}
66+
}
67+
};
68+
}
69+
return undefined;
70+
}
71+
}

src/vs/workbench/contrib/debug/browser/debugQuickAccess.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,19 @@ import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/
1212
import { ICommandService } from 'vs/platform/commands/common/commands';
1313
import { matchesFuzzy } from 'vs/base/common/filters';
1414
import { withNullAsUndefined } from 'vs/base/common/types';
15-
import { ADD_CONFIGURATION_ID } from 'vs/workbench/contrib/debug/browser/debugCommands';
15+
import { ADD_CONFIGURATION_ID, DEBUG_QUICK_ACCESS_PREFIX } from 'vs/workbench/contrib/debug/browser/debugCommands';
1616
import { debugConfigure, debugRemoveConfig } from 'vs/workbench/contrib/debug/browser/debugIcons';
1717
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
1818

1919
export class StartDebugQuickAccessProvider extends PickerQuickAccessProvider<IPickerQuickAccessItem> {
2020

21-
static PREFIX = 'debug ';
22-
2321
constructor(
2422
@IDebugService private readonly debugService: IDebugService,
2523
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService,
2624
@ICommandService private readonly commandService: ICommandService,
2725
@INotificationService private readonly notificationService: INotificationService,
2826
) {
29-
super(StartDebugQuickAccessProvider.PREFIX, {
27+
super(DEBUG_QUICK_ACCESS_PREFIX, {
3028
noResultsPick: {
3129
label: localize('noDebugResults', "No matching launch configurations")
3230
}

0 commit comments

Comments
 (0)