Skip to content

Commit

Permalink
Add quick access for debug consoles
Browse files Browse the repository at this point in the history
Fixes #151771
  • Loading branch information
andreamah committed Jun 17, 2022
1 parent 13e1d73 commit db13283
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/vs/workbench/contrib/debug/browser/debug.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from 'vs/workbench/contrib/debug/common/debug';
import { DebugToolBar } from 'vs/workbench/contrib/debug/browser/debugToolBar';
import { DebugService } from 'vs/workbench/contrib/debug/browser/debugService';
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';
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 } from 'vs/workbench/contrib/debug/browser/debugCommands';
import { StatusBarColorProvider } from 'vs/workbench/contrib/debug/browser/statusbarColorProvider';
import { IViewsRegistry, Extensions as ViewExtensions, IViewContainersRegistry, ViewContainerLocation, ViewContainer } from 'vs/workbench/common/views';
import { isMacintosh, isWeb } from 'vs/base/common/platform';
Expand Down Expand Up @@ -57,6 +57,7 @@ import { DisassemblyViewInput } from 'vs/workbench/contrib/debug/common/disassem
import { DebugLifecycle } from 'vs/workbench/contrib/debug/common/debugLifecycle';
import { Icon } from 'vs/platform/action/common/action';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { DebugConsoleQuickAccess } from 'vs/workbench/contrib/debug/browser/debugConsoleQuickAccess';

const debugCategory = nls.localize('debugCategory', "Debug");
registerColors();
Expand All @@ -83,6 +84,15 @@ Registry.as<IQuickAccessRegistry>(QuickAccessExtensions.Quickaccess).registerQui
helpEntries: [{ description: nls.localize('startDebuggingHelp', "Start Debugging"), commandId: SELECT_AND_START_ID }]
});

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


registerEditorContribution('editor.contrib.callStack', CallStackEditorContribution);
registerEditorContribution(BREAKPOINT_EDITOR_CONTRIBUTION_ID, BreakpointEditorContribution);
Expand Down
13 changes: 12 additions & 1 deletion src/vs/workbench/contrib/debug/browser/debugCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import { deepClone } from 'vs/base/common/objects';
import { isWeb, isWindows } from 'vs/base/common/platform';
import { saveAllBeforeDebugStart } from 'vs/workbench/contrib/debug/common/debugUtils';
import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/browser/panecomposite';
import { DebugConsoleQuickAccess } from 'vs/workbench/contrib/debug/browser/debugConsoleQuickAccess';
import { StartDebugQuickAccessProvider } from 'vs/workbench/contrib/debug/browser/debugQuickAccess';

export const ADD_CONFIGURATION_ID = 'debug.addConfiguration';
export const TOGGLE_INLINE_BREAKPOINT_ID = 'editor.debug.action.toggleInlineBreakpoint';
Expand All @@ -52,6 +54,7 @@ export const FOCUS_REPL_ID = 'workbench.debug.action.focusRepl';
export const JUMP_TO_CURSOR_ID = 'debug.jumpToCursor';
export const FOCUS_SESSION_ID = 'workbench.action.debug.focusProcess';
export const SELECT_AND_START_ID = 'workbench.action.debug.selectandstart';
export const SELECT_DEBUG_CONSOLE_ID = 'workbench.action.debug.selectDebugConsole';
export const DEBUG_CONFIGURE_COMMAND_ID = 'workbench.action.debug.configure';
export const DEBUG_START_COMMAND_ID = 'workbench.action.debug.start';
export const DEBUG_RUN_COMMAND_ID = 'workbench.action.debug.run';
Expand Down Expand Up @@ -471,7 +474,15 @@ CommandsRegistry.registerCommand({
id: SELECT_AND_START_ID,
handler: async (accessor: ServicesAccessor) => {
const quickInputService = accessor.get(IQuickInputService);
quickInputService.quickAccess.show('debug ');
quickInputService.quickAccess.show(StartDebugQuickAccessProvider.PREFIX);
}
});

CommandsRegistry.registerCommand({
id: SELECT_DEBUG_CONSOLE_ID,
handler: async (accessor: ServicesAccessor) => {
const quickInputService = accessor.get(IQuickInputService);
quickInputService.quickAccess.show(DebugConsoleQuickAccess.PREFIX);
}
});

Expand Down
72 changes: 72 additions & 0 deletions src/vs/workbench/contrib/debug/browser/debugConsoleQuickAccess.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { CancellationToken } from 'vs/base/common/cancellation';
import { Codicon } from 'vs/base/common/codicons';
import { matchesFuzzy } from 'vs/base/common/filters';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { localize } from 'vs/nls';
import { FastAndSlowPicks, IPickerQuickAccessItem, PickerQuickAccessProvider, Picks } from 'vs/platform/quickinput/browser/pickerQuickAccess';
import { IQuickInputService, IQuickPickSeparator } from 'vs/platform/quickinput/common/quickInput';
import { IViewsService } from 'vs/workbench/common/views';
import { StartDebugQuickAccessProvider } from 'vs/workbench/contrib/debug/browser/debugQuickAccess';
import { getStateLabel, IDebugService, IDebugSession, REPL_VIEW_ID } from 'vs/workbench/contrib/debug/common/debug';

export class DebugConsoleQuickAccess extends PickerQuickAccessProvider<IPickerQuickAccessItem> {
protected _getPicks(filter: string, disposables: DisposableStore, token: CancellationToken): Picks<IPickerQuickAccessItem> | Promise<Picks<IPickerQuickAccessItem>> | FastAndSlowPicks<IPickerQuickAccessItem> | null {
const debugConsolePicks: Array<IPickerQuickAccessItem | IQuickPickSeparator> = [];

this._debugService.getModel().getSessions(true).filter(s => s.hasSeparateRepl()).forEach((session, index) => {
const pick = this._createPick(session, index, filter);
if (pick) {
debugConsolePicks.push(pick);
}
});


if (debugConsolePicks.length > 0) {
debugConsolePicks.push({ type: 'separator' });
}

const createTerminalLabel = localize("workbench.action.debug.startDebug", "Start a New Debug Session");
debugConsolePicks.push({
label: `$(plus) ${createTerminalLabel}`,
ariaLabel: createTerminalLabel,
accept: () =>
this._quickInputService.quickAccess.show(StartDebugQuickAccessProvider.PREFIX)
});
return debugConsolePicks;
}

static PREFIX = 'debugcons ';

constructor(
@IDebugService private readonly _debugService: IDebugService,
@IViewsService private readonly _viewsService: IViewsService,
@IQuickInputService private readonly _quickInputService: IQuickInputService
) {
super(DebugConsoleQuickAccess.PREFIX, { canAcceptInBackground: true });
}

private _createPick(session: IDebugSession, sessionIndex: number, filter: string): IPickerQuickAccessItem | undefined {
const iconId = Codicon.debug.id;
const label = `$(${iconId}) ${sessionIndex + 1}: ${session.name}`;

const highlights = matchesFuzzy(filter, label, true);
if (highlights) {
return {
label,
description: getStateLabel(session.state),
highlights: { label: highlights },
accept: (keyMod, event) => {
this._debugService.focusStackFrame(undefined, undefined, session, { explicit: true });
if (!this._viewsService.isViewVisible(REPL_VIEW_ID)) {
this._viewsService.openView(REPL_VIEW_ID, true);
}
}
};
}
return undefined;
}
}

0 comments on commit db13283

Please sign in to comment.