-
-
Notifications
You must be signed in to change notification settings - Fork 645
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
Allow predicates in plugin and middleware lists #2238
Conversation
@@ -358,17 +358,57 @@ specifying the artifact ID, and the second element the version number." | |||
(string :tag "Version")))) | |||
|
|||
(defvar cider-jack-in-lein-plugins nil | |||
"List of Leiningen plugins where elements are lists of artifact name and version.") | |||
"List of Leiningen plugins to be injected at jack-in. | |||
Each element is a list of artifact name and version, followed optionally by |
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.
I'm reasonably certain without some examples most people would be really confused what are they supposed to put here.
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.
@bbatsov Do you mean in terms of the format of the keyword arguments, or why you would want to use a predicate?
If the latter, I'm not sure that this is really meant to be an end-user feature. The only current application is in clj-refactor.el
, after all. But I would not at all be opposed to adding examples.
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.
I see. That makes sense, but it's exactly the kind of info that has to be documented. First I thought this might be something users would want to use in general or something.
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.
I guess the right solution would be just add some logic that removes those plugins from the deps if they are present there and add cider-nrepl
to the list of default deps where it belong. Then we stop using this variable for non lein projects.
cider.el
Outdated
(put 'cider-jack-in-lein-plugins 'risky-local-variable t) | ||
(cider-add-to-alist 'cider-jack-in-lein-plugins | ||
"cider/cider-nrepl" (upcase cider-version)) | ||
|
||
(defun cider-jack-in-lein-plugins () |
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.
Why isn't this function used anywhere?
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.
@bbatsov Because I forgot to update the places where cider-jack-in-lein-plugins
is used. If the approach seems reasonable, I'll go and fix that. The idea is just to take any place where the variable cider-jack-in-lein-plugins
is referenced, and replace the variable with a function call.
Btw, if you want some project-specific settings isn't |
@bbatsov Yes, but that doesn't work in the case of |
@bbatsov Aside from your comments, does this approach seem reasonable? If so, I'll go ahead and fix the remaining technical problems with this PR. |
Yeah, this seems reasonable. |
cider.el
Outdated
"Return a normalized list of Leiningen plugins to be injected. | ||
See `cider-jack-in-lein-plugins' for the format, except that the list | ||
returned by this function does not include keyword arguments." | ||
(mapcar |
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.
This seem like it can be made more readable (i.e. linear) w/ a thread-last
.
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.
@xiongtx Agreed, fixed.
cider.el
Outdated
returned by this function only contains strings." | ||
(mapcar | ||
(lambda (spec) | ||
(if (listp spec) |
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.
car-safe
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.
@xiongtx That would return nil if spec
is not a cons cell. I want to return spec
.
80bbf96
to
fe98548
Compare
@bbatsov All comments are addressed and tests are added. Thanks for your feedback. Also, thanks for such a nice test suite. It was actually fun to use :) |
("boot" (cider-boot-jack-in-dependencies | ||
global-opts | ||
params | ||
(cider-add-clojure-dependencies-maybe | ||
cider-jack-in-dependencies) | ||
cider-jack-in-lein-plugins | ||
cider-jack-in-nrepl-middlewares)) | ||
(cider-jack-in-normalized-lein-plugins) |
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.
I guess this is some odd legacy, but why are we passing lein plugins to boot? //cc @benedekfazekas
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.
because they are implemented as such (both cider-nrepl and refactor-nrepl). boot either has machinery to handle them or just handles them as ordinary deps.
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.
Yeah, I know why it was done. :-) I'm just saying it looks really strange to be passing something named lein-plugins to boot. For something like tools.deps and shadow-cljs the middleware packages would be regular deps.
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.
right. unfortunately lein needs them separately. this is unfortunately the smallest denominator in terms of interface. have not checked the details of this PR yet but I am sure this can be improved.
While you're at this - the hardcoded middleware here should be replaced with the new function you introduced https://github.com/clojure-emacs/cider/blob/master/cider.el#L159 |
And this has to be rebased on top of |
@bbatsov Regarding |
Yeah, that should work. Just test that it's working by jacking-in outside a project in with |
fe98548
to
f9bd359
Compare
@bbatsov Fixed, seems to be working. |
👍 |
This pull request is a follow-up to discussion on the
clj-refactor.el
issue tracker. Basically, the problem is thatclj-refactor.el
wants to inject Leiningen plugins and nREPL middleware, but only for REPLs within a project context. (If the middleware is injected outside a project context, then errors result.) Unfortunately, CIDER provides no way to changecider-jack-in-lein-plugins
orcider-jack-in-nrepl-middlewares
without using advice. This pull request adds support for including arbitrary attributes in those variables using keyword arguments. In particular, the:predicate
keyword allows for conditionally adding to those variables. I designed the interface with the idea of not breaking backwards compatibility and not making it hard to reverse the change later, if desired.I haven't gone through the checklist yet, since I'd first like feedback on whether this is a reasonable approach to the problem.
make test
)make lint
) which is based onelisp-lint
and includescheckdoc
, check-declare, packaging metadata, indentation, and trailing whitespace checks.