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

Locate multiple ports for a single project #3234

Conversation

danmidwood
Copy link
Contributor

@danmidwood danmidwood commented Aug 4, 2022

Searching for a nrepl port to connect to would return a maximum of one
port per project, ignoring any others that you might want to connect
to. This creates a case where when connecting to a shadow-cljs nrepl
server the port is not presented to you as a completion when you
already have another nrepl server running.

This commit changes nrepl-extract-port to nrepl-extract-ports and the
return type from a single port to a list of ports (including nils
where a specific project type nrepl port file doesn't exist) to
provide the full view of nrepl servers that are available in the
project, and then the cider-locate-running-nrepl-ports fn is changed
to accommodate that.

This fixes #3140.

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):

  • The commits are consistent with our contribution guidelines
  • You've added tests (if possible) to cover your change(s)
  • All tests are passing (eldev test)
  • All code passes the linter (eldev lint) which is based on elisp-lint and includes
  • You've updated the changelog (if adding/changing user-visible functionality)
  • You've updated the user manual (if adding/changing user-visible functionality)

Thanks!

If you're just starting out to hack on CIDER you might find this section of its
manual
extremely useful.

(nrepl--port-from-file (expand-file-name ".nrepl-port" dir))
(nrepl--port-from-file (expand-file-name "target/repl-port" dir))
(nrepl--port-from-file (expand-file-name ".shadow-cljs/nrepl.port" dir))))
(defun nrepl-extract-ports (dir)
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 a public function, so renaming it would be a breaking change and we want to avoid those. You can just introduce a few function instead and perhaps mark the old function as obsolete.

nrepl-client.el Outdated
(nrepl--port-from-file (expand-file-name ".shadow-cljs/nrepl.port" dir))))
(defun nrepl-extract-ports (dir)
"Read ports from applicable repl-port files in directory DIR."
(list (nrepl--port-from-file (expand-file-name "repl-port" 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'd probably filter out the nil values here.

cider.el Outdated
(mapcar (lambda (d)
(when-let* ((ports (and d (nrepl-extract-ports (cider--file-path d)))))
(mapcar (lambda (p)
(when-let* ((p p))
Copy link
Member

Choose a reason for hiding this comment

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

If you apply the filter to the returned ports this when-let will become redundant and the code would read better.

@bbatsov
Copy link
Member

bbatsov commented Aug 4, 2022

Looks good to me overall. This need a changelog entry and perhaps we should explain somewhere in the user docs how CIDER finds nREPL ports automatically in a couple of sentences.

@bbatsov
Copy link
Member

bbatsov commented Aug 8, 2022

@danmidwood Ping :-)

@danmidwood
Copy link
Contributor Author

@danmidwood Ping :-)

I agree with all of the feedback, I will schedule some time this week to make the changes to the PR.

@danmidwood danmidwood force-pushed the autocomplete-for-multiple-project-ports-on-nrepl-connect branch 2 times, most recently from eae81ad to c1211bd Compare August 10, 2022 14:20
Searching for a nrepl port to connect to would return a maximum of one
port per project, ignoring any others that you might want to connect
to. This creates a case where when connecting to a shadow-cljs nrepl
server the port is not presented to you as a completion when you
already have another nrepl server running.

This commit changes nrepl-extract-port to nrepl-extract-ports and the
return type from a single port to a list of ports (including nils
where a specific project type nrepl port file doesn't exist) to
provide the full view of nrepl servers that are available in the
project, and then the cider-locate-running-nrepl-ports fn is changed
to accommodate that.

This fixes clojure-emacs#3140.
@danmidwood danmidwood force-pushed the autocomplete-for-multiple-project-ports-on-nrepl-connect branch from c1211bd to afc1296 Compare August 10, 2022 15:04
@danmidwood
Copy link
Contributor Author

@bbatsov I have made some changes as well as rebase on master. I marked nrepl-extract-port as obsolete and assumed version "1.4.2" would be the next one.

I didn't make any doc changes. I think the up_and_running.adoc is probably the place to do it but there's nothing there rendered out of date and I feel like adding more may make it more cumbersome.

I'm going to be away for a few weeks after this comment so if there's anything else to do then I will catch up with this when I'm back.

@bbatsov bbatsov merged commit 0f4887b into clojure-emacs:master Aug 10, 2022
@bbatsov
Copy link
Member

bbatsov commented Aug 10, 2022

Thanks!

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.

Auto detect multiple nrepl connection options, if they exist
2 participants