Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Ultra to pretty-print values by default when initializing a REPL using lein repl :connect #29

Closed
venantius opened this issue Apr 4, 2015 · 3 comments
Assignees
Labels

Comments

@venantius
Copy link
Owner

At the moment the pretty-printing middleware is activated when initializing a new REPL, no problem, but if you're connecting to an existing nREPL server that wasn't started with lein repl you may be out of luck. It would be nice to figure out a way around this.

@venantius venantius added the REPL label Apr 4, 2015
@venantius venantius self-assigned this Apr 4, 2015
@danielytics
Copy link

I guess this is because the middleware must be supplied on the nrepl server and lein repl :connect does not start a server. I tested connecting to a server started with lein repl with ultra added and the client I connected seems to pretty print just fine.

I looked at this because I'm manually embedding an nREPL server using clojure.tools.nrepl.server/start-server. You can set a custom handler using the :handler parameter and that the default handler can optionally apply middleware. So I could start my server like this:

(clojure.tools.nrepl.server/start-server
  :port 6789
  :handler (clojure.tools.nrepl.server/default-handler custom-middleware-fn))

So, my question is: is there a way for me to grammatically access ultra's nREPL middleware so that I can add it to my embedded server?

I'm not familiar with leiningen plugins, so don't know if I can just include it as a dependency and pull it out of some var or call some function to generate it.

@venantius
Copy link
Owner Author

You're right - I knew this at one point in time and then forgot it and subsequently created this issue 😛

Re: middleware: you can, and you actually don't need to use Ultra to do it (though you can if you like). The middleware that needs to be included server-side is the Whidbey middleware, which is what Ultra uses for pretty-printing values. The relevant blocks of code in Ultra can be found here (https://github.com/venantius/ultra/blob/master/src/ultra/repl/whidbey.clj#L7) and here (https://github.com/venantius/ultra/blob/master/src/ultra/repl.clj#L23) (side note, I hadn't looked at those namespaces in a while but there's a rather ugly circular dependency I'm working around that could easily be circumvented and which I should probably create an issue for).

Anyways, the middleware you want is is in clojure.tools.nrepl.middleware.render-values/render-values, which is a Whidbey ns (it looks like it's from clojure.tools.nrepl, but it's not). Ultra modifies the start-server function to just do a partial in case the user wants to layer additional middleware on top of that.

@danielytics
Copy link

Thanks!

On Sun, 17 May 2015 02:03 Ursa americanus kermodei notifications@github.com
wrote:

Closed #29 #29.


Reply to this email directly or view it on GitHub
#29 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants