-
-
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
Fix toggle connections #1920
Fix toggle connections #1920
Conversation
From the scratch buffer, we derive from clojure mode, which makes the eval architecture default to clj connections over cljs connections. Deriving from the -c mode allows us to dispatch a little easier to the first of (possibly) many connections.
Since now cljc buffer connections are determined by order, we can rotate the order to change which connection we are using.
I don't understand this. Our idea for
Hmm, I'll have to check. This function was intented to be used only in |
@bbatsov this actually wouldn't change that mechanism. Anytime something goes through One problem is that this seems to be very haphazard and needs some cleanup. For instance, load file and switch to namespace do this. However, |
And I misspoke in the earlier comment. It certainly does not introduce a new type of repl, it just recognizes a new type of buffer, a cljc one. In that case, when looking for the current cider connection, it just returns the first one, and then if you are mapping across connections, you should get the other one from |
Just to prove my point, notice the implementation of changing namespace:
and contrast with
This functionality does not map across connections, which is why there was a toggle connections in the first place. If we want to open an issue about this I can work on making this more uniform. And in that case, we would need to come up with a way to limit the connections seen by the scratch buffer. |
Yeah, this is a major problem that has to be fixed.
As I said - connection toggling was added mostly for the sake of the scratch buffers. I didn't expect that people would be using this to force the connection of a source buffer.
Absolutely. Although I don't think limiting the connections seen by the scratch buffer is that important. Maybe simply it can prompt for a connection to use when it's created. This would make everything so much simpler... |
Actually this is not true - now I remembered it was added as work-around for the difference in the eval commands behaviour and eventually I thought it might solve the problem with scratch buffers being Clojure only. The support for cljc in CIDER is truly a mess right now... |
@@ -224,6 +224,8 @@ such a link cannot be established automatically." | |||
(defun cider-connection-type-for-buffer () | |||
"Return the matching connection type (clj or cljs) for the current buffer." | |||
(cond | |||
;; cljc mode must be first as it derives from clj mode |
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.
Same applies for clojurescript-mode
. :-)
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.
clj mode -> clojure-mode
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.
cljc mode -> clojurec-mode
@@ -272,7 +274,12 @@ at all." | |||
(guessed-type (or type (cider-connection-type-for-buffer)))) | |||
;; So we have multiple connections. Look for the connection type we | |||
;; want, prioritizing the current project. | |||
(or (seq-find (lambda (conn) | |||
|
|||
;; when cljc buffer, use the first connection (you can rotate this |
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.
You forgot a closing paren here.
(setq-local cider-connections (list other-conn)) | ||
(user-error "No other connection available")))) | ||
(when-let ((conns (cider-connections))) | ||
(setq-local cider-connections (append (rest conns) (list (car conns)))) |
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 simply use cons
here.
(user-error "No other connection available")))) | ||
(when-let ((conns (cider-connections))) | ||
(setq-local cider-connections (append (rest conns) (list (car conns)))) | ||
(message "Repl type default set to: %s" (cider--connection-type (car (cider-connections)))))) |
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.
Repl -> Connection
cider-connections -> conns
(setq-local cider-connections (list other-conn)) | ||
(user-error "No other connection available")))) | ||
(when-let ((conns (cider-connections))) | ||
(setq-local cider-connections (append (rest conns) (list (car conns)))) |
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.
That's an odd change, btw - you need to make the other connection the default for this buffer (that's why the command is named toogle-connection
. Your change simply rotates the connection...
Looking more closely at the PR - I really don't think you can toggle between a clj and a matching cljs connection simply by reordering the connection list the way you've changed the implementation. You have to find the matching connection and place it first for this to make sense. And in general code that relies on the connection order is super brittle and hard to understand. Apart from assuming that first connection is the default/active/most recent/whatever connection, I'd try not to make more guesses about the nature of a connection from its position in a list - that's simply too opaque for people trying to understand the code. |
I think when I was making it I was assuming there were only connections for the particular project in the |
I guess my thinking is to set a buffer local var in cljc buffers of preferred type. And in |
This sounds reasonable. |
Alternatively the first time you evaluate something in a |
I think I like this, as when I was picking up Reagent, a cljs framework, loading namespaces caused errors in the clojure repl's and threw me off for quite a while. |
I think I want to separate |
Makes sense to me. |
This is obviously a failed first attempt. I'm gonna close it and think about it some more. I think the first step is tracking down every entrance to eval that CIDER provides and making sure they are all uniform. |
make test
)M-x checkdoc
warningsThanks!
issue 1913
This introduces a new "type" of cider repl, as returned from
cider-connection-type-for-buffer
. In addition to clj and cljs, we have cljc. This type will use the first connection incider-connections
. So we can easily reorder this list to change the default connection.Previously, since connections were inferred from what was available and what mode you were coming from, this toggle function would create a buffer local var for
cider-connections
and remove those connections. The problem was that you could not toggle them again as your list ran out of connections. This keeps all connections around and makes sure thatcider-map-connections
and others work well with multiple connections.