Kiss-Vscode can compile and load a Config.kiss

This commit is contained in:
2021-01-17 20:17:18 -07:00
parent 6c901ba943
commit 228d91f8e7
10 changed files with 89 additions and 10 deletions

View File

@@ -151,6 +151,7 @@ class Reader {
stream.startOfLine = false;
else
readFunction = chooseReadFunction(stream, k.readTable);
// This should never happen, because there is a readFunction for "":
if (readFunction == null)
throw 'No macro to read next expression';

View File

@@ -1,2 +1,6 @@
bin
*.vsix
*.vsix
config/config*.js
config/args.hxml
config/Config.kiss
config/import.hx

View File

@@ -0,0 +1,11 @@
package;
import kiss.Kiss;
import kiss.Prelude;
import js.lib.Promise;
typedef Command = (?String) -> Void;
@:build(kiss.Kiss.build("Config.kiss"))
@:build(kiss.Kiss.build("KissConfig.kiss"))
class KissConfig {}

View File

@@ -0,0 +1,14 @@
(defvar :Map<String,Command> commands (new Map))
// TODO use quickpick to choose one
(defun callCommand [] (return))
(defun registerCommand [description command]
(dictSet commands description command))
(defun registerBuiltins []
(return))
// Utility functions for VSCode actions
// TODO quickpick
/// TODO infoMessage

View File

@@ -0,0 +1,5 @@
args.hxml
-lib hxnodejs
-lib kiss
KissConfig
-js config.js

View File

@@ -0,0 +1,2 @@
(defun init []
(return))

View File

@@ -0,0 +1 @@
package;

View File

@@ -1,9 +1,13 @@
import vscode.*;
import Sys;
import sys.io.Process;
import kiss.Kiss;
import sys.io.File;
import sys.FileSystem;
import kiss.Prelude;
import haxe.io.Path;
import js.Node;
import js.node.ChildProcess;
using StringTools;
@:build(kiss.Kiss.build("src/Main.kiss"))
class Main {

View File

@@ -3,17 +3,54 @@
(or (Sys.getEnv "MSYSHOME") (Sys.getEnv "HOME") (Sys.getEnv "UserProfile"))
".kiss"]))
(defvar &mut activeConfigDir "")
(defun timeStamp []
(.replace (.replace (.toString (Date.now)) ":" "-") " " "-"))
// (defun tryLoadConfig [&opt selectedText]
// )
(defvar &mut activeConfigDir "")
(defvar &mut :Dynamic config null)
(defun tryLoadConfig [&opt :String text]
(let [activeConfigPath (Path.join [activeConfigDir "config.js"])
backupConfigPath (Path.join [activeConfigDir (+ "config" (timeStamp) ".js")])]
// Backup existing config.js
(when (FileSystem.exists activeConfigPath)
(FileSystem.rename activeConfigPath backupConfigPath))
// Supply the default (empty) config if the user doesn't have one
(let [customConfigDir
(if (FileSystem.exists (userConfigDir))
(userConfigDir)
(Path.join [activeConfigDir "default"]))
customConfigFiles
(FileSystem.readDirectory customConfigDir)]
// Copy the custom config files to the active config directory
(doFor file customConfigFiles
(File.copy
(Path.join [customConfigDir file])
(Path.join [activeConfigDir file])))
(let [buildResult
(ChildProcess.spawnSync "haxe" ["build.hxml"] (object cwd activeConfigDir))]
(if (and !buildResult.error (= 0 buildResult.status))
// Successful compilation! require the config.js package
(begin
(set config (Node.require (Path.join [activeConfigDir "config.js"])))
(Vscode.window.showInformationMessage "Config loaded successfully!"))
// If there's a build error, restore the config.js backup
(begin
(when (FileSystem.exists backupConfigPath)
(FileSystem.rename backupConfigPath activeConfigPath))
(Vscode.window.showErrorMessage
(+ "Config failed to compile: "
(if buildResult.error
#| "" + buildResult.error|#
#| "" + buildResult.stderr |#)))))))))
(defun _activate [:ExtensionContext context]
(set activeConfigDir (Path.join [context.extensionPath "config"]))
(print "yyooooo")
// TODO command to call KissConfig.callCommand if config != null
(context.subscriptions.push
(Vscode.commands.registerCommand
"kiss-vscode.sayHello"
(lambda []
(Vscode.window.showInformationMessage "Hello from Haxe!")))))
(Vscode.window.showInformationMessage "Hello from Haxe!"))))
(set activeConfigDir (Path.join [context.extensionPath "config"]))
(tryLoadConfig))