summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordpsutton <dpsutton@users.noreply.github.com>2017-01-22 19:27:23 -0600
committerBozhidar Batsov <bozhidar.batsov@gmail.com>2017-01-23 08:27:23 +0700
commitefe15912fa66c4f7547e223d3b7ed7142572e059 (patch)
tree1f36087df47ed39e837aea0a57146b46a1f9ae37
parent04e428ba4d1c2d446726fc77238a8fcd78903950 (diff)
Remove session from nrepl interaction (#1925)
Connection and session are inextricably linked. Rather than try to thread these two in lockstep throughout the whole request life cycle, we let the last step insert either the nrepl-session or the nrepl-tooling-session.
-rw-r--r--cider-client.el33
-rw-r--r--cider-inspector.el20
-rw-r--r--cider-interaction.el26
-rw-r--r--cider-test.el5
-rw-r--r--cider.el1
-rw-r--r--nrepl-client.el86
6 files changed, 70 insertions, 101 deletions
diff --git a/cider-client.el b/cider-client.el
index 3b1fbed8..f921af71 100644
--- a/cider-client.el
+++ b/cider-client.el
@@ -680,7 +680,6 @@ to be appended to the request message."
(cider-eval-spinner-handler connection callback)
callback)
connection
- (cider-current-session)
ns line column additional-params)
(cider-spinner-start connection)))
@@ -690,7 +689,6 @@ If NS is non-nil, include it in the request."
(nrepl-sync-request:eval
input
(cider-current-connection)
- (cider-current-session)
ns))
(defcustom cider-pprint-fn 'pprint
@@ -744,8 +742,8 @@ NS specifies the namespace in which to evaluate the request."
(nrepl-request:eval input
callback
(cider-current-connection)
- (cider-current-tooling-session)
- ns))
+ ns nil nil nil t ; tooling
+ ))
(defalias 'cider-current-repl-buffer #'cider-current-connection
"The current REPL buffer.
@@ -761,8 +759,7 @@ Return the REPL buffer given by `cider-current-connection'.")
(nrepl-request:interrupt
request-id
(cider-interrupt-handler (current-buffer))
- (cider-current-connection)
- (cider-current-session))))))
+ (cider-current-connection))))))
(defun cider-current-session ()
"Return the eval nREPL session id of the current connection."
@@ -855,9 +852,6 @@ loaded.
If CONNECTION is nil, use `cider-current-connection'.
If CALLBACK is nil, use `cider-load-file-handler'."
(cider-nrepl-send-request (list "op" "load-file"
- "session" (if connection
- (cider-session-for-connection connection)
- (cider-current-session))
"file" file-contents
"file-path" file-path
"file-name" file-name)
@@ -889,7 +883,6 @@ Optional arguments include SEARCH-NS, DOCS-P, PRIVATES-P, CASE-SENSITIVE-P."
(let* ((query (replace-regexp-in-string "[ \t]+" ".+" query))
(response (cider-nrepl-send-sync-request
`("op" "apropos"
- "session" ,(cider-current-session)
"ns" ,(cider-current-ns)
"query" ,query
,@(when search-ns `("search-ns" ,search-ns))
@@ -904,8 +897,7 @@ Optional arguments include SEARCH-NS, DOCS-P, PRIVATES-P, CASE-SENSITIVE-P."
(defun cider-sync-request:classpath ()
"Return a list of classpath entries."
(cider-ensure-op-supported "classpath")
- (thread-first (list "op" "classpath"
- "session" (cider-current-session))
+ (thread-first (list "op" "classpath")
(cider-nrepl-send-sync-request)
(nrepl-dict-get "classpath")))
@@ -913,7 +905,6 @@ Optional arguments include SEARCH-NS, DOCS-P, PRIVATES-P, CASE-SENSITIVE-P."
"Return a list of completions for STR using nREPL's \"complete\" op.
CONTEXT represents a completion context for compliment."
(when-let ((dict (thread-first (list "op" "complete"
- "session" (cider-current-session)
"ns" (cider-current-ns)
"symbol" str
"context" context)
@@ -923,7 +914,6 @@ CONTEXT represents a completion context for compliment."
(defun cider-sync-request:info (symbol &optional class member)
"Send \"info\" op with parameters SYMBOL or CLASS and MEMBER."
(let ((var-info (thread-first `("op" "info"
- "session" ,(cider-current-session)
"ns" ,(cider-current-ns)
,@(when symbol (list "symbol" symbol))
,@(when class (list "class" class))
@@ -936,7 +926,6 @@ CONTEXT represents a completion context for compliment."
(defun cider-sync-request:eldoc (symbol &optional class member)
"Send \"eldoc\" op with parameters SYMBOL or CLASS and MEMBER."
(when-let ((eldoc (thread-first `("op" "eldoc"
- "session" ,(cider-current-session)
"ns" ,(cider-current-ns)
,@(when symbol (list "symbol" symbol))
,@(when class (list "class" class))
@@ -949,15 +938,13 @@ CONTEXT represents a completion context for compliment."
(defun cider-sync-request:ns-list ()
"Get a list of the available namespaces."
(thread-first (list "op" "ns-list"
- "filter-regexps" cider-filtered-namespaces-regexps
- "session" (cider-current-session))
+ "filter-regexps" cider-filtered-namespaces-regexps)
(cider-nrepl-send-sync-request)
(nrepl-dict-get "ns-list")))
(defun cider-sync-request:ns-vars (ns)
"Get a list of the vars in NS."
(thread-first (list "op" "ns-vars"
- "session" (cider-current-session)
"ns" ns)
(cider-nrepl-send-sync-request)
(nrepl-dict-get "ns-vars")))
@@ -965,37 +952,32 @@ CONTEXT represents a completion context for compliment."
(defun cider-sync-request:ns-vars-with-meta (ns)
"Get a map of the vars in NS to its metadata information."
(thread-first (list "op" "ns-vars-with-meta"
- "session" (cider-current-session)
"ns" ns)
(cider-nrepl-send-sync-request)
(nrepl-dict-get "ns-vars-with-meta")))
(defun cider-sync-request:ns-load-all ()
"Load all project namespaces."
- (thread-first (list "op" "ns-load-all"
- "session" (cider-current-session))
+ (thread-first (list "op" "ns-load-all")
(cider-nrepl-send-sync-request)
(nrepl-dict-get "loaded-ns")))
(defun cider-sync-request:resource (name)
"Perform nREPL \"resource\" op with resource name NAME."
(thread-first (list "op" "resource"
- "session" (cider-current-session)
"name" name)
(cider-nrepl-send-sync-request)
(nrepl-dict-get "resource-path")))
(defun cider-sync-request:resources-list ()
"Return a list of all resources on the classpath."
- (thread-first (list "op" "resources-list"
- "session" (cider-current-session))
+ (thread-first (list "op" "resources-list")
(cider-nrepl-send-sync-request)
(nrepl-dict-get "resources-list")))
(defun cider-sync-request:format-code (code)
"Perform nREPL \"format-code\" op with CODE."
(thread-first (list "op" "format-code"
- "session" (cider-current-session)
"code" code)
(cider-nrepl-send-sync-request)
(nrepl-dict-get "formatted-code")))
@@ -1003,7 +985,6 @@ CONTEXT represents a completion context for compliment."
(defun cider-sync-request:format-edn (edn right-margin)
"Perform \"format-edn\" op with EDN and RIGHT-MARGIN."
(let* ((response (thread-first (list "op" "format-edn"
- "session" (cider-current-session)
"edn" edn)
(append (cider--nrepl-pprint-request-plist right-margin))
(cider-nrepl-send-sync-request)))
diff --git a/cider-inspector.el b/cider-inspector.el
index 2fefacdf..b173d21d 100644
--- a/cider-inspector.el
+++ b/cider-inspector.el
@@ -192,52 +192,46 @@ Current page will be reset to zero."
;; nREPL interactions
(defun cider-sync-request:inspect-pop ()
"Move one level up in the inspector stack."
- (thread-first (list "op" "inspect-pop"
- "session" (cider-current-session))
+ (thread-first (list "op" "inspect-pop")
(cider-nrepl-send-sync-request)
(nrepl-dict-get "value")))
(defun cider-sync-request:inspect-push (idx)
"Inspect the inside value specified by IDX."
(thread-first (list "op" "inspect-push"
- "idx" idx
- "session" (cider-current-session))
+ "idx" idx)
(cider-nrepl-send-sync-request)
(nrepl-dict-get "value")))
(defun cider-sync-request:inspect-refresh ()
"Re-render the currently inspected value."
- (thread-first (list "op" "inspect-refresh"
- "session" (cider-current-session))
+ (thread-first (list "op" "inspect-refresh")
(cider-nrepl-send-sync-request)
(nrepl-dict-get "value")))
(defun cider-sync-request:inspect-next-page ()
"Jump to the next page in paginated collection view."
- (thread-first (list "op" "inspect-next-page"
- "session" (cider-current-session))
+ (thread-first (list "op" "inspect-next-page")
(cider-nrepl-send-sync-request)
(nrepl-dict-get "value")))
(defun cider-sync-request:inspect-prev-page ()
"Jump to the previous page in paginated collection view."
- (thread-first (list "op" "inspect-prev-page"
- "session" (cider-current-session))
+ (thread-first (list "op" "inspect-prev-page")
(cider-nrepl-send-sync-request)
(nrepl-dict-get "value")))
(defun cider-sync-request:inspect-set-page-size (page-size)
"Set the page size in paginated view to PAGE-SIZE."
(thread-first (list "op" "inspect-set-page-size"
- "page-size" page-size
- "session" (cider-current-session))
+ "page-size" page-size)
(cider-nrepl-send-sync-request)
(nrepl-dict-get "value")))
(defun cider-sync-request:inspect-expr (expr ns page-size)
"Evaluate EXPR in context of NS and inspect its result.
Set the page size in paginated view to PAGE-SIZE."
- (thread-first (append (nrepl--eval-request expr (cider-current-session) ns)
+ (thread-first (append (nrepl--eval-request expr ns)
(list "inspect" "true"
"page-size" page-size))
(cider-nrepl-send-sync-request)
diff --git a/cider-interaction.el b/cider-interaction.el
index cc3ff4ff..b23b297e 100644
--- a/cider-interaction.el
+++ b/cider-interaction.el
@@ -878,7 +878,7 @@ into a new error buffer."
(let (causes)
(cider-nrepl-send-request
(append
- (list "op" "stacktrace" "session" (cider-current-session))
+ (list "op" "stacktrace")
(when (cider--pprint-fn)
(list "pprint-fn" (cider--pprint-fn)))
(when cider-stacktrace-print-length
@@ -1007,8 +1007,7 @@ evaluation command. Honor `cider-auto-jump-to-error'."
(with-current-buffer buffer
(nrepl-request:stdin (concat (read-from-minibuffer "Stdin: ") "\n")
(cider-stdin-handler buffer)
- (cider-current-connection)
- (cider-current-session))))
+ (cider-current-connection))))
(defun cider-emit-into-color-buffer (buffer value)
"Emit into color BUFFER the provided VALUE."
@@ -1375,7 +1374,6 @@ See `cider-mode'."
(defun cider-sync-request:toggle-trace-var (symbol)
"Toggle var tracing for SYMBOL."
(thread-first (list "op" "toggle-trace-var"
- "session" (cider-current-session)
"ns" (cider-current-ns)
"sym" symbol)
(cider-nrepl-send-sync-request)))
@@ -1405,7 +1403,6 @@ opposite of what that option dictates."
(defun cider-sync-request:toggle-trace-ns (ns)
"Toggle namespace tracing for NS."
(thread-first (list "op" "toggle-trace-ns"
- "session" (cider-current-session)
"ns" ns)
(cider-nrepl-send-sync-request)))
@@ -1437,7 +1434,6 @@ Defaults to the current ns. With prefix arg QUERY, prompts for a ns."
(lambda (sym)
(cider-nrepl-send-request
(list "op" "undef"
- "session" (cider-current-session)
"ns" (cider-current-ns)
"symbol" sym)
(cider-interactive-eval-handler (current-buffer))))))
@@ -1682,7 +1678,7 @@ START and END represent the region's boundaries."
(cider-ensure-connected)
(let ((selected-session (completing-read "Describe nREPL session: " (nrepl-sessions (cider-current-connection)))))
(when (and selected-session (not (equal selected-session "")))
- (let* ((session-info (nrepl-sync-request:describe (cider-current-connection) selected-session))
+ (let* ((session-info (nrepl-sync-request:describe (cider-current-connection)))
(ops (nrepl-dict-keys (nrepl-dict-get session-info "ops")))
(session-id (nrepl-dict-get session-info "session"))
(session-type (cond
@@ -1701,10 +1697,8 @@ START and END represent the region's boundaries."
"Close an nREPL session for the current connection."
(interactive)
(cider-ensure-connected)
- (let ((selected-session (completing-read "Close nREPL session: " (nrepl-sessions (cider-current-connection)))))
- (when selected-session
- (nrepl-sync-request:close (cider-current-connection) selected-session)
- (message "Closed nREPL session %s" selected-session))))
+ (nrepl-sync-request:close (cider-current-connection))
+ (message "Closed nREPL session"))
;;; quiting
(defun cider--close-buffer (buffer)
@@ -1716,10 +1710,8 @@ START and END represent the region's boundaries."
(when (or (not nrepl-server-buffer)
;; Sync request will hang if the server is dead.
(process-live-p (get-buffer-process nrepl-server-buffer)))
- (when nrepl-session
- (nrepl-sync-request:close buffer nrepl-session))
- (when nrepl-tooling-session
- (nrepl-sync-request:close buffer nrepl-tooling-session)))
+ (when nrepl-session or nrepl-tooling-session
+ (nrepl-sync-request:close buffer)))
(when proc (delete-process proc)))))
(kill-buffer buffer)))
@@ -1816,9 +1808,7 @@ With a prefix argument, prompt for function to run instead of -main."
(cider-ensure-connected)
(let ((name (or function "-main")))
(when-let ((response (cider-nrepl-send-sync-request
- (list "op" "ns-list-vars-by-name"
- "session" (cider-current-session)
- "name" name))))
+ (list "op" "ns-list-vars-by-name" "name" name))))
(if-let ((vars (split-string (substring (nrepl-dict-get response "var-list") 1 -1))))
(cider-interactive-eval
(if (= (length vars) 1)
diff --git a/cider-test.el b/cider-test.el
index 8aa7a4d2..e5b8570e 100644
--- a/cider-test.el
+++ b/cider-test.el
@@ -262,7 +262,7 @@ prompt and whether to use a new window. Similar to `cider-find-var'."
(let (causes)
(cider-nrepl-send-request
(append
- (list "op" "test-stacktrace" "session" (cider-current-session)
+ (list "op" "test-stacktrace"
"ns" ns "var" var "index" index)
(when (cider--pprint-fn)
(list "pprint-fn" (cider--pprint-fn)))
@@ -594,8 +594,7 @@ If SILENT is non-nil, suppress all messages other then test results."
"tests" (when (stringp ns) tests)
"load?" (when (or (stringp ns)
(eq :project ns))
- "true")
- "session" (cider-current-session))
+ "true"))
(lambda (response)
(nrepl-dbind-response response (summary results status out err)
(cond ((member "namespace-not-found" status)
diff --git a/cider.el b/cider.el
index fc645017..3adf9f17 100644
--- a/cider.el
+++ b/cider.el
@@ -456,7 +456,6 @@ should be the regular Clojure REPL started by the server process filter."
(cider-nrepl-send-request
(list "op" "eval"
"ns" (cider-current-ns)
- "session" nrepl-session
"code" cider-cljs-lein-repl)
(cider-repl-handler (current-buffer)))
(cider--offer-to-open-app-in-browser nrepl-server-buffer))))
diff --git a/nrepl-client.el b/nrepl-client.el
index 9588aa41..c5925dd9 100644
--- a/nrepl-client.el
+++ b/nrepl-client.el
@@ -674,7 +674,7 @@ eval requests for functionality like pretty-printing won't clobber the
values of *1, *2, etc."
(let* ((client-conn (process-buffer client))
(response-main (nrepl-sync-request:clone client-conn))
- (response-tooling (nrepl-sync-request:clone client-conn)))
+ (response-tooling (nrepl-sync-request:clone client-conn t))) ; t for tooling
(nrepl-dbind-response response-main (new-session err)
(if new-session
(with-current-buffer client-conn
@@ -792,16 +792,19 @@ corresponding type of response."
(with-current-buffer connection
(number-to-string (cl-incf nrepl-request-counter))))
-(defun nrepl-send-request (request callback connection)
+(defun nrepl-send-request (request callback connection &optional tooling)
"Send REQUEST and register response handler CALLBACK using CONNECTION.
REQUEST is a pair list of the form (\"op\" \"operation\" \"par1-name\"
\"par1\" ... ). See the code of `nrepl-request:clone',
-`nrepl-request:stdin', etc.
-Return the ID of the sent message."
+`nrepl-request:stdin', etc. This expects that the REQUEST does not have a
+session already in it. This code will add it as appropriate to prevent
+connection/session drift.
+Return the ID of the sent message.
+Optional argument TOOLING Set to t if desiring the tooling session rather than the standard session."
(with-current-buffer connection
- (when (and (not (lax-plist-get request "session"))
- nrepl-session)
- (setq request (append request (list "session" nrepl-session))))
+ (when-let ((session (if tooling nrepl-tooling-session nrepl-session)))
+ (setq request (append request
+ (list "session" session))))
(let* ((id (nrepl-next-request-id connection))
(request (cons 'dict (lax-plist-put request "id" id)))
(message (nrepl-bencode request)))
@@ -816,19 +819,21 @@ Return the ID of the sent message."
(declare-function cider-repl-emit-interactive-stderr "cider-repl")
(declare-function cider--render-stacktrace-causes "cider-interaction")
-(defun nrepl-send-sync-request (request connection &optional abort-on-input)
+(defun nrepl-send-sync-request (request connection &optional abort-on-input tooling)
"Send REQUEST to the nREPL server synchronously using CONNECTION.
Hold till final \"done\" message has arrived and join all response messages
of the same \"op\" that came along.
If ABORT-ON-INPUT is non-nil, the function will return nil at the first
-sign of user input, so as not to hang the interface."
+sign of user input, so as not to hang the interface.
+If TOOLING, use the tooling session rather than the standard session."
(let* ((time0 (current-time))
(response (cons 'dict nil))
(nrepl-ongoing-sync-request t)
status)
(nrepl-send-request request
(lambda (resp) (nrepl--merge response resp))
- connection)
+ connection
+ tooling)
(while (and (not (member "done" status))
(not (and abort-on-input
(input-pending-p))))
@@ -860,21 +865,19 @@ sign of user input, so as not to hang the interface."
(nrepl--mark-id-completed id)))
response))))
-(defun nrepl-request:stdin (input callback connection session)
- "Send a :stdin request with INPUT using CONNECTION and SESSION.
+(defun nrepl-request:stdin (input callback connection)
+ "Send a :stdin request with INPUT using CONNECTION.
Register CALLBACK as the response handler."
(nrepl-send-request (list "op" "stdin"
- "stdin" input
- "session" session)
+ "stdin" input)
callback
connection))
-(defun nrepl-request:interrupt (pending-request-id callback connection session)
+(defun nrepl-request:interrupt (pending-request-id callback connection)
"Send an :interrupt request for PENDING-REQUEST-ID.
-The request is dispatched using CONNECTION and SESSION.
+The request is dispatched using CONNECTION.
Register CALLBACK as the response handler."
(nrepl-send-request (list "op" "interrupt"
- "session" session
"interrupt-id" pending-request-id)
callback
connection))
@@ -882,14 +885,13 @@ Register CALLBACK as the response handler."
(define-minor-mode cider-enlighten-mode nil nil (cider-mode " light")
:global t)
-(defun nrepl--eval-request (input session &optional ns line column)
+(defun nrepl--eval-request (input &optional ns line column)
"Prepare :eval request message for INPUT.
-SESSION and NS provide context for the request.
+NS provides context for the request.
If LINE and COLUMN are non-nil and current buffer is a file buffer, \"line\",
\"column\" and \"file\" are added to the message."
(append (and ns (list "ns" ns))
(list "op" "eval"
- "session" session
"code" input)
(when cider-enlighten-mode
(list "enlighten" "true"))
@@ -899,45 +901,49 @@ If LINE and COLUMN are non-nil and current buffer is a file buffer, \"line\",
"line" line
"column" column)))))
-(defun nrepl-request:eval (input callback connection &optional session ns line column additional-params)
+(defun nrepl-request:eval (input callback connection &optional ns line column additional-params tooling)
"Send the request INPUT and register the CALLBACK as the response handler.
-The request is dispatched via CONNECTION and SESSION. If NS is non-nil,
+The request is dispatched via CONNECTION. If NS is non-nil,
include it in the request. LINE and COLUMN, if non-nil, define the position
-of INPUT in its buffer.
+of INPUT in its buffer. A CONNECTION uniquely determines two connections
+available: the standard interaction one and the tooling session. If the
+tooling is desired, set TOOLING to true.
ADDITIONAL-PARAMS is a plist to be appended to the request message."
- (nrepl-send-request (append (nrepl--eval-request input session ns line column) additional-params)
+ (nrepl-send-request (append (nrepl--eval-request input ns line column) additional-params)
callback
- connection))
+ connection
+ tooling))
-(defun nrepl-sync-request:clone (connection)
+(defun nrepl-sync-request:clone (connection &optional tooling)
"Sent a :clone request to create a new client session.
-The request is dispatched via CONNECTION."
+The request is dispatched via CONNECTION.
+Optional argument TOOLING Tooling is set to t if wanting the tooling session from CONNECTION."
(nrepl-send-sync-request '("op" "clone")
- connection))
+ connection
+ nil tooling))
-(defun nrepl-sync-request:close (connection session)
+(defun nrepl-sync-request:close (connection)
"Sent a :close request to close CONNECTION's SESSION."
- (nrepl-send-sync-request (list "op" "close" "session" session)
- connection))
+ (nrepl-send-sync-request (list "op" "close")
+ connection)
+ (nrepl-send-sync-request (list "op" "close")
+ t)) ;; close tooling session
-(defun nrepl-sync-request:describe (connection &optional session)
+(defun nrepl-sync-request:describe (connection)
"Perform :describe request for CONNECTION and SESSION."
- (if session
- (nrepl-send-sync-request (list "session" session "op" "describe")
- connection)
- (nrepl-send-sync-request '("op" "describe")
- connection)))
+ (nrepl-send-sync-request '("op" "describe")
+ connection))
(defun nrepl-sync-request:ls-sessions (connection)
"Perform :ls-sessions request for CONNECTION."
(nrepl-send-sync-request '("op" "ls-sessions") connection))
-(defun nrepl-sync-request:eval (input connection session &optional ns)
+(defun nrepl-sync-request:eval (input connection &optional ns)
"Send the INPUT to the nREPL server synchronously.
-The request is dispatched via CONNECTION and SESSION.
+The request is dispatched via CONNECTION.
If NS is non-nil, include it in the request."
(nrepl-send-sync-request
- (nrepl--eval-request input session ns)
+ (nrepl--eval-request input ns)
connection))
(defun nrepl-sessions (connection)