Kiss VSCode runnable commands
This commit is contained in:
@@ -2,9 +2,11 @@ package;
|
|||||||
|
|
||||||
import kiss.Kiss;
|
import kiss.Kiss;
|
||||||
import kiss.Prelude;
|
import kiss.Prelude;
|
||||||
|
import vscode.*;
|
||||||
import js.lib.Promise;
|
import js.lib.Promise;
|
||||||
|
|
||||||
typedef Command = (?String) -> Void;
|
typedef Command = (String) -> Void;
|
||||||
|
|
||||||
|
@:expose
|
||||||
@:build(kiss.Kiss.buildAll(["KissConfig.kiss", "Config.kiss"]))
|
@:build(kiss.Kiss.buildAll(["KissConfig.kiss", "Config.kiss"]))
|
||||||
class KissConfig {}
|
class KissConfig {}
|
||||||
|
@@ -1,14 +1,52 @@
|
|||||||
|
/**
|
||||||
|
* 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)
|
||||||
|
|
||||||
|
// ui
|
||||||
|
(defalias &ident activeTextEditor Vscode.window.activeTextEditor)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper functions
|
||||||
|
*/
|
||||||
|
(defun selectedText []
|
||||||
|
(if (and activeTextEditor .selection activeTextEditor)
|
||||||
|
(let [document
|
||||||
|
// TODO should be able to use activeTextEditor.document and have the alias still work
|
||||||
|
.document activeTextEditor
|
||||||
|
selection
|
||||||
|
.selection activeTextEditor
|
||||||
|
range (new Range selection.start selection.end)]
|
||||||
|
(document.getText range))
|
||||||
|
""))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Functionality
|
||||||
|
*/
|
||||||
(defvar :Map<String,Command> commands (new Map))
|
(defvar :Map<String,Command> commands (new Map))
|
||||||
|
|
||||||
// TODO use quickpick to choose one
|
(defun runCommand []
|
||||||
(defun callCommand [] (return))
|
(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 registerCommand [description command]
|
(defun registerCommand [description command]
|
||||||
(dictSet commands description command))
|
(dictSet commands description command))
|
||||||
|
|
||||||
(defun registerBuiltins []
|
(defun registerBuiltins []
|
||||||
(return))
|
(return))
|
||||||
|
|
||||||
// Utility functions for VSCode actions
|
|
||||||
// TODO quickpick
|
|
||||||
/// TODO infoMessage
|
|
@@ -1,5 +1,6 @@
|
|||||||
args.hxml
|
args.hxml
|
||||||
-lib hxnodejs
|
-lib hxnodejs
|
||||||
|
-lib vscode
|
||||||
-lib kiss
|
-lib kiss
|
||||||
KissConfig
|
KissConfig
|
||||||
-js config.js
|
-js config.js
|
8
projects/kiss-vscode/config/example/Config.kiss
Normal file
8
projects/kiss-vscode/config/example/Config.kiss
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
(defun init []
|
||||||
|
(registerCommand "print a nice message"
|
||||||
|
(lambda [selectedText]
|
||||||
|
(infoMessage "Hello world!")
|
||||||
|
(when selectedText
|
||||||
|
(infoMessage (+ "Also, " selectedText)))
|
||||||
|
(return)))
|
||||||
|
(return))
|
0
projects/kiss-vscode/config/example/args.hxml
Normal file
0
projects/kiss-vscode/config/example/args.hxml
Normal file
1
projects/kiss-vscode/config/example/import.hx
Normal file
1
projects/kiss-vscode/config/example/import.hx
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package;
|
@@ -10,14 +10,14 @@
|
|||||||
"Programming Languages"
|
"Programming Languages"
|
||||||
],
|
],
|
||||||
"activationEvents": [
|
"activationEvents": [
|
||||||
"onCommand:kiss-vscode.sayHello"
|
"onCommand:kiss.runCommand"
|
||||||
],
|
],
|
||||||
"main": "bin/extension.js",
|
"main": "bin/extension.js",
|
||||||
"contributes": {
|
"contributes": {
|
||||||
"commands": [
|
"commands": [
|
||||||
{
|
{
|
||||||
"command": "kiss-vscode.sayHello",
|
"command": "kiss.runCommand",
|
||||||
"title": "Say Hello"
|
"title": "Kiss: Run a Kiss command"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"languages": [{
|
"languages": [{
|
||||||
|
@@ -9,9 +9,18 @@ import js.node.ChildProcess;
|
|||||||
|
|
||||||
using StringTools;
|
using StringTools;
|
||||||
|
|
||||||
|
typedef Command = (String) -> Void;
|
||||||
|
|
||||||
|
typedef KissConfig = {
|
||||||
|
registerBuiltins:() -> Void,
|
||||||
|
registerCommand:(String, Command) -> Void,
|
||||||
|
runCommand:() -> Void,
|
||||||
|
init:() -> Void
|
||||||
|
};
|
||||||
|
|
||||||
@:build(kiss.Kiss.build("src/Main.kiss"))
|
@:build(kiss.Kiss.build("src/Main.kiss"))
|
||||||
class Main {
|
class Main {
|
||||||
// TODO support EMeta(s:MetadataEntry, e:Expr) via Kiss
|
// TODO support EMeta(s:MetadataEntry, e:Expr) via Kiss so this signature can be moved to Main.kiss
|
||||||
@:expose("activate")
|
@:expose("activate")
|
||||||
static function activate(context:ExtensionContext) {
|
static function activate(context:ExtensionContext) {
|
||||||
_activate(context);
|
_activate(context);
|
||||||
|
@@ -32,7 +32,10 @@
|
|||||||
(if (and !buildResult.error (= 0 buildResult.status))
|
(if (and !buildResult.error (= 0 buildResult.status))
|
||||||
// Successful compilation! require the config.js package
|
// Successful compilation! require the config.js package
|
||||||
(begin
|
(begin
|
||||||
(set config (Node.require (Path.join [activeConfigDir "config.js"])))
|
(set config .KissConfig (Node.require (Path.join [activeConfigDir "config.js"])))
|
||||||
|
(.registerBuiltins (the KissConfig config))
|
||||||
|
(.registerCommand (the KissConfig config) "Reload Kiss config" tryLoadConfig)
|
||||||
|
(.init (the KissConfig config))
|
||||||
(Vscode.window.showInformationMessage "Config loaded successfully!"))
|
(Vscode.window.showInformationMessage "Config loaded successfully!"))
|
||||||
// If there's a build error, restore the config.js backup
|
// If there's a build error, restore the config.js backup
|
||||||
(begin
|
(begin
|
||||||
@@ -42,15 +45,18 @@
|
|||||||
(+ "Config failed to compile: "
|
(+ "Config failed to compile: "
|
||||||
(if buildResult.error
|
(if buildResult.error
|
||||||
#| "" + buildResult.error|#
|
#| "" + buildResult.error|#
|
||||||
#| "" + buildResult.stderr |#)))))))))
|
#| "" + buildResult.stderr |#))))))))
|
||||||
|
(return))
|
||||||
|
|
||||||
(defun _activate [:ExtensionContext context]
|
(defun _activate [:ExtensionContext context]
|
||||||
// TODO command to call KissConfig.callCommand if config != null
|
|
||||||
(context.subscriptions.push
|
(context.subscriptions.push
|
||||||
(Vscode.commands.registerCommand
|
(Vscode.commands.registerCommand
|
||||||
"kiss-vscode.sayHello"
|
"kiss.runCommand"
|
||||||
(lambda []
|
(lambda []
|
||||||
(Vscode.window.showInformationMessage "Hello from Haxe!"))))
|
(if config
|
||||||
|
(.runCommand (the KissConfig config))
|
||||||
|
(Vscode.window.showErrorMessage "Can't run commands! No config is loaded."))
|
||||||
|
(return))))
|
||||||
|
|
||||||
(set activeConfigDir (Path.join [context.extensionPath "config"]))
|
(set activeConfigDir (Path.join [context.extensionPath "config"]))
|
||||||
(tryLoadConfig))
|
(tryLoadConfig))
|
||||||
|
Reference in New Issue
Block a user