Search code examples
clojurelighttablenrepl

Using Lighttable with remote nrepl


I want to start nREPL from code and let Lighttable connect to it. Here is my attempt:

(ns test
  (:require [clojure.tools.nrepl.server :refer [start-server default-handler]]
            [lighttable.nrepl.handler :refer [lighttable-ops]])
  (:gen-class))

(defn -main
  [& args]
  (start-server :port 8888
                :handler (default-handler lighttable-ops)))

However when I connect from Lighttable I get this:

Jun 19, 2014 5:30:23 PM clojure.tools.nrepl.server invoke0
SEVERE: Unhandled REPL handler exception processing message {:data {:settings {:name "localhost:8888", :remote true, :client-id 67}}, :id 67, :op client.init, :session c4f51394-135e-4579-b367-a69bdcdef15e}
java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.Atom
  at clojure.core$swap_BANG_.doInvoke(core.clj:2235)
  at clojure.lang.RestFn.invoke(RestFn.java:529)
  at lighttable.nrepl.handler$lighttable_ops$fn__6452.invoke(handler.clj:45)
  at clojure.tools.nrepl.middleware$wrap_conj_descriptor$fn__491.invoke(middleware.clj:17)
  at clojure.tools.nrepl.server$handle_STAR_.invoke(server.clj:18)
  at clojure.tools.nrepl.server$handle$fn__803.invoke(server.clj:27)
  at clojure.core$binding_conveyor_fn$fn__4145.invoke(core.clj:1910)
  at clojure.lang.AFn.call(AFn.java:18)
  at java.util.concurrent.FutureTask.run(FutureTask.java:262)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
  at java.lang.Thread.run(Thread.java:744)

dependencies I have:

[org.clojure/clojure "1.6.0"]
[org.clojure/tools.nrepl "0.2.3"]
[lein-light-nrepl "0.0.18"]

It works if I run lein repl, but I really need to distribute the code as a jar package.


Solution

  • Try using #'lighttable-ops instead of just lighttable-ops.

    I was able to reproduce the problem as you described, and this seemed to fix it.

    I'm not sure why the error only occurs in the compiled jar, but I suspect it is something to do with the aot compilation that goes on in the jar-making process.