-
-
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
Support cider.clj-reload/reload ops #3624
Conversation
@vemv just to get the ball rolling, is this roughly what you had in mind? |
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.
Looks reasonable to me - thanks!
Btw have you seen this eldev error? It happens on build and test:
|
If anyone else comes across that error, reinstalling emacs from homebrew seemed to fix it. |
21e62e0
to
e707d10
Compare
@vemv was able to get a local dev env working, debugged the feature, and I believe this PR is ready to be reviewed. I left support for the clear operation, but will continue discussion of it in clojure-emacs/cider-nrepl#850 instead. |
@@ -148,6 +156,9 @@ namespace-qualified function of zero arity." | |||
(reloading | |||
(log-echo (format "Reloading %s\n" reloading) 'font-lock-string-face)) | |||
|
|||
(progress | |||
(log-echo progress 'font-lock-string-face)) |
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 progress
key is a passthrough of the logging cli-reload
outputs. It doesn't give you a list of files being reloaded per se, just logs as they are individually unloaded/reloaded. Examples:
cider-ns-refresh: Nothing to reload
cider-ns-refresh: Reloading successful
cider-ns-refresh: Unloading scratch.scratch
cider-ns-refresh: Loading scratch.scratch
cider-ns-refresh: Reloading successful
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 seems nice. However for large projects it might get excessively noisy?
I'd suggest a defcustom, default "no logging" (since one isn't debugging stuff by default)
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 can see how this can get very spammy if you're looking at the *messages*
buffer, and agree it should be good to prevent that spam.
I worry preventing it might be premature though... it is adding another customisation, and I imagine this feature might not have a lot of users for a while. Perhaps it could prove unnecessary.
I defer to your opinion though. I don't look at *messages*
a lot. Maybe spam there is a big issue.
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.
WRT the default of no logging, there's some tension there. Reloading, especially on larger projects, can take a while. Seeing the progress is helpful, and tools.namespace
not showing the progress is actually to its detriment.
So larger projects, which are the ones where the progress report would be more spammy, are also the ones that care more about the current progress.
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.
CIDER generally uses spinner
for progress indication needs.
(it's an item that popped up in a recent PR)
It could be added at some point. Please do not feel pressured to do so, but it's what I'd expect before the "spammy" default :)
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 spinner would be quite easy to add indeed. I agree that the extra logging should probably be optional (and maybe displayed in a standalone buffer one can quickly discard). Not a big deal at this stage, though.
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.
Btw, there's already cider-ns-refresh-show-log-buffer
, which I guess it makes sure to reuse if possible.
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.
And because we're already using log-echo
it seems we don't have to worry much about spamming Messages here:
(log-echo (message &optional face)
(log message face)
(unless cider-ns-refresh-show-log-buffer
(let ((message-truncate-lines t))
(message "cider-ns-refresh: %s" message))))
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 sorry, I'm not sure what the end result is here. Is it that I should add a spinner, or hat I shouldn't do anything since cider-ns-refresh-show-log-buffer
already exists?
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.
It seems to me you don't need to do anything, as those logs will end in the dedicated buffer (when enabled).
We can discuss the need for adding a spinner down the road.
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.
LGTM!
Please let's wait till the clear
op is there.
That also gives you the opportunity to QA the feature for a few days - I tend to suggest that as it can easily uncover the need for fixes/refinements.
Cheers - V
@@ -148,6 +156,9 @@ namespace-qualified function of zero arity." | |||
(reloading | |||
(log-echo (format "Reloading %s\n" reloading) 'font-lock-string-face)) | |||
|
|||
(progress | |||
(log-echo progress 'font-lock-string-face)) |
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 seems nice. However for large projects it might get excessively noisy?
I'd suggest a defcustom, default "no logging" (since one isn't debugging stuff by default)
cider-ns.el
Outdated
@@ -186,6 +197,19 @@ Its behavior is controlled by `cider-ns-save-files-on-refresh' and | |||
(file-in-directory-p buffer-file-name dir)) | |||
dirs))))))) | |||
|
|||
(defun cider-ns-refresh--refresh-op (op-name) |
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'd name this just cider-ns--refresh-op
. Although I'm not fully sold on the current approach, as I find it weird to use one set of ops as baseline instead of something more generic. Also - the "refresh" name comes from a function with this name in c.t.n.
.
I get that the current approach will likely result in the least amount of code changes, but I still want to think about this a bit more.
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 now like cider-ns--reload-op
even more, as I guess we'll move away from the "refresh" naming at some point. So maybe you can name the clj-reload
op names (sans the namespace) the "default" here and calculate the "refresh" ops in terms of them. Something like (cider-ns--reload-op 'reload)
.
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 I effected the changes as you indicated, but please let me know if understood it wrong.
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.
Yep, it did exactly what I had in mind.
@@ -130,6 +130,13 @@ and `cider-ns-reload-all` commands can be used instead. These commands | |||
invoke Clojure's `+(require ... :reload)+` and `+(require | |||
... :reload-all)+` commands at the REPL. | |||
|
|||
You can also use https://github.com/tonsky/clj-reload[clj-reload] instead: |
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.
Hmm, won't there be any configuration differences that should be noted here? The way it's written one would expect that changing the "refresh" tool will be mostly transparent action and I'm not sure that's really the case.
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.
Yes, please indicate that one should generally (reload/init {:dirs dirs})
and that cider won't do that for users
(I'm aware that that became optional, but that was a very recent change and easily a suboptimal one, based on t.n experience)
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 happy to describe how users should add the init first but I don't see why that would come up as a difference. I don't see any direct mention of the initialisation procedure for tools.namespace either, although it seems to be implied, but also not necessary.
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.
Another difference is that cider-ns-refresh-before-fn
and cider-ns-refresh-after-fn
are not used anymore, but cli-reload supports unload hooks on individual namespaces.
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 don't see any direct mention of the initialisation procedure for tools.namespace either,
I added
Lines 258 to 260 in 23540fd
(defun cider-ns-refresh (&optional mode) | |
"Reload modified and unloaded namespaces, using the Reloaded Workflow. | |
Uses the configured 'refresh dirs' \(defaults to the classpath dirs). |
Another difference is that cider-ns-refresh-before-fn and cider-ns-refresh-after-fn are not used anymore, but cli-reload supports unload hooks on individual namespaces.
We should pay attention to this. reset
ting a system is a fundamental step when working when any commercial app.
I'd suggest that it's discussed + tackled in a follow-up PR?
@filipesilva : following #3625 you may rebase master in to get cider-nrepl with your changes in 🎉 |
...and following #3627 you should should see jumping to the culprit file/line on errors. (No backend changes were needed at all) Please let us know if it works here as well. |
0b649de
to
ca1631d
Compare
cider-ns.el
Outdated
(const :tag "clj-reload https://github.com/tonsky/clj-reload" clj-reload)) | ||
:package-version '(cider . "1.13.1")) | ||
:package-version '(cider . "1.40.0")) |
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.
1.14.0 :-)
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.
Whoops, fixed!
@filipesilva : a very common .dir-locals.el is some variation of: ((nil . ((cider-ns-refresh-before-fn . "integrant.repl/suspend")
(cider-ns-refresh-after-fn . "integrant.repl/resume")
,,, So that reloaded changes can actually affect an app. I'd be OK with merging this asap but please confirm if you'd intend to further refine the solution |
Meanwhile I found a bug where reload-all isn't working because I passed the wrong option in cider-nrepl. I'm working on fixing it and making the tests more robust. |
clojure-emacs/cider-nrepl#854 is the fix for the reload-all op. |
I think this is just calling a function immediately before |
Thanks! While t.n supports an So yeah no upstream changes are required. |
I'm squash-merging this separately as we speak. Thanks much for your work @filipesilva ! |
It's in A melpa snapshot will be automatically created later today. We'll cut a stable release soon enough. Cheers - V |
Awesome, thank you so much! |
Just following up on the "reloaded changes can actually affect an app" case. I can verify I can add this fn in a given ns:
And it is running before/after the reload, both when I call reload manually and when I call it via cider. I just used it to restart a server in an app of mine I've moved to clj-reload. So clj-reload can handle this use case via its hooks. |
Thanks! Anyway, cider-ns-refresh-before-fn / cider-ns-refresh-after-fn are now supported, so it should work as well. |
The middleware interleaves responses such as |
See clojure-emacs/cider-nrepl#850 for more.
Notes:
Replace this placeholder text with a summary of the changes in your PR.
The more detailed you are, the better.
Before submitting the PR make sure the following things have been done (and denote this
by checking the relevant checkboxes):
eldev test
)eldev lint
) which is based onelisp-lint
and includescheckdoc
, check-declare, packaging metadata, indentation, and trailing whitespace checks.Thanks!
If you're just starting out to hack on CIDER you might find this section of its
manual extremely useful.