Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/debug/browser/debugSessionPicker.ts
3296 views
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 * as nls from '../../../../nls.js';
6
import { matchesFuzzy } from '../../../../base/common/filters.js';
7
import { DisposableStore } from '../../../../base/common/lifecycle.js';
8
import { IDebugService, IDebugSession, REPL_VIEW_ID } from '../common/debug.js';
9
import { IQuickInputService, IQuickPickSeparator } from '../../../../platform/quickinput/common/quickInput.js';
10
11
import { ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js';
12
import { IPickerDebugItem } from '../common/loadedScriptsPicker.js';
13
import { IViewsService } from '../../../services/views/common/viewsService.js';
14
import { ICommandService } from '../../../../platform/commands/common/commands.js';
15
16
17
export async function showDebugSessionMenu(accessor: ServicesAccessor, selectAndStartID: string) {
18
const quickInputService = accessor.get(IQuickInputService);
19
const debugService = accessor.get(IDebugService);
20
const viewsService = accessor.get(IViewsService);
21
const commandService = accessor.get(ICommandService);
22
23
const localDisposableStore = new DisposableStore();
24
const quickPick = quickInputService.createQuickPick<IPickerDebugItem>({ useSeparators: true });
25
localDisposableStore.add(quickPick);
26
quickPick.matchOnLabel = quickPick.matchOnDescription = quickPick.matchOnDetail = quickPick.sortByLabel = false;
27
quickPick.placeholder = nls.localize('moveFocusedView.selectView', 'Search debug sessions by name');
28
29
const pickItems = _getPicksAndActiveItem(quickPick.value, selectAndStartID, debugService, viewsService, commandService);
30
quickPick.items = pickItems.picks;
31
quickPick.activeItems = pickItems.activeItems;
32
33
localDisposableStore.add(quickPick.onDidChangeValue(async () => {
34
quickPick.items = _getPicksAndActiveItem(quickPick.value, selectAndStartID, debugService, viewsService, commandService).picks;
35
}));
36
localDisposableStore.add(quickPick.onDidAccept(() => {
37
const selectedItem = quickPick.selectedItems[0];
38
selectedItem.accept();
39
quickPick.hide();
40
localDisposableStore.dispose();
41
}));
42
quickPick.show();
43
}
44
45
function _getPicksAndActiveItem(filter: string, selectAndStartID: string, debugService: IDebugService, viewsService: IViewsService, commandService: ICommandService): { picks: Array<IPickerDebugItem | IQuickPickSeparator>; activeItems: Array<IPickerDebugItem> } {
46
const debugConsolePicks: Array<IPickerDebugItem | IQuickPickSeparator> = [];
47
const headerSessions: IDebugSession[] = [];
48
49
const currSession = debugService.getViewModel().focusedSession;
50
const sessions = debugService.getModel().getSessions(false);
51
const activeItems: Array<IPickerDebugItem> = [];
52
53
sessions.forEach((session) => {
54
if (session.compact && session.parentSession) {
55
headerSessions.push(session.parentSession);
56
}
57
});
58
59
sessions.forEach((session) => {
60
const isHeader = headerSessions.includes(session);
61
if (!session.parentSession) {
62
debugConsolePicks.push({ type: 'separator', label: isHeader ? session.name : undefined });
63
}
64
65
if (!isHeader) {
66
const pick = _createPick(session, filter, debugService, viewsService, commandService);
67
if (pick) {
68
debugConsolePicks.push(pick);
69
if (session.getId() === currSession?.getId()) {
70
activeItems.push(pick);
71
}
72
}
73
}
74
});
75
76
if (debugConsolePicks.length) {
77
debugConsolePicks.push({ type: 'separator' });
78
}
79
80
const createDebugSessionLabel = nls.localize('workbench.action.debug.startDebug', 'Start a New Debug Session');
81
debugConsolePicks.push({
82
label: `$(plus) ${createDebugSessionLabel}`,
83
ariaLabel: createDebugSessionLabel,
84
accept: () => commandService.executeCommand(selectAndStartID)
85
});
86
87
return { picks: debugConsolePicks, activeItems };
88
}
89
90
91
function _getSessionInfo(session: IDebugSession): { label: string; description: string; ariaLabel: string } {
92
const label = (!session.configuration.name.length) ? session.name : session.configuration.name;
93
const parentName = session.compact ? undefined : session.parentSession?.configuration.name;
94
let description = '';
95
let ariaLabel = '';
96
if (parentName) {
97
ariaLabel = nls.localize('workbench.action.debug.spawnFrom', 'Session {0} spawned from {1}', label, parentName);
98
description = parentName;
99
}
100
101
return { label, description, ariaLabel };
102
}
103
104
function _createPick(session: IDebugSession, filter: string, debugService: IDebugService, viewsService: IViewsService, commandService: ICommandService): IPickerDebugItem | undefined {
105
const pickInfo = _getSessionInfo(session);
106
const highlights = matchesFuzzy(filter, pickInfo.label, true);
107
if (highlights) {
108
return {
109
label: pickInfo.label,
110
description: pickInfo.description,
111
ariaLabel: pickInfo.ariaLabel,
112
highlights: { label: highlights },
113
accept: () => {
114
debugService.focusStackFrame(undefined, undefined, session, { explicit: true });
115
if (!viewsService.isViewVisible(REPL_VIEW_ID)) {
116
viewsService.openView(REPL_VIEW_ID, true);
117
}
118
}
119
};
120
}
121
return undefined;
122
}
123
124
125
126