-
Notifications
You must be signed in to change notification settings - Fork 111
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
[Fix #391] Add option for disabling warnings #392
Conversation
8fa901c
to
506add8
Compare
I don't know why the build is failing, but it does not seem relevant to my change. |
clj-refactor.el
Outdated
(cons "refactor-nrepl.middleware/wrap-refactor" | ||
cider-jack-in-nrepl-middlewares))) | ||
(apply cider-jack-in args)) | ||
(apply cider-jack-in args))) |
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 do you prefer cons
over add-to-list
?
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 add-to-list
would modify the list variable globally, unless I let
-bound the variable to itself (which would be more complicated than just using cons
).
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 no harm in modifying these variables globally. Am I missing any edge cases 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.
If the variables were modified globally, then that would cause refactor-nrepl to be injected always, as opposed to just when you are inside a project. Avoiding that behavior is the whole point of this patch.
clj-refactor.el
Outdated
(add-to-list 'cider-jack-in-lein-plugins `("refactor-nrepl" ,(cljr--version t))) | ||
(add-to-list 'cider-jack-in-nrepl-middlewares "refactor-nrepl.middleware/wrap-refactor"))) | ||
(if (and (not (string-empty-p (cljr--project-dir))) | ||
cljr-inject-dependencies-at-jack-in) |
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.
keeping the boundp
checks on the cider vars make sense to make sure that the cider version installed is compatible with this feature... any particular reason you got rid of them?
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.
Oops, I was originally thinking we didn't need them since I switched from add-to-list
to let
+ cons
, but we still do since I use the original value. Fixing that now.
apart from the comments i am 👍 to merge this. build failure is weird indeed. perhaps something with |
506add8
to
9ee0521
Compare
clj-refactor.el
Outdated
|
||
;;;###autoload | ||
(eval-after-load 'cider | ||
'(cljr--inject-jack-in-dependencies)) | ||
'(advice-add #'cider-jack-in :around #'cljr--inject-jack-in-dependencies)) |
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 This seems like a no-no to me. What are you thoughts on using advice here?
For context, @raxod502 is submitting a patch so a variable will prevent the middleware dep from even being injected when we're outside a project. The reason being that the middleware will emit warnings that he doesn't care about.
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.
The reason I used advice here was that advice was already being used elsewhere; see:
clj-refactor.el/clj-refactor.el
Line 1638 in f5295df
(advice-add 'paredit-convolute-sexp :after #'clojure--replace-let-bindings-and-indent))) |
Note also that mutating a global variable in an autoload is not considered good practice either, so I don't think either the previous code or the new code is ideal.
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.
If you really don't want to use advice, I'll be happy to submit a pull request upstream for some additional customizable variables to be added so that doing this doesn't require advice.
clj-refactor.el
Outdated
@@ -155,6 +155,14 @@ as can be." | |||
:group 'cljr | |||
:type 'boolean) | |||
|
|||
(defcustom cljr-suppress-outside-project-warning nil |
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 think cljr-suppress-no-project-warning
might be a bit more self-explanatory.
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.
Good idea. Changed.
clj-refactor.el
Outdated
(defcustom cljr-suppress-outside-project-warning nil | ||
"If t, no warning is printed when starting a REPL outside a project. | ||
By default, a warning is printing in this case since clj-refactor | ||
will not work as expected in such REPLs and therefore the |
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.
Cut everything after "and therefore", as that last part only confuses things.
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.
Done.
9ee0521
to
dbf7f0c
Compare
Of course, we're still using my fork until [1] and [2] are merged. [1]: clojure-emacs/clj-refactor.el#392 [2]: clojure-emacs/clj-refactor.el#385
Any update here? |
We had another user requesting this recently :) I'd like to take you up on the offer to submit a PR to CIDER to avoid the use of advice. You're right that we have some advice for paredit, but if that advice goes stale, and breaks, everything else works fine, whereas if the advice for cider breaks down, due to changes upstream, we're likely to break both CIDER and clj-refactor for everyone. The changelog entry is also added in the wrong place (in the release notes for an already released version). That's on us, I guess, for not pushing a an 'Upcoming' section. Sorry about that. |
Indeed! |
I've created a pull request at clojure-emacs/cider#2238. Apologies for the delay in doing so. |
dbf7f0c
to
b88dd5b
Compare
I've also updated this pull request to use the |
clj-refactor.el
Outdated
@@ -155,6 +155,13 @@ as can be." | |||
:group 'cljr | |||
:type 'boolean) | |||
|
|||
(defcustom cljr-suppress-no-project-warning nil | |||
"If t, no warning is printed when starting a REPL outside a project. | |||
By default, a warning is printing in this case since clj-refactor |
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.
printing -> printed
@@ -786,6 +793,10 @@ A new record is created to define this constructor." | |||
car) | |||
"")) | |||
|
|||
(defun cljr--inside-project-p () |
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.
Think this should be called cljr--inject-middleware-p?
to better reflect its usage.
Also, shouldn't it have an argument list like (&rest _)
since it's actually expecting 3 arguments, that are ignored?
Edit: I see it's used in two places, so I'd suggest leaving this and creating another function, cljr--inject-middleware-p
that just has the right argument list and calls out to this one.
b88dd5b
to
51dda2f
Compare
Thanks, fixed. |
51dda2f
to
a15fef7
Compare
* Add `cljr-suppress-outside-project-warning' defcustom. * Use new `:predicate' support in `cider-jack-in-lein-plugins' and `cider-jack-in-nrepl-middlewares' to only inject when inside project context. (Bump CIDER dependency to 0.17.0.) * After REPL has started, if outside project context, display better warning than before (unless the new defcustom is set to non-nil).
@expez Now that the pull request for CIDER is functional and tested, I fixed a few things here and tested. Appears to be working. |
Great! 👍 |
@expez Well, the pull request has been merged upstream. Now we can look at this one :) |
Great work @raxod502! Thanks for seeing this through all the way! 👍 |
Add
cljr-suppress-outside-project-warning
defcustom. Setcider-lein-*
variables using advice-driven let-binding instead of global modification, and only inject nrepl-middleware when inside project context. After REPL has started, if outside project context, display more specific warning (unless the new defcustom is set to non-nil).cask exec emacs -batch -Q -L . -eval "(progn (setq byte-compile-error-on-warn t) (batch-byte-compile))" clj-refactor.el
)./run-tests.sh
)cljr-suppress-middleware-warnings
was not documented there