import { commands } from 'vscode' export const executeCommandsIfExist = async (commands: string[], ...args: unknown[]): Promise> => { const promises = commands.map(command => executeCommandIfExists(command, ...args)) return Promise.all(promises) } export const executeCommandIfExists = async (command: string, ...args: unknown[]): Promise => { const commandNames = await commands.getCommands() return commandNames.includes(command) ? commands.executeCommand(command) : undefined } export const executeSubcommandIfExists = (commandPrefix: string, ...args: unknown[]) => async (subcommand: string): Promise => { return executeCommandIfExists(commandPrefix + '.' + subcommand, ...args) }