[vscode] new kiss class command

This commit is contained in:
2021-05-22 14:05:30 -06:00
parent a2379074c6
commit 6d7ee27977
3 changed files with 45 additions and 3 deletions

View File

@@ -9,6 +9,10 @@ import js.lib.Promise;
import hscript.Parser;
import hscript.Interp;
import hscript.Expr;
import haxe.io.Path;
import sys.io.File;
using haxe.io.Path;
typedef Command = (String) -> Void;

View File

@@ -2,6 +2,8 @@
* 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)
@@ -213,7 +215,8 @@
(registerCommand "Run a [k]iss command" runCommand)
(registerCommand "Rerun last command" runLastCommand)
(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
(defun :Void prepareInterp []
@@ -227,6 +230,7 @@
//interp.variables.set("Helpers", Helpers);
(interp.variables.set "Prelude" Prelude)
(interp.variables.set "Lambda" Lambda)
(interp.variables.set "Vscode" Vscode)
// TODO for some reason, (interp.variables.set "Std" Std) doesn't capture
// some static functions, like parseInt. So this kludgy bit is necessary:
(interp.variables.set "Std"
@@ -240,4 +244,38 @@
`(if ,v
{,@body}
(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)))))

View File

@@ -40,7 +40,7 @@
(set config (the KissConfig .KissConfig (Node.require uniqueConfigFile)))
// (FileSystem.deleteFile uniqueConfigFile)
(config.registerBuiltins)
(config.registerCommand "Reload Kiss config" tryLoadConfig)
(config.registerCommand "[r]eload Kiss config" tryLoadConfig)
(config.prepareInterp)
// User-defined init:
(config.init)