From 6d7ee279779b3ddbf11778f6b3608d010fbb5803 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Sat, 22 May 2021 14:05:30 -0600 Subject: [PATCH] [vscode] new kiss class command --- projects/kiss-vscode/config/KissConfig.hx | 4 ++ projects/kiss-vscode/config/KissConfig.kiss | 42 ++++++++++++++++++++- projects/kiss-vscode/src/Main.kiss | 2 +- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/projects/kiss-vscode/config/KissConfig.hx b/projects/kiss-vscode/config/KissConfig.hx index d52e43f2..109893ef 100644 --- a/projects/kiss-vscode/config/KissConfig.hx +++ b/projects/kiss-vscode/config/KissConfig.hx @@ -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; diff --git a/projects/kiss-vscode/config/KissConfig.kiss b/projects/kiss-vscode/config/KissConfig.kiss index 406e892a..33777c1b 100644 --- a/projects/kiss-vscode/config/KissConfig.kiss +++ b/projects/kiss-vscode/config/KissConfig.kiss @@ -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))) \ No newline at end of file + ,@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))))) \ No newline at end of file diff --git a/projects/kiss-vscode/src/Main.kiss b/projects/kiss-vscode/src/Main.kiss index 32347752..52d580e1 100644 --- a/projects/kiss-vscode/src/Main.kiss +++ b/projects/kiss-vscode/src/Main.kiss @@ -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)