From d4bd87a4adf52c8031dbf3b47c11fa5743b382aa Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Tue, 2 Feb 2021 13:41:46 -0700 Subject: [PATCH] Add runLastCommand and stub for runKeyboardShortcut --- projects/kiss-vscode/config/KissConfig.kiss | 47 +++++++++++++++------ projects/kiss-vscode/package.json | 11 +++++ projects/kiss-vscode/src/Main.hx | 6 ++- projects/kiss-vscode/src/Main.kiss | 18 ++++++++ 4 files changed, 68 insertions(+), 14 deletions(-) diff --git a/projects/kiss-vscode/config/KissConfig.kiss b/projects/kiss-vscode/config/KissConfig.kiss index 61e1a6cc..23be6906 100644 --- a/projects/kiss-vscode/config/KissConfig.kiss +++ b/projects/kiss-vscode/config/KissConfig.kiss @@ -28,25 +28,48 @@ (document.getText range)) "")) +/** + * State + */ + +(defvar :Map commands (new Map)) +(defvar &mut :String lastCommand null) + /** * Functionality */ -(defvar :Map commands (new Map)) -(defun runCommand [] - (let [commandList - (for description (commands.keys) - (object - label description - description null - detail null - picked null - alwaysShow null))] - (awaitLet [chosenCommand (quickPick commandList)] - ((dictGet commands chosenCommand.label) (selectedText))))) +(defun runCommand [&opt command] + (if command + {(set lastCommand command) ((dictGet commands command) (selectedText))} + (let [commandList + (for description (commands.keys) + (object + label description + description null + detail null + picked null + alwaysShow null))] + (awaitLet [chosenCommand (quickPick commandList)] + (set lastCommand chosenCommand.label) + ((dictGet commands chosenCommand.label) (selectedText))))) + (return)) + +(defun runLastCommand [&opt _] + (if lastCommand + (runCommand lastCommand) + (errorMessage "No Kiss command was run previously.")) + (return)) + +(defun runKeyboardShortcut [&opt _] + // TODO + (errorMessage "Keyboard shortcut commands are not yet implemented") + (return)) (defun registerCommand [description command] (dictSet commands description command)) (defun registerBuiltins [] + (registerCommand "Rerun last command" runLastCommand) + (registerCommand "Run a keyboard shortcut command" runKeyboardShortcut) (return)) diff --git a/projects/kiss-vscode/package.json b/projects/kiss-vscode/package.json index 3e2650e4..971f372f 100644 --- a/projects/kiss-vscode/package.json +++ b/projects/kiss-vscode/package.json @@ -10,7 +10,10 @@ "Programming Languages" ], "activationEvents": [ + "onStartupFinished", "onCommand:kiss.runCommand", + "onCommand:kiss.runLastCommand", + "onCommand:kiss.runKeyboardShortcut", "onCommand:kiss.reloadConfig" ], "main": "bin/extension.js", @@ -20,6 +23,14 @@ "command": "kiss.runCommand", "title": "Kiss: Run a Kiss command" }, + { + "command": "kiss.runLastCommand", + "title": "Kiss: Rerun the last command" + }, + { + "command": "kiss.runKeyboardShortcut", + "title": "Kiss: Run a Kiss keyboard shortcut command" + }, { "command": "kiss.reloadConfig", "title": "Kiss: Reload Kiss config" diff --git a/projects/kiss-vscode/src/Main.hx b/projects/kiss-vscode/src/Main.hx index 0eb0644a..0f2649aa 100644 --- a/projects/kiss-vscode/src/Main.hx +++ b/projects/kiss-vscode/src/Main.hx @@ -11,12 +11,14 @@ import uuid.Uuid; using StringTools; using uuid.Uuid; -typedef Command = (String) -> Void; +typedef Command = (?String) -> Void; typedef KissConfig = { registerBuiltins:() -> Void, registerCommand:(String, Command) -> Void, - runCommand:() -> Void, + runCommand:Command, + runLastCommand:Command, + runKeyboardShortcut:Command, init:() -> Void }; diff --git a/projects/kiss-vscode/src/Main.kiss b/projects/kiss-vscode/src/Main.kiss index 0c9830b4..2d242294 100644 --- a/projects/kiss-vscode/src/Main.kiss +++ b/projects/kiss-vscode/src/Main.kiss @@ -68,6 +68,24 @@ (Vscode.window.showErrorMessage "Can't run commands! No config is loaded.")) (return)))) + (context.subscriptions.push + (Vscode.commands.registerCommand + "kiss.runLastCommand" + (lambda [] + (if config + (.runLastCommand (the KissConfig config)) + (Vscode.window.showErrorMessage "Can't run commands! No config is loaded.")) + (return)))) + + (context.subscriptions.push + (Vscode.commands.registerCommand + "kiss.runKeyboardShortcut" + (lambda [] + (if config + (.runKeyboardShortcut (the KissConfig config)) + (Vscode.window.showErrorMessage "Can't run commands! No config is loaded.")) + (return)))) + // TODO overload Prelude.print to use showInformationMessage (set activeConfigDir (Path.join [context.extensionPath "config"]))