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

Add support for nREPL 0.6.0 #28

Merged
merged 2 commits into from Mar 1, 2019
Merged

Conversation

cichli
Copy link
Contributor

@cichli cichli commented Feb 16, 2019

nREPL now has the set!-able dynamic var nrepl.middleware.print/*print-fn* so tools like Whidbey can set a session-wide default printer, but clients can still override this on a per-request basis by including the relevant option in the request.

To be able to set! this, we need to switch from using :init to :custom-init. The former is evaluated only once when the REPL server starts, but the latter is evaluated each time a new client session is created (with set!-able bindings in place).

I have left the :nrepl-context code in place so nREPL 0.5.x still works.

Additionally, because of technomancy/leiningen#878, there's a bit of a sharp edge around using :init or :custom-init – they aren't merged in the way you might expect. Instead splice any existing form into our init code and overwrite the existing configuration with ^:replace.

Fixes #27.

@greglook greglook self-assigned this Feb 20, 2019
Copy link
Owner

@greglook greglook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for migrating this to use the new printing middleware. A couple comments, but the approach looks good. I like the fix for #21 as well. 👍

I gave this a shot with leiningen 2.9.0 and can confirm that it pretty-prints now, but I also note that it's printing an additional newline that wasn't present before. render-str was returning newline-trimmed strings, whereas pprint output has a trailing newline.

([value writer]
(render value writer nil))
([value writer opts]
(binding [*out* writer]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the comments you added in nrepl/nrepl#118 it seems like this is the undesirable interleaved-output pattern, right? I checked fipp briefly and it looks like usage of *out* is pretty baked in here, so I don't know that it can be easily remedied.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, exactly. See brandonbloom/fipp#56 – that adds an explicit :writer option.

@@ -78,6 +95,7 @@
(defn init!
"Initializes the repl to use Whidbey's customizations."
[options]
(update-print-fn!)
(update-options! options)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is run on each new nREPL session now, does that mean that reconnecting to the repl would update your whidbey options? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hadn't thought of this. I've pushed a new version that still uses :init for the Whidbey options. Maybe it makes sense to change those to a set!-able dynamic var so they can be per-session, but it needn't be in this PR.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the way it is now works - I wouldn't want two users connecting to the repl to fight over whose options are in effect.

johannesloetzsch added a commit to johannesloetzsch/ultra that referenced this pull request Feb 26, 2019
@greglook
Copy link
Owner

@cichli to be more explicit about next steps - I think this is mergeable, but I'd like to understand the answers to my two questions above. In particular, it'd be nice not to have the extra newline in the new approach, but if it turns out to be too difficult we can move forward with this.

@cichli
Copy link
Contributor Author

cichli commented Feb 27, 2019

Sorry for the delay in coming back to this @greglook. I've pushed a new version and addressed your inline comments above.

I gave this a shot with leiningen 2.9.0 and can confirm that it pretty-prints now, but I also note that it's printing an additional newline that wasn't present before. render-str was returning newline-trimmed strings, whereas pprint output has a trailing newline.

This is tricky (but not impossible) when nrepl.middleware.print/*stream?* is true, and I didn't want to introduce any difference in rendered output between setting that on or off. It's also possible that some *print-fn* adds whitespace at the end intentionally, so it might be surprising if it were all unconditionally trimmed. I wonder if this could be solved more naturally in the client? It only needs to add a newline before the prompt if the current line isn't blank.

* Set nrepl.middleware.print/*print-fn* accordingly if it is present.

* Add a comment noting that the :printer option only applies to nREPL 0.5.x.
Leiningen doesn't know how to merge these - see technomancy/leiningen#878.
Instead, use ^:replace metadata to overwrite it completely with a form that
evaluates any existing value before evaluating our init code.
@cichli
Copy link
Contributor Author

cichli commented Feb 27, 2019

Pushed again with a fix for find-ns pointed out by @johannesloetzsch.

@greglook
Copy link
Owner

greglook commented Mar 1, 2019

I wonder if this could be solved more naturally in the client? It only needs to add a newline before the prompt if the current line isn't blank.

Yeah, this feels like the right behavior to me. I'm thinking of the behavior of shells like zsh, which will render an extra newline before the prompt when needed. For now this can ship with some extra line spacing. 🤷‍♂️

Copy link
Owner

@greglook greglook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

@greglook greglook merged commit db37597 into greglook:master Mar 1, 2019
@cichli cichli deleted the nrepl-0.6.0 branch March 2, 2019 01:26
@cichli
Copy link
Contributor Author

cichli commented Mar 2, 2019

Thanks! 🙌

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

Successfully merging this pull request may close these issues.

None yet

2 participants