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

introduce cider-start-server command #3555

Merged
merged 22 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## master (unreleased)

### New Features

- Introduce `cider-start-nrepl-server` which does the same as `cider-jack-in` but without trying to connect to the started
nREPL server.

### Changes

- Bump the injected `cider-nrepl` to [0.42.0](https://github.com/clojure-emacs/cider-nrepl/blob/v0.42.0/CHANGELOG.md#0420-2023-10-30).
Expand Down
44 changes: 36 additions & 8 deletions cider.el
Original file line number Diff line number Diff line change
Expand Up @@ -1302,12 +1302,15 @@ nil."
(define-key map (kbd "j s") #'cider-jack-in-cljs)
(define-key map (kbd "j m") #'cider-jack-in-clj&cljs)
(define-key map (kbd "j u") #'cider-jack-in-universal)
(define-key map (kbd "j n") #'cider-start-nrepl-server)
(define-key map (kbd "C-j j") #'cider-jack-in-clj)
(define-key map (kbd "C-j s") #'cider-jack-in-cljs)
(define-key map (kbd "C-j n") #'cider-start-nrepl-server)
(define-key map (kbd "C-j m") #'cider-jack-in-clj&cljs)
(define-key map (kbd "C-j C-j") #'cider-jack-in-clj)
(define-key map (kbd "C-j C-s") #'cider-jack-in-cljs)
(define-key map (kbd "C-j C-m") #'cider-jack-in-clj&cljs)
(define-key map (kbd "C-j C-n") #'cider-start-nrepl-server)
(define-key map (kbd "c j") #'cider-connect-clj)
(define-key map (kbd "c s") #'cider-connect-cljs)
(define-key map (kbd "c m") #'cider-connect-clj&cljs)
Expand All @@ -1326,24 +1329,49 @@ nil."
map)
"CIDER jack-in and connect keymap.")

(defun cider--start-nrepl-server (params &optional on-port-callback)
"Starts an nrepl server and passes the callback to it.
PARAMS is a plist optionally containing :project-dir and :jack-in-cmd.
ON-PORT-CALLBACK is a function of one argument (server buffer)
which is called by the process filter once the port of the connection has
been determined. Can be nil."
behrica marked this conversation as resolved.
Show resolved Hide resolved
(nrepl-start-server-process
(plist-get params :project-dir)
(plist-get params :jack-in-cmd)
on-port-callback))


(defun cider--update-params (params)
"Completes the passed in PARAMS from user input.
Updates :project-dir, confirmation for existing session and :jack-in-cmd."
(thread-first
params
(cider--update-project-dir)
(cider--check-existing-session)
(cider--update-jack-in-cmd)))

;;;###autoload
(defun cider-jack-in-clj (params)
"Start an nREPL server for the current project and connect to it.
PARAMS is a plist optionally containing :project-dir and :jack-in-cmd.
With the prefix argument, allow editing of the jack in command; with a
double prefix prompt for all these parameters."
(interactive "P")
(let ((params (thread-first
params
(cider--update-project-dir)
(cider--check-existing-session)
(cider--update-jack-in-cmd))))
(nrepl-start-server-process
(plist-get params :project-dir)
(plist-get params :jack-in-cmd)
(let ((params (cider--update-params params)))
(cider--start-nrepl-server
params
(lambda (server-buffer)
(cider-connect-sibling-clj params server-buffer)))))


(defun cider-start-nrepl-server (params)
"Start an nREPL server for the current project, but don't connect to it.
PARAMS is a plist optionally containing :project-dir and :jack-in-cmd.
With the prefix argument, allow editing of the start server in command; with a
double prefix prompt for all these parameters."
(interactive "P")
(cider--start-nrepl-server (cider--update-params params)))

;;;###autoload
(defun cider-jack-in-cljs (params)
"Start an nREPL server for the current project and connect to it.
Expand Down
12 changes: 12 additions & 0 deletions doc/modules/ROOT/pages/basics/up_and_running.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,18 @@ Here is an example Nbb Jack-In command, providing a custom `:jack-in-cmd`.
(cider-jack-in-clj '(:jack-in-cmd "nbb nrepl-server")))
----

==== Starting nREPL server without trying to connect to it ====

In some situations, it might be useful to only start a nREPL server process, without
connecting to it. This can support complex setups
for which CIDER cannot reliably detect to which server/port to connect, and
would therefore fail.
This assumes that the user will execute a `cider-connect` command manually afterwards,
specifying host/port.

For this scenario, the `cider-start-nrepl-server` kbd:[j n] command is offered, which optionally
takes the same parameters as `cider-jack-in`.


== Connect to a Running nREPL Server

Expand Down
Loading