fix kiss-vscode config hot-reloading
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
-lib vscode
|
-lib vscode
|
||||||
-lib hxnodejs
|
-lib hxnodejs
|
||||||
-lib kiss
|
-lib kiss
|
||||||
|
-lib uuid
|
||||||
-cp src
|
-cp src
|
||||||
-js bin/extension.js
|
-js bin/extension.js
|
||||||
-D analyzer-optimize
|
-D analyzer-optimize
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
"name": "kiss-vscode",
|
"name": "kiss-vscode",
|
||||||
"displayName": "kiss-vscode",
|
"displayName": "kiss-vscode",
|
||||||
"description": "Kiss language plugin",
|
"description": "Kiss language plugin",
|
||||||
"version": "0.0.3",
|
"version": "0.0.4",
|
||||||
"engines": {
|
"engines": {
|
||||||
"vscode": "^1.4.0"
|
"vscode": "^1.4.0"
|
||||||
},
|
},
|
||||||
|
@@ -6,8 +6,10 @@ import kiss.Prelude;
|
|||||||
import haxe.io.Path;
|
import haxe.io.Path;
|
||||||
import js.Node;
|
import js.Node;
|
||||||
import js.node.ChildProcess;
|
import js.node.ChildProcess;
|
||||||
|
import uuid.Uuid;
|
||||||
|
|
||||||
using StringTools;
|
using StringTools;
|
||||||
|
using uuid.Uuid;
|
||||||
|
|
||||||
typedef Command = (String) -> Void;
|
typedef Command = (String) -> Void;
|
||||||
|
|
||||||
|
@@ -30,11 +30,14 @@
|
|||||||
(let [buildResult
|
(let [buildResult
|
||||||
(ChildProcess.spawnSync "haxe" ["build.hxml"] (object cwd activeConfigDir))]
|
(ChildProcess.spawnSync "haxe" ["build.hxml"] (object cwd activeConfigDir))]
|
||||||
(if (and !buildResult.error (= 0 buildResult.status))
|
(if (and !buildResult.error (= 0 buildResult.status))
|
||||||
// Successful compilation! require the config.js package
|
// Successful compilation! require the config.js package.
|
||||||
(begin
|
// But since Node.require() caches modules by filename,
|
||||||
// TODO Node.require() caches the module so re-opening vscode is still required:
|
// copy it to a unique path first so hot-reloading works properly.
|
||||||
// https://stackoverflow.com/questions/9210542/node-js-require-cache-possible-to-invalidate
|
(let [activeConfigFile (Path.join [activeConfigDir "config.js"])
|
||||||
(set config .KissConfig (Node.require (Path.join [activeConfigDir "config.js"])))
|
uniqueConfigFile (Path.join [activeConfigDir "$(.toShort (Uuid.v4)).js"])]
|
||||||
|
(File.copy activeConfigFile uniqueConfigFile)
|
||||||
|
(set config .KissConfig (Node.require uniqueConfigFile))
|
||||||
|
(FileSystem.deleteFile uniqueConfigFile)
|
||||||
(.registerBuiltins (the KissConfig config))
|
(.registerBuiltins (the KissConfig config))
|
||||||
(.registerCommand (the KissConfig config) "Reload Kiss config" tryLoadConfig)
|
(.registerCommand (the KissConfig config) "Reload Kiss config" tryLoadConfig)
|
||||||
(.init (the KissConfig config))
|
(.init (the KissConfig config))
|
||||||
@@ -64,6 +67,8 @@
|
|||||||
(.runCommand (the KissConfig config))
|
(.runCommand (the KissConfig config))
|
||||||
(Vscode.window.showErrorMessage "Can't run commands! No config is loaded."))
|
(Vscode.window.showErrorMessage "Can't run commands! No config is loaded."))
|
||||||
(return))))
|
(return))))
|
||||||
|
|
||||||
|
// TODO overload Prelude.print to use showInformationMessage
|
||||||
|
|
||||||
(set activeConfigDir (Path.join [context.extensionPath "config"]))
|
(set activeConfigDir (Path.join [context.extensionPath "config"]))
|
||||||
(tryLoadConfig))
|
(tryLoadConfig))
|
||||||
|
Reference in New Issue
Block a user