[vscode] new kiss class command
This commit is contained in:
@@ -9,6 +9,10 @@ import js.lib.Promise;
|
|||||||
import hscript.Parser;
|
import hscript.Parser;
|
||||||
import hscript.Interp;
|
import hscript.Interp;
|
||||||
import hscript.Expr;
|
import hscript.Expr;
|
||||||
|
import haxe.io.Path;
|
||||||
|
import sys.io.File;
|
||||||
|
|
||||||
|
using haxe.io.Path;
|
||||||
|
|
||||||
typedef Command = (String) -> Void;
|
typedef Command = (String) -> Void;
|
||||||
|
|
||||||
|
@@ -2,6 +2,8 @@
|
|||||||
* Aliases
|
* Aliases
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// TODO pass these aliases to the KissState of "eval kiss expression"
|
||||||
|
|
||||||
// output
|
// output
|
||||||
(defalias &call infoMessage Vscode.window.showInformationMessage)
|
(defalias &call infoMessage Vscode.window.showInformationMessage)
|
||||||
(defalias &call warningMessage Vscode.window.showWarningMessage)
|
(defalias &call warningMessage Vscode.window.showWarningMessage)
|
||||||
@@ -213,7 +215,8 @@
|
|||||||
(registerCommand "Run a [k]iss command" runCommand)
|
(registerCommand "Run a [k]iss command" runCommand)
|
||||||
(registerCommand "Rerun last command" runLastCommand)
|
(registerCommand "Rerun last command" runLastCommand)
|
||||||
(registerCommand "Run a keyboard shortcut command" runKeyboardShortcut)
|
(registerCommand "Run a keyboard shortcut command" runKeyboardShortcut)
|
||||||
(registerCommand "Evaluate and print a Kiss expression" evalAndPrint))
|
(registerCommand "[e]valuate and print a Kiss expression" evalAndPrint)
|
||||||
|
(registerCommand "[n]ew kiss class" newKissClass))
|
||||||
|
|
||||||
// TODO standardize this with KissInterp
|
// TODO standardize this with KissInterp
|
||||||
(defun :Void prepareInterp []
|
(defun :Void prepareInterp []
|
||||||
@@ -227,6 +230,7 @@
|
|||||||
//interp.variables.set("Helpers", Helpers);
|
//interp.variables.set("Helpers", Helpers);
|
||||||
(interp.variables.set "Prelude" Prelude)
|
(interp.variables.set "Prelude" Prelude)
|
||||||
(interp.variables.set "Lambda" Lambda)
|
(interp.variables.set "Lambda" Lambda)
|
||||||
|
(interp.variables.set "Vscode" Vscode)
|
||||||
// TODO for some reason, (interp.variables.set "Std" Std) doesn't capture
|
// TODO for some reason, (interp.variables.set "Std" Std) doesn't capture
|
||||||
// some static functions, like parseInt. So this kludgy bit is necessary:
|
// some static functions, like parseInt. So this kludgy bit is necessary:
|
||||||
(interp.variables.set "Std"
|
(interp.variables.set "Std"
|
||||||
@@ -241,3 +245,37 @@
|
|||||||
{,@body}
|
{,@body}
|
||||||
(awaitLet [,v (inputBox)]
|
(awaitLet [,v (inputBox)]
|
||||||
,@body)))
|
,@body)))
|
||||||
|
|
||||||
|
(defun :Void newKissClass [&opt _]
|
||||||
|
(awaitLet [className (inputBox)]
|
||||||
|
(let [currentFile
|
||||||
|
.fileName .document activeTextEditor
|
||||||
|
currentFileDirectory
|
||||||
|
(Path.directory currentFile)
|
||||||
|
haxeFile
|
||||||
|
(Path.join [currentFileDirectory "${className}.hx"])
|
||||||
|
kissFile
|
||||||
|
(Path.join [currentFileDirectory "${className}.kiss"])
|
||||||
|
// Try to use the same package statement from the first line of the
|
||||||
|
// currently open Kiss class's .hx file
|
||||||
|
pkg
|
||||||
|
(or
|
||||||
|
(try
|
||||||
|
(let [currentHaxeFile
|
||||||
|
(currentFile.withExtension "hx")]
|
||||||
|
(first (.split (File.getContent currentHaxeFile) "\n")))
|
||||||
|
(catch [e] ""))
|
||||||
|
// Default to no specific package declaration
|
||||||
|
"package;")]
|
||||||
|
(File.saveContent haxeFile
|
||||||
|
"${pkg}
|
||||||
|
|
||||||
|
import kiss.Prelude;
|
||||||
|
import kiss.List;
|
||||||
|
import kiss.Operand;
|
||||||
|
|
||||||
|
@:build(kiss.Kiss.build())
|
||||||
|
class ${className} {}
|
||||||
|
")
|
||||||
|
(File.saveContent kissFile "")
|
||||||
|
(Vscode.window.showTextDocument (Uri.file kissFile)))))
|
@@ -40,7 +40,7 @@
|
|||||||
(set config (the KissConfig .KissConfig (Node.require uniqueConfigFile)))
|
(set config (the KissConfig .KissConfig (Node.require uniqueConfigFile)))
|
||||||
// (FileSystem.deleteFile uniqueConfigFile)
|
// (FileSystem.deleteFile uniqueConfigFile)
|
||||||
(config.registerBuiltins)
|
(config.registerBuiltins)
|
||||||
(config.registerCommand "Reload Kiss config" tryLoadConfig)
|
(config.registerCommand "[r]eload Kiss config" tryLoadConfig)
|
||||||
(config.prepareInterp)
|
(config.prepareInterp)
|
||||||
// User-defined init:
|
// User-defined init:
|
||||||
(config.init)
|
(config.init)
|
||||||
|
Reference in New Issue
Block a user