Path: blob/main/src/vs/workbench/contrib/debug/browser/debugConsoleQuickAccess.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/4import { CancellationToken } from '../../../../base/common/cancellation.js';5import { matchesFuzzy } from '../../../../base/common/filters.js';6import { DisposableStore } from '../../../../base/common/lifecycle.js';7import { localize } from '../../../../nls.js';8import { ICommandService } from '../../../../platform/commands/common/commands.js';9import { FastAndSlowPicks, IPickerQuickAccessItem, PickerQuickAccessProvider, Picks } from '../../../../platform/quickinput/browser/pickerQuickAccess.js';10import { IQuickPickSeparator } from '../../../../platform/quickinput/common/quickInput.js';11import { IViewsService } from '../../../services/views/common/viewsService.js';12import { DEBUG_CONSOLE_QUICK_ACCESS_PREFIX, SELECT_AND_START_ID } from './debugCommands.js';13import { IDebugService, IDebugSession, REPL_VIEW_ID } from '../common/debug.js';1415export class DebugConsoleQuickAccess extends PickerQuickAccessProvider<IPickerQuickAccessItem> {1617constructor(18@IDebugService private readonly _debugService: IDebugService,19@IViewsService private readonly _viewsService: IViewsService,20@ICommandService private readonly _commandService: ICommandService,21) {22super(DEBUG_CONSOLE_QUICK_ACCESS_PREFIX, { canAcceptInBackground: true });23}2425protected _getPicks(filter: string, disposables: DisposableStore, token: CancellationToken): Picks<IPickerQuickAccessItem> | Promise<Picks<IPickerQuickAccessItem>> | FastAndSlowPicks<IPickerQuickAccessItem> | null {26const debugConsolePicks: Array<IPickerQuickAccessItem | IQuickPickSeparator> = [];2728this._debugService.getModel().getSessions(true).filter(s => s.hasSeparateRepl()).forEach((session, index) => {29const pick = this._createPick(session, index, filter);30if (pick) {31debugConsolePicks.push(pick);32}33});343536if (debugConsolePicks.length > 0) {37debugConsolePicks.push({ type: 'separator' });38}3940const createTerminalLabel = localize("workbench.action.debug.startDebug", "Start a New Debug Session");41debugConsolePicks.push({42label: `$(plus) ${createTerminalLabel}`,43ariaLabel: createTerminalLabel,44accept: () => this._commandService.executeCommand(SELECT_AND_START_ID)45});46return debugConsolePicks;47}4849private _createPick(session: IDebugSession, sessionIndex: number, filter: string): IPickerQuickAccessItem | undefined {50const label = session.name;5152const highlights = matchesFuzzy(filter, label, true);53if (highlights) {54return {55label,56highlights: { label: highlights },57accept: (keyMod, event) => {58this._debugService.focusStackFrame(undefined, undefined, session, { explicit: true });59if (!this._viewsService.isViewVisible(REPL_VIEW_ID)) {60this._viewsService.openView(REPL_VIEW_ID, true);61}62}63};64}65return undefined;66}67}686970