From 32ae64418b8aba0ec04144205de85c788faa173e Mon Sep 17 00:00:00 2001 From: Saikyun Date: Tue, 9 Apr 2019 13:03:44 +0200 Subject: [PATCH 1/5] Update README.md --- README.md | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ffa4418..e029449 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ This is a CLJS translation of the "Hello World Minimal Sample" for VSCode. Original repo: https://github.com/Microsoft/vscode-extension-samples/tree/master/helloworld-minimal-sample -# Installation +## Installation Clone this repo. Open the repo-folder in vscode (`File > Open`). @@ -27,6 +27,36 @@ Run the command by opening the command palette (`View > Command Palette...`), th Voila! +## Steps to utilize live reloading using shadow-cljs + +In the `extension.core` namespace we have a function called `activate`. In it we tell vscode to run a lambda function when the extension is activated. `activate` is only called once, so even if we edit the message and reload our code, we won't see any change. You can try this by doing the following: + +0. Be debugging (i.e. where you left off after following the Installation-steps) +1. In same terminal as before (that is, **not** in the debug instance of vscode): `shadow-cljs watch dev` +2. Make a change in the call to `showInformationMessage`, e.g. `(showInformationMessage "Hella World!")` +3. Run the command "Hello World" from the command palette again. + +You should see the same message as earlier. + +As we are clojurians, we love us some dynamic development environments. The step to fix this is simple! + +When you register the command, instead of registering a lambda, register a var instead! + +``` +(defn hella-world [] (.. vscode.window (showInformationMessage "Hella World!"))) + +(.. vscode.commands + (registerCommand + "extension.helloWorld" + #'hella-world)) +``` + +Then save, and click the green `Restart`-symbol in the debugging interface (the one with the pause-button etc). Or if you can't find it, just stop debugging and start it again. + +Now you can make changes to `hella-world`, and those changes will be available in the debugging instance of vscode. Try it out by changing the message to something less profane, and run the command "Hello World" again! :) Make sure that your project compiles properly, you see this by looking in the terminal, where shadow-cljs is nice enough to tell you when something goes wrong. + +Enjoy! + ## Thanks -Thanks to [sogaiu](https://github.com/sogaiu) for helping me getting started with CLJS. :) \ No newline at end of file +Thanks to [sogaiu](https://github.com/sogaiu) for helping me getting started with CLJS. :) From 95b9efe9f035f74ffb522e9fe5866ca5bcdf3028 Mon Sep 17 00:00:00 2001 From: Saikyun Date: Tue, 9 Apr 2019 13:11:52 +0200 Subject: [PATCH 2/5] Update README.md --- README.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e029449..d741e5d 100644 --- a/README.md +++ b/README.md @@ -42,16 +42,35 @@ As we are clojurians, we love us some dynamic development environments. The step When you register the command, instead of registering a lambda, register a var instead! +In `core.cljs`: + ``` (defn hella-world [] (.. vscode.window (showInformationMessage "Hella World!"))) +``` + +And modify the call to `registerCommand`: +``` (.. vscode.commands (registerCommand "extension.helloWorld" #'hella-world)) ``` -Then save, and click the green `Restart`-symbol in the debugging interface (the one with the pause-button etc). Or if you can't find it, just stop debugging and start it again. +We also need to remove the cached version of our script, add the following function as well: +``` +(defn reload [] (.log js/console "Reloading...") + (js-delete js/require.cache (js/require.resolve "./extension"))) +``` + +And in `shadow-cljs.edn`, add the following: +``` +:builds + {:dev {... + :devtools {:after-load extension.core/reload}}}} +``` + +After saving both files, click the green `Restart`-symbol in the debugging interface (the one with the pause-button etc). Or if you can't find it, just stop debugging and start it again. Now you can make changes to `hella-world`, and those changes will be available in the debugging instance of vscode. Try it out by changing the message to something less profane, and run the command "Hello World" again! :) Make sure that your project compiles properly, you see this by looking in the terminal, where shadow-cljs is nice enough to tell you when something goes wrong. From 8eef77b20264201bcf049d239513e25405f15c3b Mon Sep 17 00:00:00 2001 From: Saikyun Date: Tue, 9 Apr 2019 13:12:22 +0200 Subject: [PATCH 3/5] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d741e5d..84fa751 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,9 @@ And in `shadow-cljs.edn`, add the following: After saving both files, click the green `Restart`-symbol in the debugging interface (the one with the pause-button etc). Or if you can't find it, just stop debugging and start it again. -Now you can make changes to `hella-world`, and those changes will be available in the debugging instance of vscode. Try it out by changing the message to something less profane, and run the command "Hello World" again! :) Make sure that your project compiles properly, you see this by looking in the terminal, where shadow-cljs is nice enough to tell you when something goes wrong. +Now you can make changes to `hella-world`, and those changes will be available in the debugging instance of vscode. Try it out by changing the message to something less profane, and run the command "Hello World" again! :) + +Make sure that your project compiles properly, you see this by looking in the terminal, where shadow-cljs is nice enough to tell you when something goes wrong. Enjoy! From 4dc703bb8bbbb90e23b051ac9b02cf8627d9b659 Mon Sep 17 00:00:00 2001 From: Saikyun Date: Tue, 9 Apr 2019 13:16:06 +0200 Subject: [PATCH 4/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 84fa751..4be3568 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ The `package.json` already contains the dependencies, but I wanted you to do thi Compile:\ `shadow-cljs compile dev` -Start debugging (`Debug > Start Debugging`). +Start debugging (`Debug > Start Debugging`) if you're asked, select "Node.js" as environment. Run the command by opening the command palette (`View > Command Palette...`), then write "Hello World" and press Enter. From daec63115e3c95de7aa9b5544a79f1c35ab9473a Mon Sep 17 00:00:00 2001 From: Saikyun Date: Tue, 9 Apr 2019 13:16:46 +0200 Subject: [PATCH 5/5] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 4be3568..50fc5b0 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,9 @@ And it's dependencies:\ The `package.json` already contains the dependencies, but I wanted you to do this step, in case you later decide to create a new extension! +Fetch the other dependencies:\ +`npm install` + Compile:\ `shadow-cljs compile dev`