Skip to content

Commit

Permalink
Move leftover code from the info middleware to orchard
Browse files Browse the repository at this point in the history
This patch copies the leftover "business logic" from the `info` middleware to
the `orchard` `info` function. This will make the `info` function in `orchard`
self-contained, which is easier to test and more portable (one could use
`orchard` without the `nrepl` protocol for instance - say for a Language Server
Protocol implementation).
  • Loading branch information
arichiardi committed Feb 23, 2019
1 parent 1a804a2 commit 4ee0d0a
Showing 1 changed file with 15 additions and 41 deletions.
56 changes: 15 additions & 41 deletions src/cider/nrepl/middleware/info.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
(:require
[cider.nrepl.middleware.util.cljs :as cljs]
[cider.nrepl.middleware.util.error-handling :refer [with-safe-transport]]
[cljs-tooling.info :as cljs-info]
[clojure.java.io :as io]
[clojure.string :as str]
[orchard.eldoc :as eldoc]
[orchard.info :as clj-info]
[orchard.misc :as u]))
[orchard.misc :as orchard-misc]))

(declare format-response)

Expand Down Expand Up @@ -45,48 +44,23 @@
(clj-info/javadoc-info path)))
format-nested
blacklist
u/transform-value))))

(defn info-cljs
[env symbol ns]
(some-> (cljs-info/info env symbol ns)
(select-keys [:file :line :ns :doc :column :name :arglists])
(update
:file
(fn [f]
(if (u/boot-project?)
;; Boot stores files in a temporary directory & ClojureScript
;; stores the :file metadata location absolutely instead of
;; relatively to the classpath. This means when doing jump to
;; source in Boot & ClojureScript, you end up at the temp file.
;; This code attempts to find the classpath-relative location
;; of the file, so that it can be opened correctly.
(let [path (java.nio.file.Paths/get f (into-array String []))
path-count (.getNameCount path)]
(or
(first
(sequence
(comp (map #(.subpath path % path-count))
(map str)
(filter io/resource))
(range path-count)))
f))
f)))))
orchard-misc/transform-value))))

(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)
var-info)))))
(let [[ns symbol class member] (map orchard-misc/as-sym [ns symbol class member])
env (cljs/grab-cljs-env msg)
info-params (merge {:dialect :clj
:ns ns
:sym symbol}
(when env
{:env env
:dialect :cljs}))]
(cond
(and ns symbol) (clj-info/info info-params)
(and class member) (clj-info/info-java class member)
:else (throw (Exception.
"Either \"symbol\", or (\"class\", \"member\") must be supplied")))))

(defn info-reply
[msg]
Expand Down

0 comments on commit 4ee0d0a

Please sign in to comment.