Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/services/keybinding/browser/unboundCommands.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 { CommandsRegistry, ICommandMetadata } from '../../../../platform/commands/common/commands.js';
7
import { isNonEmptyArray } from '../../../../base/common/arrays.js';
8
import { EditorExtensionsRegistry } from '../../../../editor/browser/editorExtensions.js';
9
import { MenuRegistry, MenuId, isIMenuItem } from '../../../../platform/actions/common/actions.js';
10
11
export function getAllUnboundCommands(boundCommands: Map<string, boolean>): string[] {
12
const unboundCommands: string[] = [];
13
const seenMap: Map<string, boolean> = new Map<string, boolean>();
14
const addCommand = (id: string, includeCommandWithArgs: boolean) => {
15
if (seenMap.has(id)) {
16
return;
17
}
18
seenMap.set(id, true);
19
if (id[0] === '_' || id.indexOf('vscode.') === 0) { // private command
20
return;
21
}
22
if (boundCommands.get(id) === true) {
23
return;
24
}
25
if (!includeCommandWithArgs) {
26
const command = CommandsRegistry.getCommand(id);
27
if (command && typeof command.metadata === 'object'
28
&& isNonEmptyArray((<ICommandMetadata>command.metadata).args)) { // command with args
29
return;
30
}
31
}
32
unboundCommands.push(id);
33
};
34
35
// Add all commands from Command Palette
36
for (const menuItem of MenuRegistry.getMenuItems(MenuId.CommandPalette)) {
37
if (isIMenuItem(menuItem)) {
38
addCommand(menuItem.command.id, true);
39
}
40
}
41
42
// Add all editor actions
43
for (const editorAction of EditorExtensionsRegistry.getEditorActions()) {
44
addCommand(editorAction.id, true);
45
}
46
47
for (const id of CommandsRegistry.getCommands().keys()) {
48
addCommand(id, false);
49
}
50
51
return unboundCommands;
52
}
53
54