From 489463d7d3d246a81bb73680956afa15fa6f47ca Mon Sep 17 00:00:00 2001 From: tshino Date: Thu, 2 Dec 2021 22:54:02 +0900 Subject: [PATCH] Add warning for unknown command in config #11 --- generator/gen_keymap_wrapper.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/generator/gen_keymap_wrapper.js b/generator/gen_keymap_wrapper.js index 1f929ad7..52c9973a 100644 --- a/generator/gen_keymap_wrapper.js +++ b/generator/gen_keymap_wrapper.js @@ -41,18 +41,22 @@ function checkAwaitOptions(awaitOptions) { } } -function resolveWildcardInAwaitOptions(awaitOptions, baseKeybindings) { +function resolveWildcardInAwaitOptions(awaitOptions, commands) { const newAwaitOptions = new Map; for (const [ command, awaitOption ] of awaitOptions) { if (command.endsWith('*')) { // wildcard const prefix = command.slice(0, -1); - const matches = baseKeybindings.filter( - keybinding => keybinding.command.startsWith(prefix) - ).map(keybinding => keybinding.command); + const matches = Array.from(commands.values()).filter(c => c.startsWith(prefix)); + if (matches.length === 0) { + console.warn('Warning: No matching commands for wildcard:', command); + } for (const match of matches) { newAwaitOptions.set(match, awaitOption); } } else { + if (!commands.has(command)) { + console.warn('Warning: No matching command:', command); + } newAwaitOptions.set(command, awaitOption); } } @@ -70,9 +74,10 @@ async function makeKeymapWrapper(configPath) { const exclusion = new Set(config['exclusion'] || []); const baseKeybindings = packageJson['contributes']['keybindings']; + const commands = new Set(baseKeybindings.map(keybinding => keybinding.command)); const rawAwaitOptions = new Map(config['awaitOptions'] || []); - const awaitOptions = resolveWildcardInAwaitOptions(rawAwaitOptions, baseKeybindings); + const awaitOptions = resolveWildcardInAwaitOptions(rawAwaitOptions, commands); checkAwaitOptions(awaitOptions); const wrappers = baseKeybindings.map(