cider icon indicating copy to clipboard operation
cider copied to clipboard

UX improvements for jacking in with additional aliases

Open matt-y opened this issue 2 years ago • 6 comments

Is your feature request related to a problem? Please describe.

Firstly this is an opinion that I hope is not taken in a negative way but as constructive feedback for cider. I'm a big fan of it. I appreciate your taking the time to read this.

Loading an additional alias such as :dev or :test when jacking in is a very common operation that in its current state I feel is overly difficult. Current solutions involve installing additional emacs packages such as dir-locals and providing a per-project configuration that is used every time to load additional aliases at jack-in time. Users are also able to use a prefix C-u when doing a jack-in to provide additional arguments: ``. This is not discoverable in the CIDER documentation on the web or inside emacs. If it indeed is documented, I apologize but I have failed at finding it. I have only found reference to the prefix usage in the issue tracker here on github, or deep in the clojurians slack. I myself have asked how to load an alias there!

Additionally, after jacking in and getting a repl going, loading an alias requires the repl be stopped and re-started with that alias loaded explicitly. Some kind of porcelain in front of these manual steps would be nice.

Some examples of users getting tripped up can be found below:

  • https://github.com/clojure-emacs/cider/issues/3123
  • https://github.com/clojure-emacs/cider/issues/2396

This trips a number of people up who are new to cider, myself included. It can be a little frustrating trying to figure out how to do this.

Describe the solution you'd like

I'd like to propose a new configuration option that will instruct the interactive cider-jack-in command to prompt the user to select additional aliases to load when doing a jack-in. Ideally, this configuration option (name tbd) will cause cider-jack-in to examine a user's deps.edn or leiningen project.clj (or etc) for additional aliases and explicitly prompt the user to select desired aliases to load in the minibuffer interactively.

I feel this is much better UX than a prefix or global configuration that may not be applicable to all projects, or installing dir-locals and then doing more configuration. Additionally, it would be opt-in and not disruptive to users. Cider documentation could call this out when instructing how to get up and running as well.

I'd also suggest this configuration option show this prompt when a user tells cider to restart a running repl.

Describe alternatives you've considered

Using dir-locals I do not feel is a good solution because it requires an additional emacs package. Additionally users may not wish to use the same dir-locals config every time a jack-in happens. Users should not have to install an additional package for this sort of thing.

Using cider-clojure-cli-global-options has a similar issue as a persistant dir-locals config in that it will load the same alias every time which may not be always desired. (For instance, this alias may not always exist or be differently named)

Using a prefix argument to cider-jack-in with the konami code emacs chord combo of C-u C-c C-x j j works, but requires secret knowledge that cider-jack-in takes a prefix that allows you to specify an alias, and it is a lot to remember.

All the above options do indeed solve the problem of loading an additional alias, but I feel strongly that it could be made much easier for users with some kind of porcelain such as an interactive prompt.

matt-y avatar Jan 31 '23 18:01 matt-y

Using dir-locals I do not feel is a good solution because it requires an additional emacs package.

dir-locals are actually built-in Emacs functionality. No extra packages required.

In general I get your point, but historically we've avoided adding options that are specific to particular tools, as that's a slippery slope. We already plan to remove even the global options, which were actually something kind of specific to Leiningen. So, my aim is to have fewer options here (basically the name of the executable and some command-line params for it).

Anyways, I'll keep this ticket open to see what others think about potential solution. I acknowledge that the clojure-cli is pretty popular these days and perhaps it makes some sense to provide some special support for its profiles.

bbatsov avatar Jan 31 '23 18:01 bbatsov

@bbatsov Thanks for the insight. There's always room for some custom elisp to be the glue for something like this rather than it being made part of CIDER itself and adding more tool-specific bells and whistles. Appreciate the consideration.

matt-y avatar Jan 31 '23 21:01 matt-y

This trips a number of people up who are new to cider, myself included.

FWIW, I can second this from my experience monitoring #cider over Clojurians Slack.

In general I get your point, but historically we've avoided adding options that are specific to particular tools

This seems a sensible limitation. Would it also apply to the existing cider-clojure-cli-aliases variable? Hopefully we wouldn't remove it, since being able to specify only the command-line params would be comparatively lower-level. Probably it would make mistakes easier.

So here's something I can think of:

if cider-clojure-cli-aliases is nil and we're using clojure, print the following to the minibuffer during the jack-in (or connect) process:

`cider-clojure-cli-aliases' was nil. Most likely you'd want to activate at least one alias. You can set it via the `custom-set-variables' or `.dir-locals' mechanism.

You can silence this message by setting `cider-clojure-cli-aliases' to `:nil-no-warn'.

This would be visible at least for a brief moment and would also be reflected in *Messages*, which should be a frequently visited place when troubleshooting.

And of course, we'd translate :nil-no-warn into nil.

WDYT?

vemv avatar Feb 01 '23 00:02 vemv

Would it also apply to the existing cider-clojure-cli-aliases variable?

Nope. It was meant to be middle-ground solution that doesn't require us to change the UI of CIDER jack-in. (e.g. to have specific prompts for aliases)

if cider-clojure-cli-aliases is nil and we're using clojure, print the following to the minibuffer during the jack-in (or connect) process:

I'd be OK with something like this. Perhaps we can also just prompt them for aliases at this point as it would be more or less the same thing in terms of complexity and better UX.

I also acknowledge that parsing the deps.edn is probably better and reduces the possibility for errors, but I think it will add a lot of complexity. If someone wants to tackle this, though - be my guest.

In general I'd be fine with anything that doesn't add additional configuration and is limitted to some form of prompting or inference of aliases when none are specified.

bbatsov avatar Feb 01 '23 07:02 bbatsov

Perhaps we can also just prompt them for aliases at this point as it would be more or less the same thing in terms of complexity and better UX.

I'd be fine with this. Maybe it's a bit invasive or comparatively complex, but in the end it's the UX that most people would want.

(Maybe it has the drawback that it makes it too easy to be 'lazy' and never configure .dir-locals.el!)

I agree that parsing deps.edn (and ~/.clojure/deps.edn) adds moving pieces. Surely with clojure-emacs/parseedn it's not that much of a big deal - and it could be wrapped with a try/catch to guard against unexpected nuances.

We can fallback to dev:test which would surely be perfectly fine for ~80% of projects.

vemv avatar Feb 02 '23 00:02 vemv

We already plan to remove even the global options, which were actually something kind of specific to Leiningen.

i know this might be a specific workflow issue, but i'm currently using both cider-clojure-cli-parameters and cider-clojure-cli-global-options, and they serve different purposes.

i use cider-clojure-cli-parameters to specify aliases with common libraries that i want to have on every REPL, such as adding aliases for clojure.data.{csv,json,xml}, Portal, Criterium, Tufte. so i have it set to something like "-A:data:portal:benchmark:profiler".

whilst on the other hand i'm working on a project where i need to set some specific clj-opts (which is how the manual for clojure calls it) -- more specifically -J options that'll be passed through to java_opts -- to connect to a proxy, and they need to be specified before -M. if i use cider-clojure-cli-parameters it always puts it after the -M and that simply does not work. i might be doing something wrong as well, so if you have a better way to specify clj-opts.

bigodel avatar Sep 19 '23 21:09 bigodel