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

Recompute namespace info on each shadow-cljs recompilation or evaluation #3396

Merged
merged 2 commits into from
Aug 11, 2023

Conversation

vemv
Copy link
Member

@vemv vemv commented Aug 9, 2023

Fixes #3393

Works thanks to clojure-emacs/cider-nrepl#799

I tested this one locally.

The defcustoms are bit of a POC - feedback welcome. Initially I directly inlined the code, later I figured that it would pollute the main logic.

Cheers - V

@vemv vemv requested a review from bbatsov August 9, 2023 11:01
@bbatsov
Copy link
Member

bbatsov commented Aug 9, 2023

Generally, it's good to mention all hooks in the user docs as well.

cider-repl.el Outdated
(when (nrepl-op-supported-p "cider/get-state" conn)
(nrepl-send-request '("op" "cider/get-state") nil conn))))))

(defun cider--shadow-cljs-stderr-hook (buffer err)
Copy link
Member

Choose a reason for hiding this comment

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

The list of functions to call is called a "hook", not the functions in it.

cider-repl.el Outdated
"Refresh the changed namespaces metadata given BUFFER and ERR."
(cider--maybe-get-state-for-shadow-cljs buffer err))

(defun cider--shadow-cljs-done-hook (buffer)
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

cider-repl.el Outdated
"Refresh the changed namespaces metadata given BUFFER."
(cider--maybe-get-state-for-shadow-cljs buffer))

(defcustom cider-repl-stdout-hooks nil
Copy link
Member

Choose a reason for hiding this comment

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

hooks -> hook

Refer to other hooks in the codebase.

cider-repl.el Outdated
@@ -994,14 +1044,20 @@ nREPL ops, it may be convenient to prevent inserting a prompt.")
(lambda (buffer value)
(cider-repl-emit-result buffer value t))
(lambda (buffer out)
(dolist (f cider-repl-stdout-hooks)
Copy link
Member

Choose a reason for hiding this comment

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

You should see if you can use run-hooks here. I don't recall how it played for hooks with arguments.

Copy link
Member Author

Choose a reason for hiding this comment

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

run-hooks docstring says that no arguments will be passed.

In face of that, maybe we can refrain from using the hook terminology here?

e.g. defcustom cider-repl-stdout-callbacks/ defcustom cider-repl-stdout-functions.

(callbacks would seem more expressive to me here)

Copy link
Member

Choose a reason for hiding this comment

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

It depends on whether you expect users to actually do something here or not - if you do I'd stick with hooks, just because it's the established term in the community. If not you can just makes so defvars (perhaps private) and then the names won't matter as much.

Copy link
Member Author

@vemv vemv Aug 9, 2023

Choose a reason for hiding this comment

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

I'd be wary of creating 'hooks' that couldn't be run with run-hooks - could be confusing and imcompatible with other hook-related features.

Defvars make sense :) we can always promote them later.

@vemv
Copy link
Member Author

vemv commented Aug 9, 2023

Ready, QAed again as well.

@@ -996,12 +1034,16 @@ nREPL ops, it may be convenient to prevent inserting a prompt.")
(lambda (buffer out)
(cider-repl-emit-stdout buffer out))
(lambda (buffer err)
(dolist (f cider--repl-stderr-functions)
Copy link
Member

Choose a reason for hiding this comment

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

There's one more thing to consider here (for output in general and for values) - as this can be triggered a ton of times for something generating chunked output it can degrade performance significantly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Note that the guards are carefully ordered:

    (when (and (eq cider-repl-type 'cljs)
               (eq cider-cljs-repl-type 'shadow)
               (not cider-repl-cljs-upgrade-pending)
               (if err
                   (string-match-p "Build completed\\." err)
                 t))

no matter how large the output we're receiving is, for most cases we're not even inspecting it.

WIth that said, yesterday I created thheller/shadow-cljs#1139 which is going in a good direction. A few features could be built on top of it, and then this could be discarded.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, yeah - I'm aware of this. Just a point of concern, as we have to be careful about this. Hopefully we'll come up with a better solution down the road.

@bbatsov
Copy link
Member

bbatsov commented Aug 11, 2023

Looks good. Just rebase and squash before merging.

@vemv vemv merged commit 37de49a into master Aug 11, 2023
20 checks passed
@vemv vemv deleted the shadowthing branch August 11, 2023 09:44
vemv added a commit that referenced this pull request Aug 12, 2023
Similar to #3396, except that it's only necessary on recompilation - not on evaluations.
vemv added a commit that referenced this pull request Aug 12, 2023
Similar to #3396, except that it's only necessary on recompilation - not on evaluations.
vemv added a commit that referenced this pull request Aug 12, 2023
Similar to #3396, except that it's only necessary on recompilation - not on evaluations.
vemv added a commit that referenced this pull request Aug 18, 2023
Similar to #3396, except that it's only necessary on recompilation - not on evaluations.
vemv added a commit that referenced this pull request Aug 18, 2023
Similar to #3396, except that it's only necessary on recompilation - not on evaluations.
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.

ClojureScript dynamic font lock not working for new functions (var)
2 participants