diff --git a/src/commands.ts b/src/commands.ts new file mode 100644 index 0000000..537df19 --- /dev/null +++ b/src/commands.ts @@ -0,0 +1,79 @@ +import * as vscode from 'vscode'; + +/** + * @type {Object} Command // Command to register with the VS Code Extension API + * @prop {string} command // Name of the command; e.g., 'mind-reader.selectTheme' + * @prop {callback} callback // Callback to register when `command` is invoked + */ +type Command = { + name: string, + callback: () => void +}; + +// The list of commands to register in the extension +const commands: Command[] = [ + { + name: 'mind-reader.selectTheme', + + // callbacks can be inlined... + callback: () => vscode.commands.executeCommand('workbench.action.selectTheme'), + }, + + { + name: 'mind-reader.increaseFontScale', + callback: increaseFontScale, // ...or factored out into separate functions below + }, + + { + name: 'mind-reader.decreaseFontScale', + callback: decreaseFontScale, + }, + + { + name: 'mind-reader.resetFontScale', + callback: resetFontScale, + }, + + { + name: 'mind-reader.increaseEditorScale', + callback: increaseEditorScale, + }, + + { + name: 'mind-reader.decreaseEditorScale', + callback: decreaseEditorScale, + }, + + { + name: 'mind-reader.resetEditorScale', + callback: resetEditorScale, + }, +]; + +// COMMAND CALLBACK IMPLEMENTATIONS + +function increaseFontScale(): void { + vscode.commands.executeCommand('editor.action.fontZoomIn'); +} + +function decreaseFontScale(): void { + vscode.commands.executeCommand('editor.action.fontZoomOut'); +} + +function resetFontScale(): void { + vscode.commands.executeCommand('editor.action.fontZoomReset'); +} + +function increaseEditorScale(): void { + vscode.commands.executeCommand('workbench.action.zoomIn'); +} + +function decreaseEditorScale(): void { + vscode.commands.executeCommand('workbench.action.zoomOut'); +} + +function resetEditorScale(): void { + vscode.commands.executeCommand('workbench.action.zoomReset'); +} + +export default commands; diff --git a/src/extension.ts b/src/extension.ts index 4f3b129..5767437 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,5 +1,7 @@ import * as vscode from 'vscode'; + import * as pl from './pylex'; +import commands from './commands'; let parser: pl.Parser = new pl.Parser(); @@ -9,54 +11,14 @@ export function activate(context: vscode.ExtensionContext) { parser.parse('Beep Boop'); - // Increase Font Scale - context.subscriptions.push( - vscode.commands.registerCommand('mind-reader.increaseFontScale', () => { - vscode.commands.executeCommand('editor.action.fontZoomIn'); - }) - ); - - // Decrease Font Scale - context.subscriptions.push( - vscode.commands.registerCommand('mind-reader.decreaseFontScale', () => { - vscode.commands.executeCommand('editor.action.fontZoomOut'); - }) - ); - - // Reset Font Scale - context.subscriptions.push( - vscode.commands.registerCommand('mind-reader.resetFontScale', () => { - vscode.commands.executeCommand('editor.action.fontZoomReset'); - }) - ); - - // Increase Editor Scale - context.subscriptions.push( - vscode.commands.registerCommand('mind-reader.increaseEditorScale', () => { - vscode.commands.executeCommand('workbench.action.zoomIn'); - }) - ); - - // Decrease Editor Scale - context.subscriptions.push( - vscode.commands.registerCommand('mind-reader.decreaseEditorScale', () => { - vscode.commands.executeCommand('workbench.action.zoomOut'); - }) - ); - - // Reset Editor Scale - context.subscriptions.push( - vscode.commands.registerCommand('mind-reader.resetEditorScale', () => { - vscode.commands.executeCommand('workbench.action.zoomReset'); - }) - ); - - // Select Theme - context.subscriptions.push( - vscode.commands.registerCommand('mind-reader.selectTheme', () => { - vscode.commands.executeCommand('workbench.action.selectTheme'); - }) - ); + // Register Commands + commands.forEach(command => { + let disposable = vscode.commands.registerCommand( + command.name, + command.callback + ); + context.subscriptions.push(disposable); + }); } export function deactivate() {}