Add runLastCommand and stub for runKeyboardShortcut

This commit is contained in:
2021-02-02 13:41:46 -07:00
parent a0210deaf4
commit d4bd87a4ad
4 changed files with 68 additions and 14 deletions

View File

@@ -28,25 +28,48 @@
(document.getText range))
""))
/**
* State
*/
(defvar :Map<String,Command> commands (new Map))
(defvar &mut :String lastCommand null)
/**
* Functionality
*/
(defvar :Map<String,Command> 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))

View File

@@ -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"

View File

@@ -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
};

View File

@@ -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"]))