Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/browser/actions/developerActions.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
6
import './media/actions.css';
7
8
import { localize, localize2 } from '../../../nls.js';
9
import { IKeybindingService } from '../../../platform/keybinding/common/keybinding.js';
10
import { DomEmitter } from '../../../base/browser/event.js';
11
import { Color } from '../../../base/common/color.js';
12
import { Emitter, Event } from '../../../base/common/event.js';
13
import { IDisposable, toDisposable, dispose, DisposableStore, setDisposableTracker, DisposableTracker, DisposableInfo } from '../../../base/common/lifecycle.js';
14
import { getDomNodePagePosition, append, $, getActiveDocument, onDidRegisterWindow, getWindows } from '../../../base/browser/dom.js';
15
import { createCSSRule, createStyleSheet } from '../../../base/browser/domStylesheets.js';
16
import { IConfigurationService } from '../../../platform/configuration/common/configuration.js';
17
import { ContextKeyExpr, IContextKeyService, RawContextKey } from '../../../platform/contextkey/common/contextkey.js';
18
import { Context } from '../../../platform/contextkey/browser/contextKeyService.js';
19
import { StandardKeyboardEvent } from '../../../base/browser/keyboardEvent.js';
20
import { RunOnceScheduler } from '../../../base/common/async.js';
21
import { ILayoutService } from '../../../platform/layout/browser/layoutService.js';
22
import { Registry } from '../../../platform/registry/common/platform.js';
23
import { registerAction2, Action2, MenuRegistry } from '../../../platform/actions/common/actions.js';
24
import { IStorageService, StorageScope, StorageTarget } from '../../../platform/storage/common/storage.js';
25
import { clamp } from '../../../base/common/numbers.js';
26
import { KeyCode } from '../../../base/common/keyCodes.js';
27
import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from '../../../platform/configuration/common/configurationRegistry.js';
28
import { ILogService } from '../../../platform/log/common/log.js';
29
import { IWorkingCopyService } from '../../services/workingCopy/common/workingCopyService.js';
30
import { ServicesAccessor } from '../../../platform/instantiation/common/instantiation.js';
31
import { Categories } from '../../../platform/action/common/actionCommonCategories.js';
32
import { IWorkingCopyBackupService } from '../../services/workingCopy/common/workingCopyBackup.js';
33
import { ResolutionResult, ResultKind } from '../../../platform/keybinding/common/keybindingResolver.js';
34
import { IDialogService } from '../../../platform/dialogs/common/dialogs.js';
35
import { IOutputService } from '../../services/output/common/output.js';
36
import { windowLogId } from '../../services/log/common/logConstants.js';
37
import { ByteSize } from '../../../platform/files/common/files.js';
38
import { IQuickInputService, IQuickPickItem } from '../../../platform/quickinput/common/quickInput.js';
39
import { IUserDataProfileService } from '../../services/userDataProfile/common/userDataProfile.js';
40
import { IEditorService } from '../../services/editor/common/editorService.js';
41
import product from '../../../platform/product/common/product.js';
42
import { CommandsRegistry } from '../../../platform/commands/common/commands.js';
43
import { IEnvironmentService } from '../../../platform/environment/common/environment.js';
44
45
class InspectContextKeysAction extends Action2 {
46
47
constructor() {
48
super({
49
id: 'workbench.action.inspectContextKeys',
50
title: localize2('inspect context keys', 'Inspect Context Keys'),
51
category: Categories.Developer,
52
f1: true
53
});
54
}
55
56
run(accessor: ServicesAccessor): void {
57
const contextKeyService = accessor.get(IContextKeyService);
58
59
const disposables = new DisposableStore();
60
61
const stylesheet = createStyleSheet(undefined, undefined, disposables);
62
createCSSRule('*', 'cursor: crosshair !important;', stylesheet);
63
64
const hoverFeedback = document.createElement('div');
65
const activeDocument = getActiveDocument();
66
activeDocument.body.appendChild(hoverFeedback);
67
disposables.add(toDisposable(() => hoverFeedback.remove()));
68
69
hoverFeedback.style.position = 'absolute';
70
hoverFeedback.style.pointerEvents = 'none';
71
hoverFeedback.style.backgroundColor = 'rgba(255, 0, 0, 0.5)';
72
hoverFeedback.style.zIndex = '1000';
73
74
const onMouseMove = disposables.add(new DomEmitter(activeDocument, 'mousemove', true));
75
disposables.add(onMouseMove.event(e => {
76
const target = e.target as HTMLElement;
77
const position = getDomNodePagePosition(target);
78
79
hoverFeedback.style.top = `${position.top}px`;
80
hoverFeedback.style.left = `${position.left}px`;
81
hoverFeedback.style.width = `${position.width}px`;
82
hoverFeedback.style.height = `${position.height}px`;
83
}));
84
85
const onMouseDown = disposables.add(new DomEmitter(activeDocument, 'mousedown', true));
86
Event.once(onMouseDown.event)(e => { e.preventDefault(); e.stopPropagation(); }, null, disposables);
87
88
const onMouseUp = disposables.add(new DomEmitter(activeDocument, 'mouseup', true));
89
Event.once(onMouseUp.event)(e => {
90
e.preventDefault();
91
e.stopPropagation();
92
93
const context = contextKeyService.getContext(e.target as HTMLElement) as Context;
94
console.log(context.collectAllValues());
95
96
dispose(disposables);
97
}, null, disposables);
98
}
99
}
100
101
interface IScreencastKeyboardOptions {
102
readonly showKeys?: boolean;
103
readonly showKeybindings?: boolean;
104
readonly showCommands?: boolean;
105
readonly showCommandGroups?: boolean;
106
readonly showSingleEditorCursorMoves?: boolean;
107
}
108
109
class ToggleScreencastModeAction extends Action2 {
110
111
static disposable: IDisposable | undefined;
112
113
constructor() {
114
super({
115
id: 'workbench.action.toggleScreencastMode',
116
title: localize2('toggle screencast mode', 'Toggle Screencast Mode'),
117
category: Categories.Developer,
118
f1: true
119
});
120
}
121
122
run(accessor: ServicesAccessor): void {
123
if (ToggleScreencastModeAction.disposable) {
124
ToggleScreencastModeAction.disposable.dispose();
125
ToggleScreencastModeAction.disposable = undefined;
126
return;
127
}
128
129
const layoutService = accessor.get(ILayoutService);
130
const configurationService = accessor.get(IConfigurationService);
131
const keybindingService = accessor.get(IKeybindingService);
132
133
const disposables = new DisposableStore();
134
135
const container = layoutService.activeContainer;
136
137
const mouseMarker = append(container, $('.screencast-mouse'));
138
disposables.add(toDisposable(() => mouseMarker.remove()));
139
140
const keyboardMarker = append(container, $('.screencast-keyboard'));
141
disposables.add(toDisposable(() => keyboardMarker.remove()));
142
143
const onMouseDown = disposables.add(new Emitter<MouseEvent>());
144
const onMouseUp = disposables.add(new Emitter<MouseEvent>());
145
const onMouseMove = disposables.add(new Emitter<MouseEvent>());
146
147
function registerContainerListeners(container: HTMLElement, disposables: DisposableStore): void {
148
disposables.add(disposables.add(new DomEmitter(container, 'mousedown', true)).event(e => onMouseDown.fire(e)));
149
disposables.add(disposables.add(new DomEmitter(container, 'mouseup', true)).event(e => onMouseUp.fire(e)));
150
disposables.add(disposables.add(new DomEmitter(container, 'mousemove', true)).event(e => onMouseMove.fire(e)));
151
}
152
153
for (const { window, disposables } of getWindows()) {
154
registerContainerListeners(layoutService.getContainer(window), disposables);
155
}
156
157
disposables.add(onDidRegisterWindow(({ window, disposables }) => registerContainerListeners(layoutService.getContainer(window), disposables)));
158
159
disposables.add(layoutService.onDidChangeActiveContainer(() => {
160
layoutService.activeContainer.appendChild(mouseMarker);
161
layoutService.activeContainer.appendChild(keyboardMarker);
162
}));
163
164
const updateMouseIndicatorColor = () => {
165
mouseMarker.style.borderColor = Color.fromHex(configurationService.getValue<string>('screencastMode.mouseIndicatorColor')).toString();
166
};
167
168
let mouseIndicatorSize: number;
169
const updateMouseIndicatorSize = () => {
170
mouseIndicatorSize = clamp(configurationService.getValue<number>('screencastMode.mouseIndicatorSize') || 20, 20, 100);
171
172
mouseMarker.style.height = `${mouseIndicatorSize}px`;
173
mouseMarker.style.width = `${mouseIndicatorSize}px`;
174
};
175
176
updateMouseIndicatorColor();
177
updateMouseIndicatorSize();
178
179
disposables.add(onMouseDown.event(e => {
180
mouseMarker.style.top = `${e.clientY - mouseIndicatorSize / 2}px`;
181
mouseMarker.style.left = `${e.clientX - mouseIndicatorSize / 2}px`;
182
mouseMarker.style.display = 'block';
183
mouseMarker.style.transform = `scale(${1})`;
184
mouseMarker.style.transition = 'transform 0.1s';
185
186
const mouseMoveListener = onMouseMove.event(e => {
187
mouseMarker.style.top = `${e.clientY - mouseIndicatorSize / 2}px`;
188
mouseMarker.style.left = `${e.clientX - mouseIndicatorSize / 2}px`;
189
mouseMarker.style.transform = `scale(${.8})`;
190
});
191
192
Event.once(onMouseUp.event)(() => {
193
mouseMarker.style.display = 'none';
194
mouseMoveListener.dispose();
195
});
196
}));
197
198
const updateKeyboardFontSize = () => {
199
keyboardMarker.style.fontSize = `${clamp(configurationService.getValue<number>('screencastMode.fontSize') || 56, 20, 100)}px`;
200
};
201
202
const updateKeyboardMarker = () => {
203
keyboardMarker.style.bottom = `${clamp(configurationService.getValue<number>('screencastMode.verticalOffset') || 0, 0, 90)}%`;
204
};
205
206
let keyboardMarkerTimeout!: number;
207
const updateKeyboardMarkerTimeout = () => {
208
keyboardMarkerTimeout = clamp(configurationService.getValue<number>('screencastMode.keyboardOverlayTimeout') || 800, 500, 5000);
209
};
210
211
updateKeyboardFontSize();
212
updateKeyboardMarker();
213
updateKeyboardMarkerTimeout();
214
215
disposables.add(configurationService.onDidChangeConfiguration(e => {
216
if (e.affectsConfiguration('screencastMode.verticalOffset')) {
217
updateKeyboardMarker();
218
}
219
220
if (e.affectsConfiguration('screencastMode.fontSize')) {
221
updateKeyboardFontSize();
222
}
223
224
if (e.affectsConfiguration('screencastMode.keyboardOverlayTimeout')) {
225
updateKeyboardMarkerTimeout();
226
}
227
228
if (e.affectsConfiguration('screencastMode.mouseIndicatorColor')) {
229
updateMouseIndicatorColor();
230
}
231
232
if (e.affectsConfiguration('screencastMode.mouseIndicatorSize')) {
233
updateMouseIndicatorSize();
234
}
235
}));
236
237
const onKeyDown = disposables.add(new Emitter<KeyboardEvent>());
238
const onCompositionStart = disposables.add(new Emitter<CompositionEvent>());
239
const onCompositionUpdate = disposables.add(new Emitter<CompositionEvent>());
240
const onCompositionEnd = disposables.add(new Emitter<CompositionEvent>());
241
242
function registerWindowListeners(window: Window, disposables: DisposableStore): void {
243
disposables.add(disposables.add(new DomEmitter(window, 'keydown', true)).event(e => onKeyDown.fire(e)));
244
disposables.add(disposables.add(new DomEmitter(window, 'compositionstart', true)).event(e => onCompositionStart.fire(e)));
245
disposables.add(disposables.add(new DomEmitter(window, 'compositionupdate', true)).event(e => onCompositionUpdate.fire(e)));
246
disposables.add(disposables.add(new DomEmitter(window, 'compositionend', true)).event(e => onCompositionEnd.fire(e)));
247
}
248
249
for (const { window, disposables } of getWindows()) {
250
registerWindowListeners(window, disposables);
251
}
252
253
disposables.add(onDidRegisterWindow(({ window, disposables }) => registerWindowListeners(window, disposables)));
254
255
let length = 0;
256
let composing: Element | undefined = undefined;
257
let imeBackSpace = false;
258
259
const clearKeyboardScheduler = new RunOnceScheduler(() => {
260
keyboardMarker.textContent = '';
261
composing = undefined;
262
length = 0;
263
}, keyboardMarkerTimeout);
264
265
disposables.add(onCompositionStart.event(e => {
266
imeBackSpace = true;
267
}));
268
269
disposables.add(onCompositionUpdate.event(e => {
270
if (e.data && imeBackSpace) {
271
if (length > 20) {
272
keyboardMarker.innerText = '';
273
length = 0;
274
}
275
composing = composing ?? append(keyboardMarker, $('span.key'));
276
composing.textContent = e.data;
277
} else if (imeBackSpace) {
278
keyboardMarker.innerText = '';
279
append(keyboardMarker, $('span.key', {}, `Backspace`));
280
}
281
clearKeyboardScheduler.schedule();
282
}));
283
284
disposables.add(onCompositionEnd.event(e => {
285
composing = undefined;
286
length++;
287
}));
288
289
disposables.add(onKeyDown.event(e => {
290
if (e.key === 'Process' || /[\uac00-\ud787\u3131-\u314e\u314f-\u3163\u3041-\u3094\u30a1-\u30f4\u30fc\u3005\u3006\u3024\u4e00-\u9fa5]/u.test(e.key)) {
291
if (e.code === 'Backspace') {
292
imeBackSpace = true;
293
} else if (!e.code.includes('Key')) {
294
composing = undefined;
295
imeBackSpace = false;
296
} else {
297
imeBackSpace = true;
298
}
299
clearKeyboardScheduler.schedule();
300
return;
301
}
302
303
if (e.isComposing) {
304
return;
305
}
306
307
const options = configurationService.getValue<IScreencastKeyboardOptions>('screencastMode.keyboardOptions');
308
const event = new StandardKeyboardEvent(e);
309
const shortcut = keybindingService.softDispatch(event, event.target);
310
311
// Hide the single arrow key pressed
312
if (shortcut.kind === ResultKind.KbFound && shortcut.commandId && !(options.showSingleEditorCursorMoves ?? true) && (
313
['cursorLeft', 'cursorRight', 'cursorUp', 'cursorDown'].includes(shortcut.commandId))
314
) {
315
return;
316
}
317
318
if (
319
event.ctrlKey || event.altKey || event.metaKey || event.shiftKey
320
|| length > 20
321
|| event.keyCode === KeyCode.Backspace || event.keyCode === KeyCode.Escape
322
|| event.keyCode === KeyCode.UpArrow || event.keyCode === KeyCode.DownArrow
323
|| event.keyCode === KeyCode.LeftArrow || event.keyCode === KeyCode.RightArrow
324
) {
325
keyboardMarker.innerText = '';
326
length = 0;
327
}
328
329
const keybinding = keybindingService.resolveKeyboardEvent(event);
330
const commandDetails = (this._isKbFound(shortcut) && shortcut.commandId) ? this.getCommandDetails(shortcut.commandId) : undefined;
331
332
let commandAndGroupLabel = commandDetails?.title;
333
let keyLabel: string | undefined | null = keybinding.getLabel();
334
335
if (commandDetails) {
336
if ((options.showCommandGroups ?? false) && commandDetails.category) {
337
commandAndGroupLabel = `${commandDetails.category}: ${commandAndGroupLabel} `;
338
}
339
340
if (this._isKbFound(shortcut) && shortcut.commandId) {
341
const keybindings = keybindingService.lookupKeybindings(shortcut.commandId)
342
.filter(k => k.getLabel()?.endsWith(keyLabel ?? ''));
343
344
if (keybindings.length > 0) {
345
keyLabel = keybindings[keybindings.length - 1].getLabel();
346
}
347
}
348
}
349
350
if ((options.showCommands ?? true) && commandAndGroupLabel) {
351
append(keyboardMarker, $('span.title', {}, `${commandAndGroupLabel} `));
352
}
353
354
if ((options.showKeys ?? true) || ((options.showKeybindings ?? true) && this._isKbFound(shortcut))) {
355
// Fix label for arrow keys
356
keyLabel = keyLabel?.replace('UpArrow', '↑')
357
?.replace('DownArrow', '↓')
358
?.replace('LeftArrow', '←')
359
?.replace('RightArrow', '→');
360
361
append(keyboardMarker, $('span.key', {}, keyLabel ?? ''));
362
}
363
364
length++;
365
clearKeyboardScheduler.schedule();
366
}));
367
368
ToggleScreencastModeAction.disposable = disposables;
369
}
370
371
private _isKbFound(resolutionResult: ResolutionResult): resolutionResult is { kind: ResultKind.KbFound; commandId: string | null; commandArgs: any; isBubble: boolean } {
372
return resolutionResult.kind === ResultKind.KbFound;
373
}
374
375
private getCommandDetails(commandId: string): { title: string; category?: string } | undefined {
376
const fromMenuRegistry = MenuRegistry.getCommand(commandId);
377
378
if (fromMenuRegistry) {
379
return {
380
title: typeof fromMenuRegistry.title === 'string' ? fromMenuRegistry.title : fromMenuRegistry.title.value,
381
category: fromMenuRegistry.category ? (typeof fromMenuRegistry.category === 'string' ? fromMenuRegistry.category : fromMenuRegistry.category.value) : undefined
382
};
383
}
384
385
const fromCommandsRegistry = CommandsRegistry.getCommand(commandId);
386
387
if (fromCommandsRegistry && fromCommandsRegistry.metadata?.description) {
388
return { title: typeof fromCommandsRegistry.metadata.description === 'string' ? fromCommandsRegistry.metadata.description : fromCommandsRegistry.metadata.description.value };
389
}
390
391
return undefined;
392
}
393
}
394
395
class LogStorageAction extends Action2 {
396
397
constructor() {
398
super({
399
id: 'workbench.action.logStorage',
400
title: localize2({ key: 'logStorage', comment: ['A developer only action to log the contents of the storage for the current window.'] }, "Log Storage Database Contents"),
401
category: Categories.Developer,
402
f1: true
403
});
404
}
405
406
run(accessor: ServicesAccessor): void {
407
const storageService = accessor.get(IStorageService);
408
const dialogService = accessor.get(IDialogService);
409
410
storageService.log();
411
412
dialogService.info(localize('storageLogDialogMessage', "The storage database contents have been logged to the developer tools."), localize('storageLogDialogDetails', "Open developer tools from the menu and select the Console tab."));
413
}
414
}
415
416
class LogWorkingCopiesAction extends Action2 {
417
418
constructor() {
419
super({
420
id: 'workbench.action.logWorkingCopies',
421
title: localize2({ key: 'logWorkingCopies', comment: ['A developer only action to log the working copies that exist.'] }, "Log Working Copies"),
422
category: Categories.Developer,
423
f1: true
424
});
425
}
426
427
async run(accessor: ServicesAccessor): Promise<void> {
428
const workingCopyService = accessor.get(IWorkingCopyService);
429
const workingCopyBackupService = accessor.get(IWorkingCopyBackupService);
430
const logService = accessor.get(ILogService);
431
const outputService = accessor.get(IOutputService);
432
433
const backups = await workingCopyBackupService.getBackups();
434
435
const msg = [
436
``,
437
`[Working Copies]`,
438
...(workingCopyService.workingCopies.length > 0) ?
439
workingCopyService.workingCopies.map(workingCopy => `${workingCopy.isDirty() ? '● ' : ''}${workingCopy.resource.toString(true)} (typeId: ${workingCopy.typeId || '<no typeId>'})`) :
440
['<none>'],
441
``,
442
`[Backups]`,
443
...(backups.length > 0) ?
444
backups.map(backup => `${backup.resource.toString(true)} (typeId: ${backup.typeId || '<no typeId>'})`) :
445
['<none>'],
446
];
447
448
logService.info(msg.join('\n'));
449
450
outputService.showChannel(windowLogId, true);
451
}
452
}
453
454
class RemoveLargeStorageEntriesAction extends Action2 {
455
456
private static SIZE_THRESHOLD = 1024 * 16; // 16kb
457
458
constructor() {
459
super({
460
id: 'workbench.action.removeLargeStorageDatabaseEntries',
461
title: localize2('removeLargeStorageDatabaseEntries', 'Remove Large Storage Database Entries...'),
462
category: Categories.Developer,
463
f1: true
464
});
465
}
466
467
async run(accessor: ServicesAccessor): Promise<void> {
468
const storageService = accessor.get(IStorageService);
469
const quickInputService = accessor.get(IQuickInputService);
470
const userDataProfileService = accessor.get(IUserDataProfileService);
471
const dialogService = accessor.get(IDialogService);
472
const environmentService = accessor.get(IEnvironmentService);
473
474
interface IStorageItem extends IQuickPickItem {
475
readonly key: string;
476
readonly scope: StorageScope;
477
readonly target: StorageTarget;
478
readonly size: number;
479
}
480
481
const items: IStorageItem[] = [];
482
483
for (const scope of [StorageScope.APPLICATION, StorageScope.PROFILE, StorageScope.WORKSPACE]) {
484
if (scope === StorageScope.PROFILE && userDataProfileService.currentProfile.isDefault) {
485
continue; // avoid duplicates
486
}
487
488
for (const target of [StorageTarget.MACHINE, StorageTarget.USER]) {
489
for (const key of storageService.keys(scope, target)) {
490
const value = storageService.get(key, scope);
491
if (value && (!environmentService.isBuilt /* show all keys in dev */ || value.length > RemoveLargeStorageEntriesAction.SIZE_THRESHOLD)) {
492
items.push({
493
key,
494
scope,
495
target,
496
size: value.length,
497
label: key,
498
description: ByteSize.formatSize(value.length),
499
detail: localize('largeStorageItemDetail', "Scope: {0}, Target: {1}", scope === StorageScope.APPLICATION ? localize('global', "Global") : scope === StorageScope.PROFILE ? localize('profile', "Profile") : localize('workspace', "Workspace"), target === StorageTarget.MACHINE ? localize('machine', "Machine") : localize('user', "User")),
500
});
501
}
502
}
503
}
504
}
505
506
items.sort((itemA, itemB) => itemB.size - itemA.size);
507
508
const selectedItems = await new Promise<readonly IStorageItem[]>(resolve => {
509
const disposables = new DisposableStore();
510
511
const picker = disposables.add(quickInputService.createQuickPick<IStorageItem>());
512
picker.items = items;
513
picker.canSelectMany = true;
514
picker.ok = false;
515
picker.customButton = true;
516
picker.hideCheckAll = true;
517
picker.customLabel = localize('removeLargeStorageEntriesPickerButton', "Remove");
518
picker.placeholder = localize('removeLargeStorageEntriesPickerPlaceholder', "Select large entries to remove from storage");
519
520
if (items.length === 0) {
521
picker.description = localize('removeLargeStorageEntriesPickerDescriptionNoEntries', "There are no large storage entries to remove.");
522
}
523
524
picker.show();
525
526
disposables.add(picker.onDidCustom(() => {
527
resolve(picker.selectedItems);
528
picker.hide();
529
}));
530
531
disposables.add(picker.onDidHide(() => disposables.dispose()));
532
});
533
534
if (selectedItems.length === 0) {
535
return;
536
}
537
538
const { confirmed } = await dialogService.confirm({
539
type: 'warning',
540
message: localize('removeLargeStorageEntriesConfirmRemove', "Do you want to remove the selected storage entries from the database?"),
541
detail: localize('removeLargeStorageEntriesConfirmRemoveDetail', "{0}\n\nThis action is irreversible and may result in data loss!", selectedItems.map(item => item.label).join('\n')),
542
primaryButton: localize({ key: 'removeLargeStorageEntriesButtonLabel', comment: ['&& denotes a mnemonic'] }, "&&Remove")
543
});
544
545
if (!confirmed) {
546
return;
547
}
548
549
const scopesToOptimize = new Set<StorageScope>();
550
for (const item of selectedItems) {
551
storageService.remove(item.key, item.scope);
552
scopesToOptimize.add(item.scope);
553
}
554
555
for (const scope of scopesToOptimize) {
556
await storageService.optimize(scope);
557
}
558
}
559
}
560
561
let tracker: DisposableTracker | undefined = undefined;
562
let trackedDisposables = new Set<IDisposable>();
563
564
const DisposablesSnapshotStateContext = new RawContextKey<'started' | 'pending' | 'stopped'>('dirtyWorkingCopies', 'stopped');
565
566
class StartTrackDisposables extends Action2 {
567
568
constructor() {
569
super({
570
id: 'workbench.action.startTrackDisposables',
571
title: localize2('startTrackDisposables', 'Start Tracking Disposables'),
572
category: Categories.Developer,
573
f1: true,
574
precondition: ContextKeyExpr.and(DisposablesSnapshotStateContext.isEqualTo('pending').negate(), DisposablesSnapshotStateContext.isEqualTo('started').negate())
575
});
576
}
577
578
run(accessor: ServicesAccessor): void {
579
const disposablesSnapshotStateContext = DisposablesSnapshotStateContext.bindTo(accessor.get(IContextKeyService));
580
disposablesSnapshotStateContext.set('started');
581
582
trackedDisposables.clear();
583
584
tracker = new DisposableTracker();
585
setDisposableTracker(tracker);
586
}
587
}
588
589
class SnapshotTrackedDisposables extends Action2 {
590
591
constructor() {
592
super({
593
id: 'workbench.action.snapshotTrackedDisposables',
594
title: localize2('snapshotTrackedDisposables', 'Snapshot Tracked Disposables'),
595
category: Categories.Developer,
596
f1: true,
597
precondition: DisposablesSnapshotStateContext.isEqualTo('started')
598
});
599
}
600
601
run(accessor: ServicesAccessor): void {
602
const disposablesSnapshotStateContext = DisposablesSnapshotStateContext.bindTo(accessor.get(IContextKeyService));
603
disposablesSnapshotStateContext.set('pending');
604
605
trackedDisposables = new Set(tracker?.computeLeakingDisposables(1000)?.leaks.map(disposable => disposable.value));
606
}
607
}
608
609
class StopTrackDisposables extends Action2 {
610
611
constructor() {
612
super({
613
id: 'workbench.action.stopTrackDisposables',
614
title: localize2('stopTrackDisposables', 'Stop Tracking Disposables'),
615
category: Categories.Developer,
616
f1: true,
617
precondition: DisposablesSnapshotStateContext.isEqualTo('pending')
618
});
619
}
620
621
run(accessor: ServicesAccessor): void {
622
const editorService = accessor.get(IEditorService);
623
624
const disposablesSnapshotStateContext = DisposablesSnapshotStateContext.bindTo(accessor.get(IContextKeyService));
625
disposablesSnapshotStateContext.set('stopped');
626
627
if (tracker) {
628
const disposableLeaks = new Set<DisposableInfo>();
629
630
for (const disposable of new Set(tracker.computeLeakingDisposables(1000)?.leaks) ?? []) {
631
if (trackedDisposables.has(disposable.value)) {
632
disposableLeaks.add(disposable);
633
}
634
}
635
636
const leaks = tracker.computeLeakingDisposables(1000, Array.from(disposableLeaks));
637
if (leaks) {
638
editorService.openEditor({ resource: undefined, contents: leaks.details });
639
}
640
}
641
642
setDisposableTracker(null);
643
tracker = undefined;
644
trackedDisposables.clear();
645
}
646
}
647
648
// --- Actions Registration
649
registerAction2(InspectContextKeysAction);
650
registerAction2(ToggleScreencastModeAction);
651
registerAction2(LogStorageAction);
652
registerAction2(LogWorkingCopiesAction);
653
registerAction2(RemoveLargeStorageEntriesAction);
654
if (!product.commit) {
655
registerAction2(StartTrackDisposables);
656
registerAction2(SnapshotTrackedDisposables);
657
registerAction2(StopTrackDisposables);
658
}
659
660
// --- Configuration
661
662
// Screen Cast Mode
663
const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);
664
configurationRegistry.registerConfiguration({
665
id: 'screencastMode',
666
order: 9,
667
title: localize('screencastModeConfigurationTitle', "Screencast Mode"),
668
type: 'object',
669
properties: {
670
'screencastMode.verticalOffset': {
671
type: 'number',
672
default: 20,
673
minimum: 0,
674
maximum: 90,
675
description: localize('screencastMode.location.verticalPosition', "Controls the vertical offset of the screencast mode overlay from the bottom as a percentage of the workbench height.")
676
},
677
'screencastMode.fontSize': {
678
type: 'number',
679
default: 56,
680
minimum: 20,
681
maximum: 100,
682
description: localize('screencastMode.fontSize', "Controls the font size (in pixels) of the screencast mode keyboard.")
683
},
684
'screencastMode.keyboardOptions': {
685
type: 'object',
686
description: localize('screencastMode.keyboardOptions.description', "Options for customizing the keyboard overlay in screencast mode."),
687
properties: {
688
'showKeys': {
689
type: 'boolean',
690
default: true,
691
description: localize('screencastMode.keyboardOptions.showKeys', "Show raw keys.")
692
},
693
'showKeybindings': {
694
type: 'boolean',
695
default: true,
696
description: localize('screencastMode.keyboardOptions.showKeybindings', "Show keyboard shortcuts.")
697
},
698
'showCommands': {
699
type: 'boolean',
700
default: true,
701
description: localize('screencastMode.keyboardOptions.showCommands', "Show command names.")
702
},
703
'showCommandGroups': {
704
type: 'boolean',
705
default: false,
706
description: localize('screencastMode.keyboardOptions.showCommandGroups', "Show command group names, when commands are also shown.")
707
},
708
'showSingleEditorCursorMoves': {
709
type: 'boolean',
710
default: true,
711
description: localize('screencastMode.keyboardOptions.showSingleEditorCursorMoves', "Show single editor cursor move commands.")
712
}
713
},
714
default: {
715
'showKeys': true,
716
'showKeybindings': true,
717
'showCommands': true,
718
'showCommandGroups': false,
719
'showSingleEditorCursorMoves': true
720
},
721
additionalProperties: false
722
},
723
'screencastMode.keyboardOverlayTimeout': {
724
type: 'number',
725
default: 800,
726
minimum: 500,
727
maximum: 5000,
728
description: localize('screencastMode.keyboardOverlayTimeout', "Controls how long (in milliseconds) the keyboard overlay is shown in screencast mode.")
729
},
730
'screencastMode.mouseIndicatorColor': {
731
type: 'string',
732
format: 'color-hex',
733
default: '#FF0000',
734
description: localize('screencastMode.mouseIndicatorColor', "Controls the color in hex (#RGB, #RGBA, #RRGGBB or #RRGGBBAA) of the mouse indicator in screencast mode.")
735
},
736
'screencastMode.mouseIndicatorSize': {
737
type: 'number',
738
default: 20,
739
minimum: 20,
740
maximum: 100,
741
description: localize('screencastMode.mouseIndicatorSize', "Controls the size (in pixels) of the mouse indicator in screencast mode.")
742
},
743
}
744
});
745
746