-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add user and workspace activate script functionality * Add workspace activate example Fixes #8
- Loading branch information
Showing
10 changed files
with
166 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
(ns activate | ||
(:require [joyride.core :as joyride] | ||
["vscode" :as vscode] | ||
[promesa.core :as p])) | ||
|
||
(println "Hello World, from Workspace activate.cljs script") | ||
|
||
(defonce !db (atom {:disposables []})) | ||
|
||
;; To make the activation script re-runnable we dispose of | ||
;; event handlers and such that we might have registered | ||
;; in previous runs. | ||
(defn- clear-disposables! [] | ||
(run! (fn [disposable] | ||
(.dispose disposable)) | ||
(:disposables @!db)) | ||
(swap! !db assoc :disposables [])) | ||
|
||
;; Pushing the disposables on the extension context's | ||
;; subscriptions will make VS Code dispose of them when the | ||
;; Joyride extension is deactivated. | ||
(defn- push-disposable [disposable] | ||
(swap! !db update :disposables conj disposable) | ||
(-> (joyride/get-extension-context) | ||
.-subscriptions | ||
(.push disposable))) | ||
|
||
(defn- my-main [] | ||
(clear-disposables!) | ||
(push-disposable | ||
;; It might surprise you to see how often and when this happens, | ||
;; and when it doesn't happen. | ||
(vscode/workspace.onDidOpenTextDocument | ||
(fn [doc] | ||
(println "[Joyride example]" | ||
(.-languageId doc) | ||
"document opened:" | ||
(.-fileName doc)))))) | ||
|
||
(when true | ||
(my-main)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(ns joyride.db) | ||
|
||
(defonce !app-db (atom {})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
(ns joyride.life-cycle | ||
(:require ["path" :as path] | ||
["vscode" :as vscode] | ||
[joyride.config :as conf] | ||
[joyride.utils :as utils] | ||
[promesa.core :as p])) | ||
|
||
(def user-init-script "activate.cljs") | ||
(def user-init-script-path (path/join conf/user-config-path | ||
conf/user-scripts-path | ||
user-init-script)) | ||
|
||
(def workspace-init-script "activate.cljs") | ||
(def workspace-init-script-path (path/join conf/workspace-scripts-path | ||
workspace-init-script)) | ||
(def workspace-init-script-abs-path (path/join vscode/workspace.rootPath | ||
workspace-init-script-path)) | ||
|
||
(def init-scripts {:user {:label "User activate" | ||
:script user-init-script | ||
:script-path user-init-script-path | ||
:script-abs-path user-init-script-path} | ||
:workspace {:label "Workspace activate" | ||
:script user-init-script | ||
:script-path workspace-init-script-path | ||
:script-abs-path workspace-init-script-abs-path}}) | ||
|
||
(defn maybe-run-init-script+ [run-fn {:keys [label script script-path script-abs-path]}] | ||
(utils/say (str label " script: " script-path)) | ||
(-> (utils/path-exists?+ script-abs-path) | ||
(p/then (fn [exists?] | ||
(if exists? | ||
(do | ||
(utils/say (str " Running...")) | ||
(run-fn script)) | ||
(utils/say (str " No " label " script present"))))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters