Refactor kvscode aliases and macros to Util.kiss
This commit is contained in:
@@ -1,28 +1,4 @@
|
|||||||
/**
|
(loadFrom "kiss-vscode" "src/Util.kiss")
|
||||||
* 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))
|
|
||||||
|
|
||||||
// ui
|
// ui
|
||||||
(defAlias &ident activeTextEditor Vscode.window.activeTextEditor)
|
(defAlias &ident activeTextEditor Vscode.window.activeTextEditor)
|
||||||
@@ -40,12 +16,6 @@
|
|||||||
(document.getText range))
|
(document.getText range))
|
||||||
""))
|
""))
|
||||||
|
|
||||||
(defMacro withValueOrInputBox [v &body body]
|
|
||||||
`(if ,v
|
|
||||||
{,@body}
|
|
||||||
(awaitLet [,v (inputBox)]
|
|
||||||
,@body)))
|
|
||||||
|
|
||||||
(function insertAt [:vscode.Position pos text]
|
(function insertAt [:vscode.Position pos text]
|
||||||
(activeTextEditor.edit
|
(activeTextEditor.edit
|
||||||
(lambda [e]
|
(lambda [e]
|
||||||
@@ -69,6 +39,7 @@
|
|||||||
* Functionality
|
* Functionality
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// TODO pass macros and aliases from Util.kiss to the KissState of "eval kiss expression"
|
||||||
(function :Dynamic evalString [:String kissStr]
|
(function :Dynamic evalString [:String kissStr]
|
||||||
(try
|
(try
|
||||||
(interp.execute
|
(interp.execute
|
||||||
@@ -90,17 +61,9 @@
|
|||||||
(unless inputText (set inputText (selectedText)))
|
(unless inputText (set inputText (selectedText)))
|
||||||
(if command
|
(if command
|
||||||
(_runCommandFunc command)
|
(_runCommandFunc command)
|
||||||
(let [commandList
|
(awaitLet [chosenCommand (quickPick (collect (commands.keys)))]
|
||||||
(for description (commands.keys)
|
|
||||||
(object
|
|
||||||
label description
|
|
||||||
description null
|
|
||||||
detail null
|
|
||||||
picked null
|
|
||||||
alwaysShow null))]
|
|
||||||
(awaitLet [chosenCommand (quickPick commandList)]
|
|
||||||
(when chosenCommand
|
(when chosenCommand
|
||||||
(_runCommandFunc chosenCommand.label))))))
|
(_runCommandFunc chosenCommand)))))
|
||||||
|
|
||||||
(function :Void runLastCommand [&opt _]
|
(function :Void runLastCommand [&opt _]
|
||||||
(if lastCommand
|
(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
|
// This has to be a macro so it can return from tryLoadConfig
|
||||||
(defMacro trySpawnSync [command args options onError]
|
(defMacro trySpawnSync [command args options onError]
|
||||||
`(let [command ,command
|
`(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
|
// Based on https://github.com/microsoft/vscode-extension-samples/blob/main/custom-editor-sample/src/catScratchEditor.ts
|
||||||
|
|
||||||
(function register [context]
|
(function register [context]
|
||||||
|
Reference in New Issue
Block a user