Browse files

Now works with recent Leiningen 2 release

* Updated to mostly latest Leiningen 2 REPL code, doesn't support:
  * Headless mode
  * Connect to nREPL server mode
* Properly adds VimClojure server dependency (GitHub #8)
  • Loading branch information...
1 parent 41eb9a4 commit 71d25bcad2eb2b43a8dd5013ff48612b8eef5984 @sattvik committed Aug 26, 2012
Showing with 49 additions and 37 deletions.
  1. +3 −2 src/leiningen/vimclojure/deps.clj
  2. +46 −35 src/leiningen/vimclojure/repl/lein2.clj
View
5 src/leiningen/vimclojure/deps.clj
@@ -4,9 +4,10 @@
(:require [leinjacker.deps :as deps])
(:use [trammel.core :only [defconstrainedfn]]))
-(def ^{:private true
+(def ^{:internal true
:doc "The name of the VimClojure dependency."}
- vimclojure-spec ['vimclojure/server "2.3.6"])
+ vimclojure-spec ^:displace ['vimclojure/server "2.3.6"
+ :exclusions ['org.clojure/clojure]])
(defn has-vimclojure?
"Returns a value that evaluates to true if the project has a VimClojure
View
81 src/leiningen/vimclojure/repl/lein2.clj
@@ -2,30 +2,39 @@
"Runs the REPL in a Leiningen 2 project. The code here is largely derivative
of the code from `leiningen.repl`."
{:author "Daniel Solano Gómez"}
- (:require [clojure.tools.nrepl.ack :as nrepl.ack]
+ (:require [clojure.java.io :as io]
+ [clojure.tools.nrepl.ack :as nrepl.ack]
[leiningen.repl :as repl]
[leiningen.trampoline :as trampoline]
[leiningen.core.eval :as eval]
[leiningen.core.project :as project]
[leiningen.core.user :as user]
+ [leiningen.vimclojure.deps :as deps]
[leinjacker.utils :as utils]
[reply.main :as reply]
reply.exit)
(:use [trammel.core :only [defconstrainedfn]]))
+(def ^{:private true
+ :doc "A profile that contains the VimClojure server dependency."}
+ vimclojure-profile {:dependencies [deps/vimclojure-spec]})
+
(defconstrainedfn ^{:private true} start-server
"This a modified version of Lein 2’s `leiningen.repl/start-server` to
accomodate the VimClojure server. One particularly evil thing that I do here
is redefine `reply.exit/exit` so that it shuts down the VimClojure server.
Otherwise the process will just hang to my great annoyance. This seems to
only happen to plug-in projects."
- [project port ack-port vimclojure-host vimclojure-port with-server]
+ [project host port ack-port vimclojure-host vimclojure-port with-server]
[(or (map? project) (nil? project))
+ (string? host)
(integer? port)
(integer? ack-port)
(string? vimclojure-host)
(integer? vimclojure-port)]
- (let [server-starting-form
+ (let [handler-for @(resolve 'leiningen.repl/handler-for)
+ init-requires @(resolve 'leiningen.repl/init-requires)
+ server-starting-form
(with-server
`(fn [vimclojure#]
(when-let [exit-var# (try (resolve 'reply.exit/exit)
@@ -38,19 +47,22 @@
(catch Throwable _#))
(f#)))))
(let [server# (clojure.tools.nrepl.server/start-server
- :port ~port :ack-port ~ack-port)]
+ :bind ~host :port ~port :ack-port ~ack-port
+ :handler ~(handler-for project))
+ port# (-> server# deref :ss .getLocalPort)]
(println (str "Starting VimClojure server on "
~vimclojure-host ", " ~vimclojure-port))
(.start (Thread. vimclojure#))
- (println "nREPL server started on port"
- (-> server# deref :ss .getLocalPort))
- (while true (Thread/sleep Long/MAX_VALUE)))))]
+ (println "nREPL server started on port" port#)
+ (spit ~(str (io/file (:target-path project) "repl-port")) port#)
+ @(promise))))]
(if project
(eval/eval-in-project
- (project/merge-profiles project [(:repl (user/profiles) repl/profile)])
+ (project/merge-profiles project [(:repl (user/profiles) repl/profile)
+ repl/reply-profile
+ vimclojure-profile])
server-starting-form
- '(do (require 'clojure.tools.nrepl.server)
- (require 'complete.core)))
+ `(require ~@(init-requires project)))
(eval server-starting-form))))
(defconstrainedfn run
@@ -60,10 +72,14 @@
[(or (map? project) (nil? project))
(string? vimclojure-host)
(integer? vimclojure-port)]
- (let [repl-port @(resolve 'leiningen.repl/repl-port)]
+ (let [repl-port @(resolve 'leiningen.repl/repl-port)
+ repl-host @(resolve 'leiningen.repl/repl-host)
+ init-requires @(resolve 'leiningen.repl/init-requires)]
(if trampoline/*trampoline?*
(let [options (repl/options-for-reply project :port (repl-port project))
- profiles [(:repl (user/profiles) repl/profile) repl/trampoline-profile]]
+ profiles [(:repl (user/profiles) repl/profile)
+ repl/trampoline-profile
+ vimclojure-profile]]
(eval/eval-in-project
(project/merge-profiles project profiles)
(with-server
@@ -82,27 +98,22 @@
~vimclojure-port))
(.. (Thread. vimclojure#) start)
(reply.main/launch-nrepl ~options)))
- '(do
- (require 'reply.main)
- (require 'clojure.tools.nrepl.server)
- (require 'complete.core))))
- (do
+ `(require ~@(init-requires project 'reply.main))))
+ (let [prep-blocker @eval/prep-blocker]
(nrepl.ack/reset-ack-port!)
- (let [prepped (promise)]
- (.start
- (Thread.
- (bound-fn []
- (start-server (and project (vary-meta project assoc
- :prepped prepped))
- (repl-port project)
- (-> @repl/lein-repl-server deref :ss .getLocalPort)
- vimclojure-host
- vimclojure-port
- with-server))))
- (and project @prepped)
- (if-let [repl-port (nrepl.ack/wait-for-ack (or (-> project
- :repl-options
- :timeout)
- 30000))]
- (reply/launch-nrepl (repl/options-for-reply project :attach repl-port))
- (println "REPL server launch timed out.")))))))
+ (.start
+ (Thread.
+ (bound-fn []
+ (start-server project
+ (repl-host project)
+ (repl-port project)
+ (-> @repl/lein-repl-server deref :ss .getLocalPort)
+ vimclojure-host
+ vimclojure-port
+ with-server))))
+ (when project @prep-blocker)
+ (if-let [repl-port (nrepl.ack/wait-for-ack (-> project
+ :repl-options
+ (:timeout 30000)))]
+ (reply/launch-nrepl (repl/options-for-reply project :attach repl-port))
+ (println "REPL server launch timed out."))))))

0 comments on commit 71d25bc

Please sign in to comment.