Kiss-Vscode can compile and load a Config.kiss
This commit is contained in:
@@ -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';
|
||||
|
||||
|
6
projects/kiss-vscode/.gitignore
vendored
6
projects/kiss-vscode/.gitignore
vendored
@@ -1,2 +1,6 @@
|
||||
bin
|
||||
*.vsix
|
||||
*.vsix
|
||||
config/config*.js
|
||||
config/args.hxml
|
||||
config/Config.kiss
|
||||
config/import.hx
|
11
projects/kiss-vscode/config/KissConfig.hx
Normal file
11
projects/kiss-vscode/config/KissConfig.hx
Normal 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 {}
|
14
projects/kiss-vscode/config/KissConfig.kiss
Normal file
14
projects/kiss-vscode/config/KissConfig.kiss
Normal 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
|
5
projects/kiss-vscode/config/build.hxml
Normal file
5
projects/kiss-vscode/config/build.hxml
Normal file
@@ -0,0 +1,5 @@
|
||||
args.hxml
|
||||
-lib hxnodejs
|
||||
-lib kiss
|
||||
KissConfig
|
||||
-js config.js
|
2
projects/kiss-vscode/config/default/Config.kiss
Normal file
2
projects/kiss-vscode/config/default/Config.kiss
Normal file
@@ -0,0 +1,2 @@
|
||||
(defun init []
|
||||
(return))
|
0
projects/kiss-vscode/config/default/args.hxml
Normal file
0
projects/kiss-vscode/config/default/args.hxml
Normal file
1
projects/kiss-vscode/config/default/import.hx
Normal file
1
projects/kiss-vscode/config/default/import.hx
Normal file
@@ -0,0 +1 @@
|
||||
package;
|
@@ -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 {
|
||||
|
@@ -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))
|
||||
|
Reference in New Issue
Block a user