Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move leftover code from the info middleware to orchard #594

Merged
merged 4 commits into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ JAVA_VERSION = $(shell lein with-profile +sysutils \
inline-deps: .inline-deps

test: .inline-deps
lein with-profile +$(CLOJURE_VERSION),+plugin.mranderson/config test
lein with-profile +$(CLOJURE_VERSION),+test,+plugin.mranderson/config test

eastwood:
lein with-profile +$(CLOJURE_VERSION),+eastwood eastwood
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ Let's also acknowledge some of the projects leveraged by cider-nrepl:

* [orchard][] - extracted from `cider-nrepl`, so that non-nREPL clients can leverage the generic tooling functionality (like `inspect`, `apropos`, `var-info`, etc
* [compliment][] - for Clojure code completion
* [cljs-tooling][] - for ClojureScript code completion and var info
* [cljs-tooling][] - for ClojureScript code completion
* [tools.trace][] - for tracing
* [tools.namespace][] - for namespace reloading
* [cljfmt][] - for code formatting
Expand Down
16 changes: 9 additions & 7 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:url "http://www.eclipse.org/legal/epl-v10.html"}
:scm {:name "git" :url "https://github.com/clojure-emacs/cider-nrepl"}
:dependencies [[nrepl "0.6.0"]
^:inline-dep [cider/orchard "0.5.0-beta3"]
^:inline-dep [cider/orchard "0.5.0-beta4"]
^:inline-dep [thunknyc/profile "0.5.2"]
^:inline-dep [mvxcvi/puget "1.1.2"]
^:inline-dep [fipp "0.6.18"]; can be removed in unresolved-tree mode
Expand Down Expand Up @@ -59,28 +59,30 @@

:dev {:dependencies [[boot/base "2.8.3"]
[boot/core "2.8.3"]
[leiningen-core "2.9.0"]]}
[leiningen-core "2.9.0"]]
:global-vars {*assert* true}}

:1.8 {:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.8.51" :scope "provided"]
[org.clojure/clojurescript "1.10.520" :scope "provided"]
[javax.xml.bind/jaxb-api "2.3.1" :scope "provided"]]}
:1.9 {:dependencies [[org.clojure/clojure "1.9.0"]
[org.clojure/clojurescript "1.9.946" :scope "provided"]
[org.clojure/clojurescript "1.10.520" :scope "provided"]
[javax.xml.bind/jaxb-api "2.3.1" :scope "provided"]]
;; TODO: Merge the tests in this dir in to test/clj once we
;; drop support for Clojure 1.8
:test-paths ["test/spec"]}
:1.10 {:dependencies [[org.clojure/clojure "1.10.0"]
[org.clojure/clojurescript "1.10.63" :scope "provided"]]
[org.clojure/clojurescript "1.10.520" :scope "provided"]]
:test-paths ["test/spec"]}
:master {:repositories [["snapshots" "https://oss.sonatype.org/content/repositories/snapshots"]]
:dependencies [[org.clojure/clojure "1.11.0-master-SNAPSHOT"]
[org.clojure/clojurescript "1.10.516" :scope "provided"]]}
[org.clojure/clojurescript "1.10.520" :scope "provided"]]}

:test {:source-paths ["test/src"]
:java-source-paths ["test/java"]
:resource-paths ["test/resources"]
:dependencies [[cider/piggieback "0.4.0"]]}
:dependencies [[pjstadig/humane-test-output "0.9.0"]
[cider/piggieback "0.4.0"]]}

;; Need ^:repl because of: https://github.com/technomancy/leiningen/issues/2132
:repl ^:repl [:test
Expand Down
2 changes: 1 addition & 1 deletion src/cider/nrepl/middleware/debug.clj
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ this map (identified by a key), and will `dissoc` it afterwards."}
(when-not (::instrumented (meta v))
(when-let [{:keys [ns file form] :as var-meta} (m/var-code v)]
(let [full-path (misc/transform-value (:file (info/file-info file)))]
(binding [*ns* ns
(binding [*ns* (find-ns ns)
*file* file
*msg* (-> *msg*
(merge var-meta)
Expand Down
58 changes: 16 additions & 42 deletions src/cider/nrepl/middleware/info.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
(: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.info :as info]
[orchard.misc :as u]))

(declare format-response)
Expand Down Expand Up @@ -40,53 +39,28 @@
(when-let [forms (:forms info)]
{:forms-str (forms-join forms)})
(when-let [file (:file info)]
(clj-info/file-info file))
(info/file-info file))
(when-let [path (:javadoc info)]
(clj-info/javadoc-info path)))
(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 (System/getProperty "fake.class.path")
arichiardi marked this conversation as resolved.
Show resolved Hide resolved
;; 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)))))

(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 u/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) (info/info* info-params)
(and class member) (info/info-java class member)
:else (throw (Exception.
"Either \"symbol\", or (\"class\", \"member\") must be supplied")))))

(defn info-reply
[msg]
Expand Down
2 changes: 1 addition & 1 deletion src/cider/nrepl/middleware/macroexpand.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
(:require
[cider.nrepl.middleware.util.cljs :as cljs]
[cider.nrepl.middleware.util.error-handling :refer [with-safe-transport]]
[cljs-tooling.util.analysis :as cljs-ana]
[orchard.cljs.analysis :as cljs-ana]
[clojure.pprint :as pp]
[clojure.tools.reader :as reader]
[clojure.walk :as walk]
Expand Down
13 changes: 5 additions & 8 deletions src/cider/nrepl/middleware/ns.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
[cider.nrepl.middleware.util.coerce :as util.coerce]
[cider.nrepl.middleware.util.error-handling :refer [with-safe-transport]]
[cider.nrepl.middleware.util.meta :as um]
[cljs-tooling.info :as cljs-info]
[cljs-tooling.util.analysis :as cljs-analysis]
[orchard.info :as info]
[orchard.cljs.analysis :as cljs-analysis]
[orchard.misc :as u]
[orchard.namespace :as ns]
[orchard.query :as query]))
Expand Down Expand Up @@ -62,11 +62,6 @@
(u/update-keys name)
(into (sorted-map)))))

(defn ns-path-cljs [env ns]
(->> (symbol ns)
(cljs-info/info env)
(:file)))

(defn ns-list [{:keys [filter-regexps] :as msg}]
(if-let [cljs-env (cljs/grab-cljs-env msg)]
(ns-list-cljs cljs-env)
Expand All @@ -84,7 +79,9 @@

(defn ns-path [{:keys [ns] :as msg}]
(if-let [cljs-env (cljs/grab-cljs-env msg)]
(ns-path-cljs cljs-env ns)
(:file (info/info* {:dialect :cljs
:env cljs-env
:sym (symbol ns)}))
(.getPath (ns/canonical-source ns))))

(defn ns-list-reply [msg]
Expand Down
2 changes: 1 addition & 1 deletion src/cider/nrepl/middleware/stacktrace.clj
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
:fn (str/join "/" (cons fn anons))
:var (str ns "/" fn)
;; Full file path
:file-url (or (some-> (info/info 'user (symbol (str ns "/" fn)))
:file-url (or (some-> (info/info* {:ns 'user :sym (symbol ns fn)})
:file
path->url
u/transform-value)
Expand Down