From 1c7c0dcc6d42b79917a51843e349811511e715a9 Mon Sep 17 00:00:00 2001 From: Andrea Richiardi Date: Wed, 27 Feb 2019 15:10:17 -0800 Subject: [PATCH 1/4] Bump the ClojureScript dependencies in project.clj --- project.clj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/project.clj b/project.clj index 13f91e6bf..a52ac8617 100644 --- a/project.clj +++ b/project.clj @@ -62,20 +62,20 @@ [leiningen-core "2.9.0"]]} :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"] From 38ec7898491734b21a49ff7dc9b9f2e61d9ccec8 Mon Sep 17 00:00:00 2001 From: Andrea Richiardi Date: Sun, 10 Feb 2019 12:43:40 -0800 Subject: [PATCH 2/4] [Fix #37] Move leftover code from the info middleware to orchard 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). It also moves calls to cljs-analysis to the ones in the orchard. Only completion is still done in cljs-tooling. --- README.md | 2 +- project.clj | 2 +- src/cider/nrepl/middleware/info.clj | 58 ++++++---------------- src/cider/nrepl/middleware/macroexpand.clj | 2 +- src/cider/nrepl/middleware/ns.clj | 13 ++--- src/cider/nrepl/middleware/stacktrace.clj | 2 +- 6 files changed, 25 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index 696de58de..47f7b2a3b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/project.clj b/project.clj index a52ac8617..fa61d4157 100644 --- a/project.clj +++ b/project.clj @@ -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 diff --git a/src/cider/nrepl/middleware/info.clj b/src/cider/nrepl/middleware/info.clj index f1c13c9ee..a95164b25 100644 --- a/src/cider/nrepl/middleware/info.clj +++ b/src/cider/nrepl/middleware/info.clj @@ -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) @@ -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") - ;; 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] diff --git a/src/cider/nrepl/middleware/macroexpand.clj b/src/cider/nrepl/middleware/macroexpand.clj index 5302f347b..27720aefe 100644 --- a/src/cider/nrepl/middleware/macroexpand.clj +++ b/src/cider/nrepl/middleware/macroexpand.clj @@ -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] diff --git a/src/cider/nrepl/middleware/ns.clj b/src/cider/nrepl/middleware/ns.clj index 89d01eaa4..45c0afc1e 100644 --- a/src/cider/nrepl/middleware/ns.clj +++ b/src/cider/nrepl/middleware/ns.clj @@ -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])) @@ -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) @@ -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] diff --git a/src/cider/nrepl/middleware/stacktrace.clj b/src/cider/nrepl/middleware/stacktrace.clj index 762c19246..513ec5469 100644 --- a/src/cider/nrepl/middleware/stacktrace.clj +++ b/src/cider/nrepl/middleware/stacktrace.clj @@ -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) From 7139d42a2e15fb36b7730c647608bca8d5e4df81 Mon Sep 17 00:00:00 2001 From: Andrea Richiardi Date: Wed, 27 Feb 2019 15:06:42 -0800 Subject: [PATCH 3/4] Use find for namespaces in cider.nrepl.middleware.debug Given that orchard now returns a namespace symbol instead of an object, we have to trigger a find-ns in the debug middleware instrumentation code. --- src/cider/nrepl/middleware/debug.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cider/nrepl/middleware/debug.clj b/src/cider/nrepl/middleware/debug.clj index 66d24577c..18f63c01f 100644 --- a/src/cider/nrepl/middleware/debug.clj +++ b/src/cider/nrepl/middleware/debug.clj @@ -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) From b02a8bd4fb8334c79405a11875d64e55a0cba78a Mon Sep 17 00:00:00 2001 From: Andrea Richiardi Date: Wed, 27 Feb 2019 15:11:21 -0800 Subject: [PATCH 4/4] Tweak the :test profile in order to test the new orchard code --- Makefile | 2 +- project.clj | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 5072464e7..83bc364e7 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/project.clj b/project.clj index fa61d4157..83f70a970 100644 --- a/project.clj +++ b/project.clj @@ -59,7 +59,8 @@ :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.10.520" :scope "provided"] @@ -80,7 +81,8 @@ :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