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

Connection fixes #2458

Merged
merged 8 commits into from
Sep 23, 2018
Merged

Connection fixes #2458

merged 8 commits into from
Sep 23, 2018

Conversation

vspinu
Copy link
Contributor

@vspinu vspinu commented Sep 22, 2018

Fix most of the connection related issues except of #2447 for which the details are not yet clear, and #2446 which would re-quire a bit more of the design thinking.

(defun cider--get-reusable-repl-buffer (params)
"Find connection-less REPL buffer.
PARAMS is a plist as received by `cider-repl-create'. REPL with similar
connection PARAMS is proffered. Return nil if none such buffers exist."
Copy link
Member

Choose a reason for hiding this comment

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

preferred maybe?

(host (plist-get params :host))
(port (plist-get params :port))
(cljsp (string-match-p "cljs" (plist-get params :repl-type)))
(build-pred (lambda (&optional no-port no-host no-proj-dir)
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit puzzled here. Shouldn't we always try to reuse a repl matching the host and the project dir? I'm guessing you wrote the code like this to account for REPL without a project dir, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wrote it to account for possibility to to re-use the REPL even from a different project or host. First try to match all parameters, then all except port, then all except port host etc.

I have no specific preferences over how this should work and I don't think it's important. This one felt like the most flexible approach.

Copy link
Member

Choose a reason for hiding this comment

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

That's fine by me, but that should probably be documented somewhere in the manual as well, so people know what to expect.

(or no-proj-dir (equal proj-dir (plist-get bparams :project-dir)))
(or no-host (equal host (plist-get bparams :host)))
(or no-port (equal port (plist-get bparams :port))))))))
(repl (car (or
Copy link
Member

Choose a reason for hiding this comment

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

I think we should show the user a completing-read with all dead REPLs if there's more than one, instead of assuming they'll go with the best match in case of ambiguity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. This could be. But then one would need to sort the repls in the order of similarity.

Copy link
Member

Choose a reason for hiding this comment

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

I guess that'd be trivial - you just have to concatenate the lists you got from the consecutive filter invocations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All fixed. I went for explicit scoring - highest score for project, lower for host, lowest for port. Should do the trick.

(or no-port (equal port (plist-get bparams :port))))))))
(repl (car (or
(seq-filter (funcall build-pred) repls)
(seq-filter (funcall build-pred t) repls)
Copy link
Member

Choose a reason for hiding this comment

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

This code would be more readable with 6 t params in it. :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeh. I love those too ;)

(seq-filter (funcall build-pred t t) repls)
(seq-filter (funcall build-pred t t t) repls)))))
(and repl
(y-or-n-p (format "A dead REPL exists %s, reuse? " repl))
Copy link
Member

Choose a reason for hiding this comment

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

I think %s should go before the word exists.

@@ -887,6 +887,7 @@ nil."

;;; User Level Connectors

;;;###autoload (autoload 'cider-start-map "cider" "CIDER jack-in and connect keymap." t 'keymap)
Copy link
Member

Choose a reason for hiding this comment

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

I didn't even know this was possible. :-)

@bbatsov bbatsov merged commit 93f760d into clojure-emacs:master Sep 23, 2018
@bbatsov
Copy link
Member

bbatsov commented Sep 23, 2018

Great work!

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.

2 participants