weavejester / lein-ring

Ring plugin for Leiningen
Eclipse Public License 1.0
501 stars 100 forks source link

Use nrepl options middleware #138

Closed worrel closed 9 years ago

worrel commented 10 years ago

Utilize :nrepl-middleware for Ring's nREPL

Makes 'lein ring server' honor :nrepl-middleware specified in :repl-options, optionally overriden directly in the :ring option map.

Possibly conflicts with #118 or might supercede it - I don't use Cider.

Example usage (with LightTable nREPL middleware):

;;project.clj

(defproject my-app "0.1.0-SNAPSHOT"
:ring {:handler my-app.core/handler
         :nrepl {:start? true
                 :nrepl-middleware [lighttable.nrepl.handler/lighttable-ops]}} ;; overrides below

;;or

:repl-options {:nrepl-middleware [lighttable.nrepl.handler/lighttable-ops]})
worrel commented 10 years ago

Also, addresses #87

weavejester commented 10 years ago

Added a few comments. Mostly superficial stuff.

worrel commented 10 years ago

Fixed up the formatting, the indentation change was LightTable's doing on smart re-indent - perhaps I have non-standard config? Version is back to 0.8.13.

worrel commented 10 years ago

Also fixed long commit message with rebase/amend/force push.

weavejester commented 9 years ago

That should be the last change needed. Then I can merge this PR.

MichaelBlume commented 9 years ago

This all looks solid to me and @weavejester's last concern seems to be addressed.

zarkone commented 9 years ago

Git version do not work for me:

java.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to clojure.lang.Named
 at clojure.core$namespace.invoke (core.clj:1526)
    leiningen.ring.server$load_namespaces$iter__3165__3169$fn__3170.invoke (server.clj:21)
...

Seems like It's because of 4b1b10b3545d2362383db5075c92f284b90cb943 from this PR -- I revert it back and lein-ring works again.

worrel commented 9 years ago

ugh, that'll teach me to not test a change :-(. @MichaelBlume @weavejester the issue with https://github.com/weavejester/lein-ring/commit/4b1b10b3545d2362383db5075c92f284b90cb943 is that (nrepl-middleware project) (correctly) returns a vector not an individual symbol. I don't see a really clean way to construct the input to load-namespaces while factoring in the fact that the nREPL namespaces are conditionally loaded. We can either go with the prior let/apply call (@zarkone 's fix does that), or drop the let and do

(apply load-namespaces
        (conj (into 
               ['ring.server.leiningen
                (if (nrepl? project) 'clojure.tools.nrepl.server)]
               (if (nrepl? project) (nrepl-middleware project)))
              (-> project :ring :handler)
              (-> project :ring :init)
              (-> project :ring :destroy))))))