kiss-vscode-api defCommand macro
This commit is contained in:
@@ -155,4 +155,71 @@
|
|||||||
(Vscode.window.showErrorMessage chosen.match)
|
(Vscode.window.showErrorMessage chosen.match)
|
||||||
(executeCommand "workbench.action.quickOpen" (substr (chosen.namedGroup "file") 0 -1)))
|
(executeCommand "workbench.action.quickOpen" (substr (chosen.namedGroup "file") 0 -1)))
|
||||||
}
|
}
|
||||||
(Vscode.window.showErrorMessage errorMessage))))
|
(Vscode.window.showErrorMessage errorMessage)))
|
||||||
|
|
||||||
|
// Example:
|
||||||
|
/*
|
||||||
|
(defCommand myExt.customCommand "Custom command that does something" "C-; C-c" [<args...>] <body...>)
|
||||||
|
*/
|
||||||
|
(defMacro defCommand [context id description shortcut argList &body body]
|
||||||
|
(let [id (symbolNameValue id)
|
||||||
|
description (eval description)
|
||||||
|
shortcut (eval shortcut)
|
||||||
|
shortcutWithHyphensProcessed
|
||||||
|
(StringTools.replace
|
||||||
|
(StringTools.replace
|
||||||
|
(StringTools.replace
|
||||||
|
(StringTools.replace
|
||||||
|
(StringTools.replace
|
||||||
|
shortcut
|
||||||
|
"Cmd" "C")
|
||||||
|
"Ctrl" "C")
|
||||||
|
"--" "++")
|
||||||
|
"-" "+")
|
||||||
|
"++" "-+")
|
||||||
|
packageJson
|
||||||
|
(Json.parse (File.getContent "package.json"))
|
||||||
|
keybindings
|
||||||
|
packageJson.contributes.keybindings
|
||||||
|
commands
|
||||||
|
packageJson.contributes.commands
|
||||||
|
functionName
|
||||||
|
(symbol (StringTools.replace id "." "_"))
|
||||||
|
&mut keyBindingIndex null
|
||||||
|
&mut commandIndex null]
|
||||||
|
(doFor [idx binding] (enumerate keybindings)
|
||||||
|
(when (= binding.command id)
|
||||||
|
(set keyBindingIndex idx)
|
||||||
|
(break)))
|
||||||
|
(doFor [idx command] (enumerate commands)
|
||||||
|
(when (= command.command id)
|
||||||
|
(set commandIndex idx)
|
||||||
|
(break)))
|
||||||
|
// Manage the command entry in JSON
|
||||||
|
(unless commandIndex (set commandIndex commands.length))
|
||||||
|
(setNth commands commandIndex
|
||||||
|
(object
|
||||||
|
command id
|
||||||
|
title description))
|
||||||
|
// Manage the keybinding entry in JSON
|
||||||
|
(cond
|
||||||
|
(shortcut
|
||||||
|
(unless keyBindingIndex (set keyBindingIndex keybindings.length))
|
||||||
|
(setNth keybindings keyBindingIndex
|
||||||
|
(object
|
||||||
|
command id
|
||||||
|
mac (StringTools.replace shortcutWithHyphensProcessed "C" "Cmd")
|
||||||
|
key (StringTools.replace shortcutWithHyphensProcessed "C" "Ctrl"))))
|
||||||
|
|
||||||
|
// A binding element is in the JSON that needs to be removed:
|
||||||
|
(keyBindingIndex
|
||||||
|
(keybindings.splice keyBindingIndex 1)))
|
||||||
|
(File.saveContent "package.json" (Json.stringify packageJson null "\t"))
|
||||||
|
`{
|
||||||
|
(function ,functionName ,argList
|
||||||
|
,@body)
|
||||||
|
(.push .subscriptions ,context
|
||||||
|
(Vscode.commands.registerCommand
|
||||||
|
,(ReaderExp.StrExp id )
|
||||||
|
,functionName))
|
||||||
|
})))
|
||||||
@@ -11,6 +11,12 @@
|
|||||||
"Programming Languages",
|
"Programming Languages",
|
||||||
"Extension Packs"
|
"Extension Packs"
|
||||||
],
|
],
|
||||||
|
"extensionPack": [
|
||||||
|
"2gua.rainbow-brackets"
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"monaco-editor": "^0.29.1"
|
||||||
|
},
|
||||||
"publisher": "NQNStudios",
|
"publisher": "NQNStudios",
|
||||||
"contributes": {
|
"contributes": {
|
||||||
"grammars": [
|
"grammars": [
|
||||||
@@ -42,9 +48,21 @@
|
|||||||
"key": "ctrl+;"
|
"key": "ctrl+;"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"customEditors": [
|
||||||
|
{
|
||||||
|
"selector": [
|
||||||
|
{
|
||||||
|
"filenamePattern": "*.*.*.ktxt2"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"priority": "default",
|
||||||
|
"viewType": "ktxt2.splitView",
|
||||||
|
"displayName": "KTxt2 Split View"
|
||||||
|
}
|
||||||
|
],
|
||||||
"commands": [
|
"commands": [
|
||||||
{
|
{
|
||||||
"title": "Kiss: Run a Kiss command",
|
"title": "Kiss: Run a kiss command",
|
||||||
"command": "kiss.runCommand"
|
"command": "kiss.runCommand"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -76,18 +94,6 @@
|
|||||||
"kiss"
|
"kiss"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
|
||||||
"customEditors": [
|
|
||||||
{
|
|
||||||
"viewType": "ktxt2.splitView",
|
|
||||||
"displayName": "KTxt2 Split View",
|
|
||||||
"selector": [
|
|
||||||
{
|
|
||||||
"filenamePattern": "*.*.*.ktxt2"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"priority": "default"
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
@@ -101,11 +107,5 @@
|
|||||||
"onCommand:kiss.runKeyboardShortcut",
|
"onCommand:kiss.runKeyboardShortcut",
|
||||||
"onCommand:kiss.reloadConfig"
|
"onCommand:kiss.reloadConfig"
|
||||||
],
|
],
|
||||||
"displayName": "kiss-vscode",
|
"displayName": "kiss-vscode"
|
||||||
"dependencies": {
|
|
||||||
"monaco-editor": "^0.29.1"
|
|
||||||
},
|
|
||||||
"extensionPack": [
|
|
||||||
"2gua.rainbow-brackets"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
@@ -150,13 +150,12 @@
|
|||||||
(Vscode.commands.registerCommand
|
(Vscode.commands.registerCommand
|
||||||
"kiss.reloadConfig"
|
"kiss.reloadConfig"
|
||||||
->(tryLoadConfig true)))
|
->(tryLoadConfig true)))
|
||||||
(context.subscriptions.push
|
|
||||||
(Vscode.commands.registerCommand
|
(defCommand context kiss.runCommand "Kiss: Run a kiss command" "" []
|
||||||
"kiss.runCommand"
|
(if config
|
||||||
(lambda :Void []
|
(.runCommand (the KissConfig config))
|
||||||
(if config
|
(Vscode.window.showErrorMessage "Can't run commands! No config is loaded."))
|
||||||
(.runCommand (the KissConfig config))
|
null)
|
||||||
(Vscode.window.showErrorMessage "Can't run commands! No config is loaded.")))))
|
|
||||||
|
|
||||||
(context.subscriptions.push
|
(context.subscriptions.push
|
||||||
(Vscode.commands.registerCommand
|
(Vscode.commands.registerCommand
|
||||||
|
|||||||
Reference in New Issue
Block a user