1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IQuickPickSeparator } from 'vs/platform/quickinput/common/quickInput';
import { PickerQuickAccessProvider, IPickerQuickAccessItem, TriggerAction } from 'vs/platform/quickinput/browser/pickerQuickAccess';
import { localize } from 'vs/nls';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IDebugService } from 'vs/workbench/contrib/debug/common/debug';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { matchesFuzzy } from 'vs/base/common/filters';
import { withNullAsUndefined } from 'vs/base/common/types';
import { ADD_CONFIGURATION_ID, DEBUG_QUICK_ACCESS_PREFIX } from 'vs/workbench/contrib/debug/browser/debugCommands';
import { debugConfigure, debugRemoveConfig } from 'vs/workbench/contrib/debug/browser/debugIcons';
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
export class StartDebugQuickAccessProvider extends PickerQuickAccessProvider<IPickerQuickAccessItem> {
constructor(
@IDebugService private readonly debugService: IDebugService,
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService,
@ICommandService private readonly commandService: ICommandService,
@INotificationService private readonly notificationService: INotificationService,
) {
super(DEBUG_QUICK_ACCESS_PREFIX, {
noResultsPick: {
label: localize('noDebugResults', "No matching launch configurations")
}
});
}
protected async _getPicks(filter: string): Promise<(IQuickPickSeparator | IPickerQuickAccessItem)[]> {
const picks: Array<IPickerQuickAccessItem | IQuickPickSeparator> = [];
if (!this.debugService.getAdapterManager().hasEnabledDebuggers()) {
return [];
}
picks.push({ type: 'separator', label: 'launch.json' });
const configManager = this.debugService.getConfigurationManager();
// Entries: configs
let lastGroup: string | undefined;
for (const config of configManager.getAllConfigurations()) {
const highlights = matchesFuzzy(filter, config.name, true);
if (highlights) {
// Separator
if (lastGroup !== config.presentation?.group) {
picks.push({ type: 'separator' });
lastGroup = config.presentation?.group;
}
// Launch entry
picks.push({
label: config.name,
description: this.contextService.getWorkbenchState() === WorkbenchState.WORKSPACE ? config.launch.name : '',
highlights: { label: highlights },
buttons: [{
iconClass: ThemeIcon.asClassName(debugConfigure),
tooltip: localize('customizeLaunchConfig', "Configure Launch Configuration")
}],
trigger: () => {
config.launch.openConfigFile(false);
return TriggerAction.CLOSE_PICKER;
},
accept: async () => {
await configManager.selectConfiguration(config.launch, config.name);
try {
await this.debugService.startDebugging(config.launch, undefined, { startedByUser: true });
} catch (error) {
this.notificationService.error(error);
}
}
});
}
}
// Entries detected configurations
const dynamicProviders = await configManager.getDynamicProviders();
if (dynamicProviders.length > 0) {
picks.push({
type: 'separator', label: localize({
key: 'contributed',
comment: ['contributed is lower case because it looks better like that in UI. Nothing preceeds it. It is a name of the grouping of debug configurations.']
}, "contributed")
});
}
configManager.getRecentDynamicConfigurations().forEach(({ name, type }) => {
const highlights = matchesFuzzy(filter, name, true);
if (highlights) {
picks.push({
label: name,
highlights: { label: highlights },
buttons: [{
iconClass: ThemeIcon.asClassName(debugRemoveConfig),
tooltip: localize('removeLaunchConfig', "Remove Launch Configuration")
}],
trigger: () => {
configManager.removeRecentDynamicConfigurations(name, type);
return TriggerAction.CLOSE_PICKER;
},
accept: async () => {
await configManager.selectConfiguration(undefined, name, undefined, { type });
try {
const { launch, getConfig } = configManager.selectedConfiguration;
const config = await getConfig();
await this.debugService.startDebugging(launch, config, { startedByUser: true });
} catch (error) {
this.notificationService.error(error);
}
}
});
}
});
dynamicProviders.forEach(provider => {
picks.push({
label: `$(folder) ${provider.label}...`,
ariaLabel: localize({ key: 'providerAriaLabel', comment: ['Placeholder stands for the provider label. For example "NodeJS".'] }, "{0} contributed configurations", provider.label),
accept: async () => {
const pick = await provider.pick();
if (pick) {
// Use the type of the provider, not of the config since config sometimes have subtypes (for example "node-terminal")
await configManager.selectConfiguration(pick.launch, pick.config.name, pick.config, { type: provider.type });
this.debugService.startDebugging(pick.launch, pick.config, { startedByUser: true });
}
}
});
});
// Entries: launches
const visibleLaunches = configManager.getLaunches().filter(launch => !launch.hidden);
// Separator
if (visibleLaunches.length > 0) {
picks.push({ type: 'separator', label: localize('configure', "configure") });
}
for (const launch of visibleLaunches) {
const label = this.contextService.getWorkbenchState() === WorkbenchState.WORKSPACE ?
localize("addConfigTo", "Add Config ({0})...", launch.name) :
localize('addConfiguration', "Add Configuration...");
// Add Config entry
picks.push({
label,
description: this.contextService.getWorkbenchState() === WorkbenchState.WORKSPACE ? launch.name : '',
highlights: { label: withNullAsUndefined(matchesFuzzy(filter, label, true)) },
accept: () => this.commandService.executeCommand(ADD_CONFIGURATION_ID, launch.uri.toString())
});
}
return picks;
}
}
|