diff --git a/CHANGELOG.md b/CHANGELOG.md index de706d07..eed1bbba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## master (unreleased) +### New features + +* [#766](https://github.com/clojure-emacs/cider-nrepl/issues/766) Complete local bindings for ClojureScript files. + ## 0.29.0 (2022-12-05) ### New features diff --git a/src/cider/nrepl/middleware/complete.clj b/src/cider/nrepl/middleware/complete.clj index 2ef65718..acd319be 100644 --- a/src/cider/nrepl/middleware/complete.clj +++ b/src/cider/nrepl/middleware/complete.clj @@ -36,7 +36,13 @@ (def cljs-sources "A list of ClojureScript completion sources for compliment." - [::suitable-sources/cljs-source]) + [::suitable-sources/cljs-source + ;; The local binding analysis done by + ;; :compliment.sources.local-bindings/local-bindings doesn't perform any + ;; evaluation or execution of the context form. Thus, it is independent of + ;; the actual host platform differences. Given that, we can use that same + ;; source for ClojureScript completion. + :compliment.sources.local-bindings/local-bindings]) (defn complete [{:keys [ns prefix symbol context extra-metadata enhanced-cljs-completion?] :as msg}] diff --git a/test/cljs/cider/nrepl/middleware/cljs_complete_test.clj b/test/cljs/cider/nrepl/middleware/cljs_complete_test.clj index b3694762..19f7a6a0 100644 --- a/test/cljs/cider/nrepl/middleware/cljs_complete_test.clj +++ b/test/cljs/cider/nrepl/middleware/cljs_complete_test.clj @@ -64,7 +64,18 @@ :ns "cljs.user" :prefix "js/Ob"}) candidates (:completions response)] - (is (empty? candidates))))) + (is (empty? candidates)))) + (testing "local bindings" + (let [response (session/message {:op "complete" + :ns "cljs.user" + :prefix "ba" + ;; Including `quux :quux` helps ensuring that only + ;; bindings with the specified prefix (ba*) will be + ;; suggested, instead of all the local bindings. + :context "(defn foo [bar] (let [baz :baz, quux :quux] (str __prefix__)))" + :enhanced-cljs-completion? "t"}) + candidates (:completions response)] + (is (= [{:candidate "bar", :type "local"}, {:candidate "baz", :type "local"}] candidates))))) (deftest cljs-complete-doc-test (testing "no suitable documentation can be found"