Skip to content

Commit

Permalink
undef-all: skip unmapping of default imports (#751)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhan0 authored May 18, 2022
1 parent 5c0f211 commit dfa2f07
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

## 0.28.3 (2022-02-22)

### Bugs Fixed

* [#751](https://github.com/clojure-emacs/cider-nrepl/issues/751): Skip unmapping of default imports in `undef-all` op.

### Changes

* Upgrade [Orchard to version 0.9.2](https://github.com/clojure-emacs/orchard/blob/v0.9.2/CHANGELOG.md#092-2022-02-22).

## 0.28.2 (2022-02-01)
Expand Down
7 changes: 5 additions & 2 deletions src/cider/nrepl/middleware/undef.clj
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@
"Undefines all symbol mappings and aliases in the namespace."
[{:keys [ns]}]
(let [ns (misc/as-sym ns)]
(doseq [[sym _] (ns-map ns)]
(ns-unmap ns sym))
;; Do not remove the default java.lang imports, as they are not relinked on the next load
;; see https://github.com/clojure-emacs/cider/issues/3194
(doseq [[sym ref] (ns-map ns)]
(when-not (identical? ref (get clojure.lang.RT/DEFAULT_IMPORTS sym))
(ns-unmap ns sym)))
(doseq [[sym _] (ns-aliases ns)]
(ns-unalias ns sym))
ns))
Expand Down
8 changes: 7 additions & 1 deletion test/clj/cider/nrepl/middleware/undef_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
(is (:ex response)))))

(deftest undef-all-test
(testing "undef-all undefines all vars in namespace"
(testing "undef-all undefines all vars in namespace, except default imports"
(is (= #{"done"}
(:status (session/message {:op "eval"
:code "(do (ns other.ns (:require [clojure.walk :as walk :refer [postwalk]])))"}))))
Expand All @@ -113,6 +113,9 @@
(is (= ["#'clojure.walk/postwalk"]
(:value (session/message {:op "eval"
:code "(ns-resolve 'other.ns 'postwalk)"}))))
(is (= ["java.lang.System"]
(:value (session/message {:op "eval"
:code "(ns-resolve 'other.ns 'System)"}))))
(is (= #{"done"}
(:status (session/message {:op "undef-all"
:ns "other.ns"}))))
Expand All @@ -122,6 +125,9 @@
(is (= ["nil"]
(:value (session/message {:op "eval"
:code "(ns-resolve 'other.ns 'postwalk)"}))))
(is (= ["java.lang.System"]
(:value (session/message {:op "eval"
:code "(ns-resolve 'other.ns 'System)"}))))
(is (= ["{}"]
(:value (session/message {:op "eval"
:code "(ns-aliases 'other.ns)"}))))))

0 comments on commit dfa2f07

Please sign in to comment.