-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
add pprint #33
add pprint #33
Conversation
@kolharsam To be honest, I'm not sure what should happen, so I'm going to ask @bbatsov what is the idea of #18. Are clients going to pass in an option that they want to get results printed in a certain way? |
@borkdude I thought so since |
@kolharsam @bbatsov How does this work with nREPL on the JVM? Do you have an example of how this works over there? |
Keep in mind that the print functionality in nREPL is generic, meaning that pprint is just one possible printer, not some special case that has to be handled separately. The implementation here definitely seems to differ from what nREPL does. In your case probably you want to have |
It's described here in great detail https://nrepl.org/nrepl/0.8/design/middleware.html#pretty-printing Basically, the expectation is the desired printer function is available on the classpath (it will be auto-required if so). |
@bbatsov Thanks! Yeah, those docs are pretty great. What I meant was: are these also user-facing options? Or does |
Currently they are only meant to be passed via requests. Eventually there might be some defaults passed via the config/command-line, but that's not currently the case. |
@bbatsov So if I understand correctly, when a user invokes
So the babashka nrepl just has to check for this value and then do a lookup on supported print-functions, etc. It's starting to make sense I think. |
@borkdude are you suggesting that we do something similar here as well? That I feel would be ideal and a lot simpler to do. |
More like add those params to the
Yeah, more or less, that's what's needed.
It has to be similar at the request/response API level, otherwise babashka's nREPL won't work properly with existing Clojure clients. |
@kolharsam So to re-iterate. We should handle this within eval-msg. That function should not get an extra parameter, but we should inspect the message on the presence of a print middleware key, near here:
If the middleware key is present, we should resolve that function. I suggest that we do not use Clojure's If the middleware key is not present we default to The printing happens here:
|
Sounds very reasonable to me. |
@borkdude I have updated the PR; I'm not sure if I was able to follow your remarks correctly but please let me know how I can improve it. |
@kolharsam I added three comments. |
@borkdude I have updated the PR as per the previous review. |
I inspected the nREPL messages when calling
So the pprint function here is |
@kolharsam The tests are failing because you have to require 'clojure.pprint` first.
|
@borkdude should I be updating any tests for this? |
@kolharsam Yes, a test for this would be nice, but still waiting on @bbatsov input on: We don't know about a |
That would certainly be convenient for the users, but it's totally up to you. We can also ask them to configure the appropriate function manually themselves in CIDER's docs. Less configuration, doesn't hurt though. :-) |
@bbatsov So for convenience it would be ok to map |
Yep. The main reason for the wrapper is to expose the supported options via a parameter, as |
@bbatsov In this case it seems better to just copy over the cider pprint function and support also the |
"value" (pr-str value)}) opts) | ||
"value" (if nrepl-pprint | ||
(if-let [pprint-fn (get nrepl-pprint pretty-print-fns-map)] | ||
(pprint-fn value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kolharsam Note that clojure.pprint/pprint
prints to *out*
. To return a string we'll need to use with-out-str
here.
@Grazfather has offered to work on pt. 2 in a new PR to the pprint branch. Thanks so far @kolharsam |
WIP...to add the pprint option.