Skip to content

Commit 154dd39

Browse files
vspinubbatsov
authored andcommitted
Simplify ns caching and fix non-evaluation of ns form in cljs
- No need for hash tables; they have non-local dynamics in emacs. - Make calls to cider--prep-interactive-eval explicit on connection.
1 parent d2e22e7 commit 154dd39

File tree

2 files changed

+26
-38
lines changed

2 files changed

+26
-38
lines changed

cider-interaction.el

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,41 +1065,31 @@ evaluation command. Honor `cider-auto-jump-to-error'."
10651065
#'identity))
10661066
"Function to translate Emacs filenames to nREPL namestrings.")
10671067

1068-
(defvar-local cider--ns-form-cache (make-hash-table :test 'equal)
1069-
"ns form cache for the current buffer.
1070-
1071-
The cache is a hash where the keys are connection names and the values
1072-
are ns forms. This allows every connection to keep track of the ns
1073-
form independently.")
1074-
1075-
(defun cider--cache-ns-form ()
1076-
"Cache the form in the current buffer for the current connection."
1077-
(puthash (cider-current-connection)
1078-
(cider-ns-form)
1079-
cider--ns-form-cache))
1080-
1081-
(defun cider--cached-ns-form ()
1082-
"Retrieve the cached ns form for the current buffer & connection."
1083-
(gethash (cider-current-connection) cider--ns-form-cache))
1084-
1085-
(defun cider--prep-interactive-eval (form)
1086-
"Prepare the environment for an interactive eval of FORM.
1087-
1088-
Ensure the current ns declaration has been
1089-
evaluated (so that the ns containing FORM exists).
1090-
If FORM is a ns declaration it's not processed and cached.
1091-
1092-
Clears any compilation highlights and kills the error window."
1068+
(defvar-local cider--last-ns-form nil
1069+
"Ns-form of the most recent interactive evaluation.")
1070+
1071+
(defun cider--prep-interactive-eval (form connection)
1072+
"Prepare the environment for an interactive eval of FORM in CONNECTION.
1073+
Ensure the current ns declaration has been evaluated (so that the ns
1074+
containing FORM exists). Cache ns-form in the current buffer unless FORM is
1075+
ns declaration itself. Clear any compilation highlights and kill the error
1076+
window."
10931077
(cider--clear-compilation-highlights)
10941078
(cider--quit-error-window)
10951079
(let ((cur-ns-form (cider-ns-form)))
10961080
(when (and cur-ns-form
1097-
(not (string= cur-ns-form (cider--cached-ns-form)))
1081+
(not (string= cur-ns-form
1082+
(buffer-local-value 'cider--last-ns-form connection)))
10981083
(not (cider-ns-form-p form)))
10991084
(when cider-auto-track-ns-form-changes
1100-
;; TODO: check for evaluation errors
1101-
(cider-eval-ns-form 'sync))
1102-
(cider--cache-ns-form))))
1085+
;; The first interactive eval on a file can load a lot of libs. This can
1086+
;; easily lead to more than 10 sec.
1087+
(let ((nrepl-sync-request-timeout 30))
1088+
;; TODO: check for evaluation errors
1089+
(cider-nrepl-sync-request:eval cur-ns-form connection)))
1090+
;; cache at the end, in case of errors
1091+
(with-current-buffer connection
1092+
(setq cider--last-ns-form cur-ns-form)))))
11031093

11041094
(defvar-local cider-interactive-eval-override nil
11051095
"Function to call instead of `cider-interactive-eval'.")
@@ -1127,9 +1117,9 @@ arguments and only proceed with evaluation if it returns nil."
11271117
(functionp cider-interactive-eval-override)
11281118
(funcall cider-interactive-eval-override form callback bounds))
11291119
(cider-map-connections #'ignore :any)
1130-
(cider--prep-interactive-eval form)
11311120
(cider-map-connections
11321121
(lambda (connection)
1122+
(cider--prep-interactive-eval form connection)
11331123
(cider-nrepl-request:eval
11341124
form
11351125
(or callback (cider-interactive-eval-handler nil bounds))
@@ -1624,10 +1614,12 @@ ClojureScript REPL exists for the project, it is evaluated in both REPLs."
16241614
(remove-overlays nil nil 'cider-temporary t)
16251615
(cider--clear-compilation-highlights)
16261616
(cider--quit-error-window)
1627-
(cider--cache-ns-form)
1628-
(let ((filename (buffer-file-name buffer)))
1617+
(let ((filename (buffer-file-name buffer))
1618+
(ns-form (cider-ns-form)))
16291619
(cider-map-connections
16301620
(lambda (connection)
1621+
(with-current-buffer connection
1622+
(setq cider--last-ns-form ns-form))
16311623
(cider-request:load-file (cider-file-string filename)
16321624
(funcall cider-to-nrepl-filename-function
16331625
(cider--server-filename filename))
@@ -1795,11 +1787,7 @@ START and END represent the region's boundaries."
17951787
(defun cider--quit-connection (conn)
17961788
"Quit the connection CONN."
17971789
(when conn
1798-
(cider--close-connection-buffer conn)
1799-
;; clean the cached ns forms for this connection in all Clojure buffers
1800-
(dolist (clojure-buffer (cider-util--clojure-buffers))
1801-
(with-current-buffer clojure-buffer
1802-
(remhash conn cider--ns-form-cache)))))
1790+
(cider--close-connection-buffer conn)))
18031791

18041792
(defun cider-quit (&optional quit-all)
18051793
"Quit the currently active CIDER connection.

cider-repl.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ When there is a possible unfinished ansi control sequence,
554554
"Regexp used to highlight root ns in REPL buffers.")
555555

556556
(defvar-local cider-repl--root-ns-regexp nil
557-
"Cache of root ns regexp in REPLs")
557+
"Cache of root ns regexp in REPLs.")
558558

559559
(defun cider-repl--apply-current-project-color (string)
560560
"Fontify project's root namespace to make stacktraces more readable.

0 commit comments

Comments
 (0)