Path: blob/main/src/vs/workbench/services/keybinding/browser/unboundCommands.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { CommandsRegistry, ICommandMetadata } from '../../../../platform/commands/common/commands.js';6import { isNonEmptyArray } from '../../../../base/common/arrays.js';7import { EditorExtensionsRegistry } from '../../../../editor/browser/editorExtensions.js';8import { MenuRegistry, MenuId, isIMenuItem } from '../../../../platform/actions/common/actions.js';910export function getAllUnboundCommands(boundCommands: Map<string, boolean>): string[] {11const unboundCommands: string[] = [];12const seenMap: Map<string, boolean> = new Map<string, boolean>();13const addCommand = (id: string, includeCommandWithArgs: boolean) => {14if (seenMap.has(id)) {15return;16}17seenMap.set(id, true);18if (id[0] === '_' || id.indexOf('vscode.') === 0) { // private command19return;20}21if (boundCommands.get(id) === true) {22return;23}24if (!includeCommandWithArgs) {25const command = CommandsRegistry.getCommand(id);26if (command && typeof command.metadata === 'object'27&& isNonEmptyArray((<ICommandMetadata>command.metadata).args)) { // command with args28return;29}30}31unboundCommands.push(id);32};3334// Add all commands from Command Palette35for (const menuItem of MenuRegistry.getMenuItems(MenuId.CommandPalette)) {36if (isIMenuItem(menuItem)) {37addCommand(menuItem.command.id, true);38}39}4041// Add all editor actions42for (const editorAction of EditorExtensionsRegistry.getEditorActions()) {43addCommand(editorAction.id, true);44}4546for (const id of CommandsRegistry.getCommands().keys()) {47addCommand(id, false);48}4950return unboundCommands;51}525354