reorganize kiss-vscode

This commit is contained in:
2021-10-19 12:30:37 -04:00
parent 737e42c588
commit b0a19330c4
10 changed files with 65 additions and 61 deletions

View File

@@ -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

View File

@@ -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)))))
int Std.int)))

View File

@@ -97,4 +97,4 @@
"onCommand:kiss.reloadConfig"
],
"displayName": "kiss-vscode"
}
}

View File

@@ -1,5 +1,6 @@
#if !test
import vscode.*;
import ktxt2.*;
#end
import Sys;
import sys.io.File;

View File

@@ -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)

View File

@@ -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))))))

View File

@@ -1,3 +1,5 @@
package ktxt2;
import js.html.Window;
typedef VSCodeAPI = {

View File

@@ -1,4 +1,4 @@
import EditorExterns;
package ktxt2;
class KTxt2Editor {
public static function main() {

View File

@@ -1,3 +1,5 @@
package ktxt2;
import kiss.Prelude;
import kiss.List;
import vscode.*;