|
10 | 10 | [orchard.misc :as misc]
|
11 | 11 | [suitable.compliment.sources.cljs :as suitable-sources]))
|
12 | 12 |
|
13 |
| -;; TODO: Replace this with a presence check for shadow-cljs |
14 |
| -;; See https://github.com/rksm/clj-suitable/issues/15 for details |
15 |
| -(def suitable-enabled? (System/getProperty "cider.internal.test.cljs-suitable-enabled")) |
| 13 | +(def shadow-cljs-present? |
| 14 | + (try (require 'shadow.cljs.devtools.api) true |
| 15 | + (catch Throwable _ false))) |
16 | 16 |
|
17 |
| -(when suitable-enabled? |
18 |
| - (require 'suitable.complete-for-nrepl)) |
| 17 | +;; TODO: Suitable is currently broken for shadow-cljs |
| 18 | +;; See https://github.com/rksm/clj-suitable/issues/15 for details |
| 19 | +(def suitable-enabled? (not shadow-cljs-present?)) |
19 | 20 |
|
20 | 21 | (def suitable-complete-for-nrepl
|
21 | 22 | (when suitable-enabled?
|
| 23 | + (require 'suitable.complete-for-nrepl) |
22 | 24 | @(resolve 'suitable.complete-for-nrepl/complete-for-nrepl)))
|
23 | 25 |
|
24 | 26 | (def clj-sources
|
25 |
| - "Source keywords for Clojure completions." |
| 27 | + "A list of Clojure completion sources for compliment." |
26 | 28 | [:compliment.sources.special-forms/literals
|
27 | 29 | :compliment.sources.class-members/static-members
|
28 | 30 | :compliment.sources.ns-mappings/ns-mappings
|
|
34 | 36 | :compliment.sources.special-forms/special-forms])
|
35 | 37 |
|
36 | 38 | (def cljs-sources
|
37 |
| - "Source keywords for ClojureScript completions." |
| 39 | + "A list of ClojureScript completion sources for compliment." |
38 | 40 | [::suitable-sources/cljs-source])
|
39 | 41 |
|
40 | 42 | (defn complete
|
|
45 | 47 | :context context
|
46 | 48 | :extra-metadata (set (map keyword extra-metadata))}]
|
47 | 49 | (if-let [cljs-env (cljs/grab-cljs-env msg)]
|
| 50 | + ;; ClojureScript completion |
48 | 51 | (binding [suitable-sources/*compiler-env* cljs-env]
|
| 52 | + ;; First we get whatever candidates we can from the ClojureScript compiler source |
49 | 53 | (cond-> (complete/completions prefix (merge completion-opts {:sources cljs-sources}))
|
| 54 | + ;; and we optionally append to them dynamically obtained candidates |
| 55 | + ;; See https://github.com/rksm/clj-suitable#how-does-it-work for details |
50 | 56 | (and suitable-enabled? enhanced-cljs-completion?)
|
51 | 57 | (concat (suitable-complete-for-nrepl (assoc msg :symbol prefix)))))
|
| 58 | + ;; Clojure completion |
52 | 59 | (complete/completions prefix (merge completion-opts {:sources clj-sources})))))
|
53 | 60 |
|
54 | 61 | (defn completion-doc
|
|
0 commit comments