diff --git a/projects/kiss-vscode/build.hxml b/projects/kiss-vscode/build.hxml index bb66e085..9f41c0ff 100644 --- a/projects/kiss-vscode/build.hxml +++ b/projects/kiss-vscode/build.hxml @@ -1,7 +1,3 @@ --cp src --js bin/ktxt2editor.js ---main KTxt2Editor ---next -lib vscode -lib hxnodejs -lib kiss @@ -14,3 +10,7 @@ -D js-es=6 -debug --main Main +--next +-cp src +-js bin/ktxt2editor.js +--main ktxt2.KTxt2Editor \ No newline at end of file diff --git a/projects/kiss-vscode/config/KissConfig.kiss b/projects/kiss-vscode/config/KissConfig.kiss index 04910a61..79d1303b 100644 --- a/projects/kiss-vscode/config/KissConfig.kiss +++ b/projects/kiss-vscode/config/KissConfig.kiss @@ -40,8 +40,12 @@ (document.getText range)) "")) -// TODO make an async annotation that throws an error if the promise is not wrapped in awaitLet or awaitBegin or returned by an async function? -// but in some cases it doesn't matter and there are so many edge cases. +(defMacro withValueOrInputBox [v &body body] + `(if ,v + {,@body} + (awaitLet [,v (inputBox)] + ,@body))) + (function insertAt [:vscode.Position pos text] (activeTextEditor.edit (lambda [e] @@ -74,13 +78,6 @@ (errorMessage "Error `${e}` from $kissStr") null))) -(function :Void evalAndPrint [&opt :String selectedText] - (if selectedText - (infoMessage (Std.string (evalString selectedText)))) - - (awaitLet [kissStr (inputBox)] - (infoMessage (Std.string (evalString kissStr))))) - (function :Void runCommand [&opt command] (_runCommand command)) (defMacro _runCommandFunc [commandName] @@ -241,13 +238,17 @@ (function registerExistingCommand [description command] (registerCommand description (lambda :Void [&opt _] (executeCommand command)))) +(loadFrom "kiss-vscode" "src/commands/KissTools.kiss") + (function :Void registerBuiltins [] (set Prelude.printStr ->:Void s (infoMessage s)) - (registerCommand "Run a [k]iss command" runCommand) - (registerCommand "Rerun last command" runLastCommand) - (registerCommand "Run a keyboard shortcut command" runKeyboardShortcut) - (registerCommand "[e]valuate and print a Kiss expression" evalAndPrint) - (registerCommand "[n]ew kiss class" newKissClass)) + // In this file: + (registerCommand "[K]iss: Run a Kiss-VSCode [c]ommand" runCommand) + (registerCommand "[K]iss: Re-run [l]ast Kiss-VSCode command" runLastCommand) + (registerCommand "[K]iss: Run a keyboard [s]hortcut command" runKeyboardShortcut) + // KissTools.kiss: + (registerCommand "[K]iss: [e]valuate and print an expression" evalAndPrint) + (registerCommand "[K]iss: create [n]ew kiss class" newKissClass)) // TODO standardize this with KissInterp (function :Void prepareInterp [] @@ -266,43 +267,4 @@ parseInt Std.parseInt string Std.string random Std.random - int Std.int))) - -(defMacro withValueOrInputBox [v &body body] - `(if ,v - {,@body} - (awaitLet [,v (inputBox)] - ,@body))) - -(function :Void newKissClass [&opt _] - (awaitLet [className (inputBox)] - (let [currentFile - activeTextEditor.document.fileName - currentFileDirectory - (Path.directory currentFile) - haxeFile - (joinPath currentFileDirectory "${className}.hx") - kissFile - (joinPath 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; - -@:build(kiss.Kiss.build()) -class ${className} {} -") - (File.saveContent kissFile "") - (Vscode.window.showTextDocument (Uri.file kissFile))))) \ No newline at end of file + int Std.int))) \ No newline at end of file diff --git a/projects/kiss-vscode/package.json b/projects/kiss-vscode/package.json index 845343c7..458f7b22 100644 --- a/projects/kiss-vscode/package.json +++ b/projects/kiss-vscode/package.json @@ -97,4 +97,4 @@ "onCommand:kiss.reloadConfig" ], "displayName": "kiss-vscode" -} \ No newline at end of file +} diff --git a/projects/kiss-vscode/src/Main.hx b/projects/kiss-vscode/src/Main.hx index 7ada2ebf..470d4dd9 100644 --- a/projects/kiss-vscode/src/Main.hx +++ b/projects/kiss-vscode/src/Main.hx @@ -1,5 +1,6 @@ #if !test import vscode.*; +import ktxt2.*; #end import Sys; import sys.io.File; diff --git a/projects/kiss-vscode/src/Main.kiss b/projects/kiss-vscode/src/Main.kiss index 6b6ddf8a..3a9f045c 100644 --- a/projects/kiss-vscode/src/Main.kiss +++ b/projects/kiss-vscode/src/Main.kiss @@ -92,7 +92,7 @@ (set config (the KissConfig .KissConfig (Node.require uniqueConfigFile))) // (FileSystem.deleteFile uniqueConfigFile) (config.registerBuiltins) - (config.registerCommand "[r]eload Kiss config" tryLoadConfig) + (config.registerCommand "[K]iss: [r]eload Kiss config" tryLoadConfig) (config.prepareInterp) // User-defined init: (config.init) diff --git a/projects/kiss-vscode/src/commands/KissTools.kiss b/projects/kiss-vscode/src/commands/KissTools.kiss new file mode 100644 index 00000000..fb45a9e4 --- /dev/null +++ b/projects/kiss-vscode/src/commands/KissTools.kiss @@ -0,0 +1,37 @@ +(function :Void evalAndPrint [&opt :String selectedText] + (withValueOrInputBox selectedText + (infoMessage (Std.string (evalString selectedText))))) + +(function :Void newKissClass [&opt _] + (awaitLet [className (inputBox)] + (when className + (let [currentFile + activeTextEditor.document.fileName + currentFileDirectory + (Path.directory currentFile) + haxeFile + (joinPath currentFileDirectory "${className}.hx") + kissFile + (joinPath 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; + +@: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/EditorExterns.hx b/projects/kiss-vscode/src/ktxt2/EditorExterns.hx similarity index 94% rename from projects/kiss-vscode/src/EditorExterns.hx rename to projects/kiss-vscode/src/ktxt2/EditorExterns.hx index 3455366b..fbbe1874 100644 --- a/projects/kiss-vscode/src/EditorExterns.hx +++ b/projects/kiss-vscode/src/ktxt2/EditorExterns.hx @@ -1,3 +1,5 @@ +package ktxt2; + import js.html.Window; typedef VSCodeAPI = { diff --git a/projects/kiss-vscode/src/KTxt2Editor.hx b/projects/kiss-vscode/src/ktxt2/KTxt2Editor.hx similarity index 93% rename from projects/kiss-vscode/src/KTxt2Editor.hx rename to projects/kiss-vscode/src/ktxt2/KTxt2Editor.hx index aeaa88a6..e6369c73 100644 --- a/projects/kiss-vscode/src/KTxt2Editor.hx +++ b/projects/kiss-vscode/src/ktxt2/KTxt2Editor.hx @@ -1,4 +1,4 @@ -import EditorExterns; +package ktxt2; class KTxt2Editor { public static function main() { diff --git a/projects/kiss-vscode/src/KTxt2EditorProvider.hx b/projects/kiss-vscode/src/ktxt2/KTxt2EditorProvider.hx similarity index 89% rename from projects/kiss-vscode/src/KTxt2EditorProvider.hx rename to projects/kiss-vscode/src/ktxt2/KTxt2EditorProvider.hx index 366deab8..fa067fce 100644 --- a/projects/kiss-vscode/src/KTxt2EditorProvider.hx +++ b/projects/kiss-vscode/src/ktxt2/KTxt2EditorProvider.hx @@ -1,3 +1,5 @@ +package ktxt2; + import kiss.Prelude; import kiss.List; import vscode.*; diff --git a/projects/kiss-vscode/src/KTxt2EditorProvider.kiss b/projects/kiss-vscode/src/ktxt2/KTxt2EditorProvider.kiss similarity index 100% rename from projects/kiss-vscode/src/KTxt2EditorProvider.kiss rename to projects/kiss-vscode/src/ktxt2/KTxt2EditorProvider.kiss