-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
joyride_api.cljs
62 lines (53 loc) · 2.06 KB
/
joyride_api.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
(ns joyride-api
(:require ["vscode" :as vscode]
["ext://betterthantomorrow.joyride" :as joy-api]
[promesa.core :as p]
[joyride.core :as joyride]))
(def joyrideExt (vscode/extensions.getExtension "betterthantomorrow.joyride"))
(comment
;; Starting the nREPL server
(-> (joy-api/startNReplServer)
(p/catch (fn [e] (println (.-message e) e))))
;; (Oh, yes, it's already started, of course.)
;; Try first stopping the server? That will not help,
;; because you also need to disconnect from it before
;; it is stopped for real.
)
(comment
;; Getting contexts
(joy-api/getContextValue "joyride.isNReplServerRunning")
;; Non-Joyride context keys returns `nil`
(joy-api/getContextValue "foo.bar")
;; NB: Use the extension instance for this!
(joy-api/getContextValue "joyride.isActive")
;; Like so:
(.-isActive joyrideExt)
;; (Not that it matters, you can't deactivate Joyride,
;; and you can't talk to a deactivated REPL server.)
)
(comment
;; Joyride scripts can also reach the Joyride extension
;; through `joyride.core`
(-> (joyride/extension-context)
.-extension
.-exports)
(require '[clojure.repl :refer [doc]])
(doc joyride/extension-context))
;; in addition to the extension context, joyride.core also has:
;; * *file* - the absolute path of the file where an
;; evaluation takes place
;; * invoked-script - the absolute path of a script being run
;; `nil` in other execution contexts
;; * output-channel - Joyride's output channel
(doto (joyride/output-channel)
(.show true)
(.append "Writing to the ")
(.appendLine "Joyride output channel.")
(.appendLine (str "Joyride extension path: "
(-> (joyride/extension-context)
.-extension
.-extensionPath)))
(.appendLine (str "joyride/*file*: " joyride/*file*))
(.appendLine (str "Invoked script: " (joyride/invoked-script)))
(.appendLine "🎉"))
;; Try both invoking this file as a script, and loading it in the REPL