From 73d7225d80e73930a447f0ccfb755fb34b29f158 Mon Sep 17 00:00:00 2001 From: Andrea Richiardi Date: Thu, 6 Feb 2020 18:24:36 -0800 Subject: [PATCH 1/2] Handle the user namespace for doc completions It seems like compliment is passing the 'user namespace to the doc function by default if the namespace is missing. This patch makes so that we check in both cljs.user and cljs.core (in this order) if that is the case. We check in cljs.core as well because that is were the doc for built-ins lives, rather than in cljs.user. --- .../suitable/compliment/sources/cljs.cljc | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/main/suitable/compliment/sources/cljs.cljc b/src/main/suitable/compliment/sources/cljs.cljc index 40574ca..1764bab 100644 --- a/src/main/suitable/compliment/sources/cljs.cljc +++ b/src/main/suitable/compliment/sources/cljs.cljc @@ -353,16 +353,29 @@ (defn doc [s ns] - (some-> - (cond - (plain-symbol? s) (let [ns-sym (or (some-> ns ns-name) 'cljs.core) - qualified-sym (symbol (str ns-sym) s)] - (or (ana/qualified-symbol-meta *compiler-env* qualified-sym) - (ana/macro-meta *compiler-env* qualified-sym))) - (nscl-symbol? s) (-> s symbol ana/ns-meta) - :else nil) - (not-empty) - (generate-docstring))) + (let [ns-sym (some-> ns ns-name)] + (some-> + (cond + ;; This is needed because compliment defaults to 'user in the absence of + ;; a ns. Additionally, in order to preserve the Clojure's behavior we + ;; try against cljs.core if nothing is found for cljs.user + (or (= ns-sym 'user) (= ns-sym 'cljs.user)) + (or (ana/qualified-symbol-meta *compiler-env* (symbol "cljs.user" s)) + (ana/macro-meta *compiler-env* (symbol "cljs.user" s)) + (ana/qualified-symbol-meta *compiler-env* (symbol "cljs.core" s)) + (ana/macro-meta *compiler-env* (symbol "cljs.core" s))) + + (plain-symbol? s) (let [ns-sym (cond + (nil? ns) 'cljs.core + (= ns 'user) 'cljs.user + :else (ns-name ns)) + qualified-sym (symbol (str ns-sym) s)] + (or (ana/qualified-symbol-meta *compiler-env* qualified-sym) + (ana/macro-meta *compiler-env* qualified-sym))) + (nscl-symbol? s) (-> s symbol ana/ns-meta) + :else nil) + (not-empty) + (generate-docstring)))) (defsource ::cljs-source :candidates #'candidates From 29515f61de0010c13cc846f8d63be24581b028b9 Mon Sep 17 00:00:00 2001 From: Andrea Richiardi Date: Thu, 6 Feb 2020 18:29:35 -0800 Subject: [PATCH 2/2] Make sure we return nil in macro-meta if things are missing. We always want to return nil because the main suitable.compliment.sources.cljs/doc function relies on that for trying alternatives. --- .../suitable/compliment/sources/cljs/analysis.cljc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/suitable/compliment/sources/cljs/analysis.cljc b/src/main/suitable/compliment/sources/cljs/analysis.cljc index 33d8aab..8140755 100644 --- a/src/main/suitable/compliment/sources/cljs/analysis.cljc +++ b/src/main/suitable/compliment/sources/cljs/analysis.cljc @@ -261,9 +261,9 @@ (defn macro-meta [env qualified-sym] - #?(:clj (var-meta (find-var qualified-sym)) + #?(:clj (some-> (find-var qualified-sym) var-meta) :cljs (let [referred-ns (symbol (namespace qualified-sym))] - (-> env - (ns-interns-from-env (add-ns-macros referred-ns)) - (get refer) - var-meta)))) + (some-> env + (ns-interns-from-env (add-ns-macros referred-ns)) + (get refer) + var-meta))))