Refactor kvscode aliases and macros to Util.kiss
This commit is contained in:
@@ -1,28 +1,4 @@
|
||||
/**
|
||||
* Aliases
|
||||
*/
|
||||
|
||||
// TODO pass these aliases to the KissState of "eval kiss expression"
|
||||
|
||||
// output
|
||||
(defAlias &call infoMessage Vscode.window.showInformationMessage)
|
||||
(defAlias &call warningMessage Vscode.window.showWarningMessage)
|
||||
(defAlias &call errorMessage Vscode.window.showErrorMessage)
|
||||
|
||||
// input
|
||||
(defAlias &call inputBox Vscode.window.showInputBox)
|
||||
(defAlias &call quickPick Vscode.window.showQuickPick)
|
||||
|
||||
// commands
|
||||
(defAlias &call executeCommand Vscode.commands.executeCommand)
|
||||
(function repeatCommand [command times]
|
||||
(let [iteration
|
||||
->[&opt _] (executeCommand command)
|
||||
&mut promise
|
||||
(iteration)]
|
||||
(doFor i (range (- times 1))
|
||||
(set promise (promise.then iteration)))
|
||||
promise))
|
||||
(loadFrom "kiss-vscode" "src/Util.kiss")
|
||||
|
||||
// ui
|
||||
(defAlias &ident activeTextEditor Vscode.window.activeTextEditor)
|
||||
@@ -40,12 +16,6 @@
|
||||
(document.getText range))
|
||||
""))
|
||||
|
||||
(defMacro withValueOrInputBox [v &body body]
|
||||
`(if ,v
|
||||
{,@body}
|
||||
(awaitLet [,v (inputBox)]
|
||||
,@body)))
|
||||
|
||||
(function insertAt [:vscode.Position pos text]
|
||||
(activeTextEditor.edit
|
||||
(lambda [e]
|
||||
@@ -69,6 +39,7 @@
|
||||
* Functionality
|
||||
*/
|
||||
|
||||
// TODO pass macros and aliases from Util.kiss to the KissState of "eval kiss expression"
|
||||
(function :Dynamic evalString [:String kissStr]
|
||||
(try
|
||||
(interp.execute
|
||||
@@ -90,17 +61,9 @@
|
||||
(unless inputText (set inputText (selectedText)))
|
||||
(if command
|
||||
(_runCommandFunc command)
|
||||
(let [commandList
|
||||
(for description (commands.keys)
|
||||
(object
|
||||
label description
|
||||
description null
|
||||
detail null
|
||||
picked null
|
||||
alwaysShow null))]
|
||||
(awaitLet [chosenCommand (quickPick commandList)]
|
||||
(awaitLet [chosenCommand (quickPick (collect (commands.keys)))]
|
||||
(when chosenCommand
|
||||
(_runCommandFunc chosenCommand.label))))))
|
||||
(_runCommandFunc chosenCommand)))))
|
||||
|
||||
(function :Void runLastCommand [&opt _]
|
||||
(if lastCommand
|
||||
|
@@ -1,3 +1,50 @@
|
||||
/**
|
||||
* Aliases
|
||||
*/
|
||||
|
||||
|
||||
// output
|
||||
(defAlias &call infoMessage Vscode.window.showInformationMessage)
|
||||
(defAlias &call warningMessage Vscode.window.showWarningMessage)
|
||||
(defAlias &call errorMessage Vscode.window.showErrorMessage)
|
||||
|
||||
// input
|
||||
(defAlias &call inputBox Vscode.window.showInputBox)
|
||||
(defAlias &call _quickPick Vscode.window.showQuickPick)
|
||||
|
||||
(function quickPickItem [label &opt description]
|
||||
(object
|
||||
label label
|
||||
description description
|
||||
detail null
|
||||
picked null
|
||||
alwaysShow null))
|
||||
|
||||
(function quickPick [:Array<String> strings]
|
||||
(awaitLet [chosenItem (_quickPick (for string strings (quickPickItem string)))]
|
||||
chosenItem.label))
|
||||
|
||||
(function quickPickMap [:Map<String,Dynamic> stringMap]
|
||||
(awaitLet [chosenItem (_quickPick (for =>key value stringMap (quickPickItem key (Std.string value))))]
|
||||
(dictGet stringMap chosenItem.label)))
|
||||
|
||||
// commands
|
||||
(defAlias &call executeCommand Vscode.commands.executeCommand)
|
||||
(function repeatCommand [command times]
|
||||
(let [iteration
|
||||
->[&opt _] (executeCommand command)
|
||||
&mut promise
|
||||
(iteration)]
|
||||
(doFor i (range (- times 1))
|
||||
(set promise (promise.then iteration)))
|
||||
promise))
|
||||
|
||||
(defMacro withValueOrInputBox [v &body body]
|
||||
`(if ,v
|
||||
{,@body}
|
||||
(awaitLet [,v (inputBox)]
|
||||
,@body)))
|
||||
|
||||
// This has to be a macro so it can return from tryLoadConfig
|
||||
(defMacro trySpawnSync [command args options onError]
|
||||
`(let [command ,command
|
||||
|
@@ -1,3 +1,5 @@
|
||||
(load "../Util.kiss")
|
||||
|
||||
// Based on https://github.com/microsoft/vscode-extension-samples/blob/main/custom-editor-sample/src/catScratchEditor.ts
|
||||
|
||||
(function register [context]
|
||||
|
Reference in New Issue
Block a user