-
Notifications
You must be signed in to change notification settings - Fork 39.4k
Expand file tree
/
Copy pathgettingStarted.contribution.ts
More file actions
356 lines (324 loc) · 16.3 KB
/
gettingStarted.contribution.ts
File metadata and controls
356 lines (324 loc) · 16.3 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { localize, localize2 } from '../../../../nls.js';
import { GettingStartedInputSerializer, GettingStartedPage, inWelcomeContext } from './gettingStarted.js';
import { Registry } from '../../../../platform/registry/common/platform.js';
import { EditorExtensions, IEditorFactoryRegistry } from '../../../common/editor.js';
import { MenuId, registerAction2, Action2 } from '../../../../platform/actions/common/actions.js';
import { ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js';
import { ContextKeyExpr, IContextKeyService, RawContextKey } from '../../../../platform/contextkey/common/contextkey.js';
import { IEditorService, SIDE_GROUP } from '../../../services/editor/common/editorService.js';
import { KeybindingWeight } from '../../../../platform/keybinding/common/keybindingsRegistry.js';
import { KeyCode } from '../../../../base/common/keyCodes.js';
import { EditorPaneDescriptor, IEditorPaneRegistry } from '../../../browser/editor.js';
import { SyncDescriptor } from '../../../../platform/instantiation/common/descriptors.js';
import { IWalkthroughsService } from './gettingStartedService.js';
import { GettingStartedEditorOptions, GettingStartedInput } from './gettingStartedInput.js';
import { registerWorkbenchContribution2, WorkbenchPhase } from '../../../common/contributions.js';
import { ConfigurationScope, Extensions as ConfigurationExtensions, IConfigurationRegistry } from '../../../../platform/configuration/common/configurationRegistry.js';
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
import { workbenchConfigurationNodeBase } from '../../../common/configuration.js';
import { CommandsRegistry, ICommandService } from '../../../../platform/commands/common/commands.js';
import { IQuickInputService, IQuickPickItem } from '../../../../platform/quickinput/common/quickInput.js';
import { IRemoteAgentService } from '../../../services/remote/common/remoteAgentService.js';
import { isLinux, isMacintosh, isWindows, OperatingSystem as OS } from '../../../../base/common/platform.js';
import { IExtensionManagementServerService } from '../../../services/extensionManagement/common/extensionManagement.js';
import { IExtensionService } from '../../../services/extensions/common/extensions.js';
import { StartupPageEditorResolverContribution, StartupPageRunnerContribution } from './startupPage.js';
import { Categories } from '../../../../platform/action/common/actionCommonCategories.js';
import { DisposableStore } from '../../../../base/common/lifecycle.js';
import { AccessibleViewRegistry } from '../../../../platform/accessibility/browser/accessibleViewRegistry.js';
import { GettingStartedAccessibleView } from './gettingStartedAccessibleView.js';
import { AgentSessionsWelcomePage } from '../../welcomeAgentSessions/browser/agentSessionsWelcome.js';
import { IChatEntitlementService } from '../../../services/chat/common/chatEntitlementService.js';
export * as icons from './gettingStartedIcons.js';
registerAction2(class extends Action2 {
constructor() {
super({
id: 'workbench.action.openWalkthrough',
title: localize2('miWelcome', 'Welcome'),
category: Categories.Help,
f1: true,
menu: {
id: MenuId.MenubarHelpMenu,
group: '1_welcome',
order: 1,
},
metadata: {
description: localize2('minWelcomeDescription', 'Opens a Walkthrough to help you get started in VS Code.')
}
});
}
public run(
accessor: ServicesAccessor,
walkthroughID: string | { category: string; step: string } | undefined,
optionsOrToSide: { toSide?: boolean; inactive?: boolean } | boolean | undefined
) {
const editorService = accessor.get(IEditorService);
const commandService = accessor.get(ICommandService);
const configurationService = accessor.get(IConfigurationService);
const chatEntitlementService = accessor.get(IChatEntitlementService);
const toSide = typeof optionsOrToSide === 'object' ? optionsOrToSide.toSide : optionsOrToSide;
const inactive = typeof optionsOrToSide === 'object' ? optionsOrToSide.inactive : false;
const activeEditor = editorService.activeEditor;
// If no specific walkthrough is requested and agent sessions welcome is preferred, open that instead
if (!walkthroughID && !chatEntitlementService.sentiment.hidden && configurationService.getValue<string>('workbench.startupEditor') === 'agentSessionsWelcomePage') {
commandService.executeCommand(AgentSessionsWelcomePage.COMMAND_ID);
return;
} else {
if (walkthroughID) {
const selectedCategory = typeof walkthroughID === 'string' ? walkthroughID : walkthroughID.category;
let selectedStep: string | undefined;
if (typeof walkthroughID === 'object' && 'category' in walkthroughID && 'step' in walkthroughID) {
selectedStep = `${walkthroughID.category}#${walkthroughID.step}`;
} else {
selectedStep = undefined;
}
// If the walkthrough is already open just reveal the step
if (selectedStep && activeEditor instanceof GettingStartedInput && activeEditor.selectedCategory === selectedCategory) {
activeEditor.showWelcome = false;
commandService.executeCommand('walkthroughs.selectStep', selectedStep);
return;
}
let options: GettingStartedEditorOptions;
if (selectedCategory) {
// Otherwise open the walkthrough editor with the selected category and step
options = { selectedCategory, selectedStep, showWelcome: false, preserveFocus: toSide ?? false, inactive };
} else {
// Open Welcome page
options = { selectedCategory, selectedStep, showWelcome: true, preserveFocus: toSide ?? false, inactive };
}
editorService.openEditor({
resource: GettingStartedInput.RESOURCE,
options
}, toSide ? SIDE_GROUP : undefined);
} else {
editorService.openEditor({
resource: GettingStartedInput.RESOURCE,
options: { preserveFocus: toSide ?? false, inactive }
}, toSide ? SIDE_GROUP : undefined);
}
}
}
});
Registry.as<IEditorFactoryRegistry>(EditorExtensions.EditorFactory).registerEditorSerializer(GettingStartedInput.ID, GettingStartedInputSerializer);
Registry.as<IEditorPaneRegistry>(EditorExtensions.EditorPane).registerEditorPane(
EditorPaneDescriptor.create(
GettingStartedPage,
GettingStartedPage.ID,
localize('welcome', "Welcome")
),
[
new SyncDescriptor(GettingStartedInput)
]
);
const category = localize2('welcome', "Welcome");
registerAction2(class extends Action2 {
constructor() {
super({
id: 'welcome.goBack',
title: localize2('welcome.goBack', 'Go Back'),
category,
keybinding: {
weight: KeybindingWeight.EditorContrib,
primary: KeyCode.Escape,
when: inWelcomeContext
},
precondition: ContextKeyExpr.equals('activeEditor', 'gettingStartedPage'),
f1: true
});
}
run(accessor: ServicesAccessor) {
const editorService = accessor.get(IEditorService);
const editorPane = editorService.activeEditorPane;
if (editorPane instanceof GettingStartedPage) {
editorPane.escape();
}
}
});
CommandsRegistry.registerCommand({
id: 'walkthroughs.selectStep',
handler: (accessor, stepID: string) => {
const editorService = accessor.get(IEditorService);
const editorPane = editorService.activeEditorPane;
if (editorPane instanceof GettingStartedPage) {
editorPane.selectStepLoose(stepID);
} else {
console.error('Cannot run walkthroughs.selectStep outside of walkthrough context');
}
}
});
registerAction2(class extends Action2 {
constructor() {
super({
id: 'welcome.markStepComplete',
title: localize('welcome.markStepComplete', "Mark Step Complete"),
category,
});
}
run(accessor: ServicesAccessor, arg: string) {
if (!arg) { return; }
const gettingStartedService = accessor.get(IWalkthroughsService);
gettingStartedService.progressStep(arg);
}
});
registerAction2(class extends Action2 {
constructor() {
super({
id: 'welcome.markStepIncomplete',
title: localize('welcome.markStepInomplete', "Mark Step Incomplete"),
category,
});
}
run(accessor: ServicesAccessor, arg: string) {
if (!arg) { return; }
const gettingStartedService = accessor.get(IWalkthroughsService);
gettingStartedService.deprogressStep(arg);
}
});
registerAction2(class extends Action2 {
constructor() {
super({
id: 'welcome.showAllWalkthroughs',
title: localize2('welcome.showAllWalkthroughs', 'Open Walkthrough...'),
category,
f1: true,
menu: {
id: MenuId.MenubarHelpMenu,
group: '1_welcome',
order: 3,
},
});
}
private async getQuickPickItems(
contextService: IContextKeyService,
gettingStartedService: IWalkthroughsService
): Promise<IQuickPickItem[]> {
const categories = await gettingStartedService.getWalkthroughs();
return categories
.filter(c => contextService.contextMatchesRules(c.when))
.map(x => ({
id: x.id,
label: x.title,
detail: x.description,
description: x.source,
}));
}
async run(accessor: ServicesAccessor) {
const commandService = accessor.get(ICommandService);
const contextService = accessor.get(IContextKeyService);
const quickInputService = accessor.get(IQuickInputService);
const gettingStartedService = accessor.get(IWalkthroughsService);
const extensionService = accessor.get(IExtensionService);
const disposables = new DisposableStore();
const quickPick = disposables.add(quickInputService.createQuickPick());
quickPick.canSelectMany = false;
quickPick.matchOnDescription = true;
quickPick.matchOnDetail = true;
quickPick.placeholder = localize('pickWalkthroughs', 'Select a walkthrough to open');
quickPick.items = await this.getQuickPickItems(contextService, gettingStartedService);
quickPick.busy = true;
disposables.add(quickPick.onDidAccept(() => {
const selection = quickPick.selectedItems[0];
if (selection) {
commandService.executeCommand('workbench.action.openWalkthrough', selection.id);
}
quickPick.hide();
}));
disposables.add(quickPick.onDidHide(() => disposables.dispose()));
await extensionService.whenInstalledExtensionsRegistered();
disposables.add(gettingStartedService.onDidAddWalkthrough(async () => {
quickPick.items = await this.getQuickPickItems(contextService, gettingStartedService);
}));
quickPick.show();
quickPick.busy = false;
}
});
CommandsRegistry.registerCommand({
id: 'welcome.newWorkspaceChat',
handler: (accessor, stepID: string) => {
const commandService = accessor.get(ICommandService);
commandService.executeCommand('workbench.action.chat.open', { mode: 'agent', query: '#new ', isPartialQuery: true });
}
});
export const WorkspacePlatform = new RawContextKey<'mac' | 'linux' | 'windows' | 'webworker' | undefined>('workspacePlatform', undefined, localize('workspacePlatform', "The platform of the current workspace, which in remote or serverless contexts may be different from the platform of the UI"));
class WorkspacePlatformContribution {
static readonly ID = 'workbench.contrib.workspacePlatform';
constructor(
@IExtensionManagementServerService private readonly extensionManagementServerService: IExtensionManagementServerService,
@IRemoteAgentService private readonly remoteAgentService: IRemoteAgentService,
@IContextKeyService private readonly contextService: IContextKeyService,
) {
this.remoteAgentService.getEnvironment().then(env => {
const remoteOS = env?.os;
const remotePlatform = remoteOS === OS.Macintosh ? 'mac'
: remoteOS === OS.Windows ? 'windows'
: remoteOS === OS.Linux ? 'linux'
: undefined;
if (remotePlatform) {
WorkspacePlatform.bindTo(this.contextService).set(remotePlatform);
} else if (this.extensionManagementServerService.localExtensionManagementServer) {
if (isMacintosh) {
WorkspacePlatform.bindTo(this.contextService).set('mac');
} else if (isLinux) {
WorkspacePlatform.bindTo(this.contextService).set('linux');
} else if (isWindows) {
WorkspacePlatform.bindTo(this.contextService).set('windows');
}
} else if (this.extensionManagementServerService.webExtensionManagementServer) {
WorkspacePlatform.bindTo(this.contextService).set('webworker');
} else {
console.error('Error: Unable to detect workspace platform');
}
});
}
}
const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);
configurationRegistry.registerConfiguration({
...workbenchConfigurationNodeBase,
properties: {
'workbench.welcomePage.walkthroughs.openOnInstall': {
scope: ConfigurationScope.MACHINE,
type: 'boolean',
default: true,
description: localize('workbench.welcomePage.walkthroughs.openOnInstall', "When enabled, an extension's walkthrough will open upon install of the extension.")
},
'workbench.startupEditor': {
'scope': ConfigurationScope.RESOURCE,
'type': 'string',
'enum': ['none', 'welcomePage', 'readme', 'newUntitledFile', 'welcomePageInEmptyWorkbench', 'terminal', 'agentSessionsWelcomePage'],
'enumDescriptions': [
localize({ comment: ['This is the description for a setting. Values surrounded by single quotes are not to be translated.'], key: 'workbench.startupEditor.none' }, "Start without an editor."),
localize({ comment: ['This is the description for a setting. Values surrounded by single quotes are not to be translated.'], key: 'workbench.startupEditor.welcomePage' }, "Open the Welcome page, with content to aid in getting started with VS Code and extensions."),
localize({ comment: ['This is the description for a setting. Values surrounded by single quotes are not to be translated.'], key: 'workbench.startupEditor.readme' }, "Open the README when opening a folder that contains one, fallback to 'welcomePage' otherwise. Note: This is only observed as a global configuration, it will be ignored if set in a workspace or folder configuration."),
localize({ comment: ['This is the description for a setting. Values surrounded by single quotes are not to be translated.'], key: 'workbench.startupEditor.newUntitledFile' }, "Open a new untitled text file (only applies when opening an empty window)."),
localize({ comment: ['This is the description for a setting. Values surrounded by single quotes are not to be translated.'], key: 'workbench.startupEditor.welcomePageInEmptyWorkbench' }, "Open the Welcome page when opening an empty workbench."),
localize({ comment: ['This is the description for a setting. Values surrounded by single quotes are not to be translated.'], key: 'workbench.startupEditor.terminal' }, "Open a new terminal in the editor area."),
localize({ comment: ['This is the description for a setting. Values surrounded by single quotes are not to be translated.'], key: 'workbench.startupEditor.agentSessionsWelcomePage' }, "Open the Agent Sessions Welcome page. Will override the workbench secondary side bar visibility settings."),
],
'default': 'welcomePage',
'description': localize('workbench.startupEditor', "Controls which editor is shown at startup, if none are restored from the previous session."),
'experiment': { mode: 'auto' }
},
'workbench.welcomePage.preferReducedMotion': {
scope: ConfigurationScope.APPLICATION,
type: 'boolean',
default: false,
deprecationMessage: localize('deprecationMessage', "Deprecated, use the global `workbench.reduceMotion`."),
description: localize('workbench.welcomePage.preferReducedMotion', "When enabled, reduce motion in welcome page.")
},
'workbench.welcomePage.experimentalOnboarding': {
scope: ConfigurationScope.APPLICATION,
type: 'boolean',
default: false,
tags: ['experimental'],
description: localize('workbench.welcomePage.experimentalOnboarding', "When enabled, show the new onboarding experience instead of the classic walkthrough on first launch.")
}
}
});
registerWorkbenchContribution2(WorkspacePlatformContribution.ID, WorkspacePlatformContribution, WorkbenchPhase.AfterRestored);
registerWorkbenchContribution2(StartupPageEditorResolverContribution.ID, StartupPageEditorResolverContribution, WorkbenchPhase.BlockRestore);
registerWorkbenchContribution2(StartupPageRunnerContribution.ID, StartupPageRunnerContribution, WorkbenchPhase.AfterRestored);
AccessibleViewRegistry.register(new GettingStartedAccessibleView());