Kiss VSCode runnable commands
This commit is contained in:
@@ -2,9 +2,11 @@ package;
|
||||
|
||||
import kiss.Kiss;
|
||||
import kiss.Prelude;
|
||||
import vscode.*;
|
||||
import js.lib.Promise;
|
||||
|
||||
typedef Command = (?String) -> Void;
|
||||
typedef Command = (String) -> Void;
|
||||
|
||||
@:expose
|
||||
@:build(kiss.Kiss.buildAll(["KissConfig.kiss", "Config.kiss"]))
|
||||
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))
|
||||
|
||||
// TODO use quickpick to choose one
|
||||
(defun callCommand [] (return))
|
||||
(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 registerCommand [description command]
|
||||
(dictSet commands description command))
|
||||
|
||||
(defun registerBuiltins []
|
||||
(return))
|
||||
|
||||
// Utility functions for VSCode actions
|
||||
// TODO quickpick
|
||||
/// TODO infoMessage
|
@@ -1,5 +1,6 @@
|
||||
args.hxml
|
||||
-lib hxnodejs
|
||||
-lib vscode
|
||||
-lib kiss
|
||||
KissConfig
|
||||
-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"
|
||||
],
|
||||
"activationEvents": [
|
||||
"onCommand:kiss-vscode.sayHello"
|
||||
"onCommand:kiss.runCommand"
|
||||
],
|
||||
"main": "bin/extension.js",
|
||||
"contributes": {
|
||||
"commands": [
|
||||
{
|
||||
"command": "kiss-vscode.sayHello",
|
||||
"title": "Say Hello"
|
||||
"command": "kiss.runCommand",
|
||||
"title": "Kiss: Run a Kiss command"
|
||||
}
|
||||
],
|
||||
"languages": [{
|
||||
|
@@ -9,9 +9,18 @@ import js.node.ChildProcess;
|
||||
|
||||
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"))
|
||||
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")
|
||||
static function activate(context:ExtensionContext) {
|
||||
_activate(context);
|
||||
|
@@ -32,7 +32,10 @@
|
||||
(if (and !buildResult.error (= 0 buildResult.status))
|
||||
// Successful compilation! require the config.js package
|
||||
(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!"))
|
||||
// If there's a build error, restore the config.js backup
|
||||
(begin
|
||||
@@ -42,15 +45,18 @@
|
||||
(+ "Config failed to compile: "
|
||||
(if buildResult.error
|
||||
#| "" + buildResult.error|#
|
||||
#| "" + buildResult.stderr |#)))))))))
|
||||
#| "" + buildResult.stderr |#))))))))
|
||||
(return))
|
||||
|
||||
(defun _activate [:ExtensionContext context]
|
||||
// TODO command to call KissConfig.callCommand if config != null
|
||||
(context.subscriptions.push
|
||||
(Vscode.commands.registerCommand
|
||||
"kiss-vscode.sayHello"
|
||||
"kiss.runCommand"
|
||||
(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"]))
|
||||
(tryLoadConfig))
|
||||
|
Reference in New Issue
Block a user