Skip to content

Commit

Permalink
elide :ns in load-file responses, as it's always user, NREPL-68
Browse files Browse the repository at this point in the history
  • Loading branch information
cemerick committed Mar 12, 2015
1 parent 1b62bd5 commit ece1466
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/main/clojure/clojure/tools/nrepl/middleware/load_file.clj
@@ -1,6 +1,8 @@
(ns ^{:author "Chas Emerick"}
clojure.tools.nrepl.middleware.load-file
(:require [clojure.tools.nrepl.middleware.interruptible-eval :as eval])
(:import clojure.tools.nrepl.transport.Transport)
(:require [clojure.tools.nrepl.middleware.interruptible-eval :as eval]
[clojure.tools.nrepl.transport :as t])
(:use [clojure.tools.nrepl.middleware :as middleware :only (set-descriptor!)]))

; need to hold file contents "out of band" so as to avoid JVM method
Expand Down Expand Up @@ -72,15 +74,24 @@ be loaded."} file-contents (atom {}))
This middleware depends on the availability of an :op \"eval\"
middleware below it (such as interruptible-eval)."
[h]
(fn [{:keys [op file file-name file-path] :as msg}]
(fn [{:keys [op file file-name file-path transport] :as msg}]
(if (not= op "load-file")
(h msg)
(h (assoc msg
:op "eval"
:code ((if (thread-bound? #'load-file-code)
load-file-code
load-large-file-code)
file file-path file-name))))))
file file-path file-name)
:transport (reify Transport
(recv [this] (.recv transport))
(recv [this timeout] (.recv transport timeout))
(send [this resp]
; *ns* is always 'user' after loading a file, so
; *remove it to avoid confusing tools that assume any
; *:ns always reports *ns*
(.send transport (dissoc resp :ns))
this)))))))

(set-descriptor! #'wrap-load-file
{:requires #{}
Expand Down
9 changes: 9 additions & 0 deletions src/test/clojure/clojure/tools/nrepl/load_file_test.clj
Expand Up @@ -58,3 +58,12 @@

(is (= [4]
(repl-values session (nrepl/code d)))))

(def-repl-test load-file-response-no-ns
(is (not (contains? (nrepl/combine-responses
(nrepl/message session
{:op "load-file"
:file "(ns foo) (def x 5)"
:file-path "/path/to/source.clj"
:file-name "source.clj"}))
:ns))))

0 comments on commit ece1466

Please sign in to comment.