clojure-emacs/cider-nrepl — pull request #140 by cichli (2014-12-21 19:45:21+00:00)
Title: Add option for custom cljs compiler env

See bhauman/lein-figwheel#59 for a bit more context on what this would enable. Basically, there are several new tools (figwheel, shadow-build, boot-reload, that I know of...) for cljs that fulfil a similar role - automatically compiling cljs on any file change, and reloading just the relevant changes in a connected web browser. This somewhat obviates the need for an actual REPL, and makes relying on Piggieback as the source of the cljs compiler environment somewhat troublesome from CIDER's perspective (as its compiler state does not update automatically to reflect what's been compiled by the build tool). I think in these situations, it would be okay to forgo the eval/load-file support from Piggieback but still have access to completion/doc lookup/the ns browser etc.

This is just a proposal of a possible implementation - the global var approach will presumably not be sufficient for multiple concurrent clients. Is this a situation we aim to support? (I'm not even sure if any of the cljs build tools that currently exist would behave well having multiple instances running on the same JVM, but this will likely change in the future).

One alternative solution would be to get the compiler environment from the current session by looking it up using some known key (e.g. `:cider.nrepl/cljs-compiler-env`), and create a separate middleware that allows injecting the compiler-env atom into the current session with this key. This is essentially what Piggieback does using the key `#'cemerick.piggieback/*cljs-repl-env*`. A user could then integrate the compiler state from the build tool of their choosing by configuring this middleware accordingly. I like how general this would be - it would be compatible with any build tool that exposed its cljs compiler state atom.

Another idea I'm toying with is creating a specialised `figwheel-nrepl` middleware (and some supporting elisp) that would integrate figwheel with CIDER, allowing for starting/stopping of the figwheel server, reporting of compiler errors/warnings in emacs itself, and ensuring middleware ops automatically use the compiler state from figwheel (presumably by injecting it into the session as suggested above).

Thoughts?