Created
November 18, 2018 04:55
-
-
Save kapilreddy/6923f310d00ed28b3d0cc667e2733963 to your computer and use it in GitHub Desktop.
Info middleware change to support protocol code navigation
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
(defn info | |
[{:keys [ns symbol class member] :as msg}] | |
(let [[ns symbol class member] (map u/as-sym [ns symbol class member])] | |
(if-let [cljs-env (cljs/grab-cljs-env msg)] | |
(info-cljs cljs-env symbol ns) | |
(let [var-info (cond (and ns symbol) (clj-info/info ns symbol) | |
(and class member) (clj-info/info-java class member) | |
:else (throw (Exception. | |
"Either \"symbol\", or (\"class\", \"member\") must be supplied"))) | |
;; we have to use the resolved (real) namespace and name here | |
see-also (clj-info/see-also (:ns var-info) (:name var-info))] | |
(if (seq see-also) | |
(merge {:see-also see-also} var-info) | |
(if-let [p (:protocol var-info)] | |
(let [proto (deref p) | |
x (filter #(extends? proto | |
%) | |
(filter #(class? %) | |
(map val (mapcat ns-imports (all-ns))))) | |
xs (map (fn [x] | |
(let [xs (clojure.string/split (pr-str x) | |
#"\.")] | |
(str (clojure.string/replace (clojure.string/join "." (drop-last xs)) | |
#"\_" | |
"-") | |
"/map->" | |
(last xs)))) | |
x)] | |
{:candidates (into {} | |
(map (fn [s] | |
[s (clj-info/info ns | |
(u/as-sym s))]) | |
xs))}) | |
var-info)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment