Skip to content

Commit 76d6044

Browse files
committed
[Fix #309] am uses alias for fully qualified ns
1 parent a488350 commit 76d6044

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
### Bugs fixed
1515

16-
-[#299](https://github.com/clojure-emacs/clj-refactor.el/issues/299) `ml` moves cursor
16+
- [#299](https://github.com/clojure-emacs/clj-refactor.el/issues/299) `ml` moves cursor
17+
- [#309](https://github.com/clojure-emacs/clj-refactor.el/issues/309) `am` creates alias for fully-qualified symbols.
1718
- [#320](https://github.com/clojure-emacs/clj-refactor.el/issues/320) `*data-readers*` ignored when searching for macros.
1819

1920
## 2.2.0

clj-refactor.el

+17-11
Original file line numberDiff line numberDiff line change
@@ -2972,14 +2972,20 @@ to create an alias or refer."
29722972
(save-excursion
29732973
(cljr--insert-in-ns ":require")
29742974
(let ((missing (format "%s" missing-symbol))
2975-
(alias? (cljr--qualified-symbol-p symbol)))
2976-
(if alias?
2977-
(cljr--insert-libspec-verbosely (format "[%s :as %s]" missing
2978-
(cljr--symbol-prefix symbol)))
2979-
(if (and (s-contains-p "." missing)
2980-
(s-uppercase? (s-left 1 (cljr--symbol-suffix missing))))
2981-
(cljr--insert-libspec-verbosely (cljr--symbol-prefix symbol))
2982-
(cljr--insert-libspec-verbosely (format "[%s :refer [%s]]"
2975+
(alias? (cljr--qualified-symbol-p symbol)))
2976+
(cond
2977+
;; defrecord / deftype where the package must be required
2978+
((and (s-contains-p "." missing)
2979+
(s-uppercase? (s-left 1 (cljr--symbol-suffix symbol))))
2980+
(cljr--insert-libspec-verbosely (cljr--symbol-prefix missing)))
2981+
;; Fully qualified symbol
2982+
((and (cljr--qualified-symbol-p symbol)
2983+
(string= (cljr--symbol-prefix symbol) missing))
2984+
(cljr--insert-libspec-verbosely missing))
2985+
(alias?
2986+
(cljr--insert-libspec-verbosely (format "[%s :as %s]" missing
2987+
(cljr--symbol-prefix symbol))))
2988+
(t (cljr--insert-libspec-verbosely (format "[%s :refer [%s]]"
29832989
missing symbol)))))))
29842990

29852991
(defun cljr--add-missing-libspec (symbol candidates)
@@ -2994,11 +3000,11 @@ to create an alias or refer."
29943000
;; In the line below we're assuming that all clojure code
29953001
;; will prefer - over _ when naming namespaces :(
29963002
(progn (cljr--insert-missing-require
2997-
(s-replace "_" "-" (format "%s" missing-symbol))
2998-
missing-symbol)
3003+
symbol
3004+
(s-replace "_" "-" (format "%s" missing-symbol)))
29993005
(cljr--insert-missing-import missing-symbol)))
30003006
((eq type :class) (cljr--insert-missing-import missing-symbol))
3001-
(t (error (format "Uknown type %s" type))))))
3007+
(t (error (format "Unknown type %s" type))))))
30023008

30033009
(defun cljr--symbol-suffix (symbol)
30043010
"java.util.Date => Date

features/add-missing-libspec.feature

+8
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,11 @@ Feature: resolve-missing; nrepl middleware response mocked
4343
(:require modular.ring)
4444
(:import modular.ring.WebrequestHandler)
4545
"""
46+
47+
Scenario: Require fully qualified without aliasing #309
48+
Given I call the add-missing-libspec callback directly with mock data to require schema.test
49+
Then I should see:
50+
"""
51+
(ns example.core
52+
(:require schema.test))
53+
"""

features/step-definitions/clj-refactor-steps.el

+6
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@
112112
(list (cljr--make-seeded-hash-table
113113
:name 'modular.ring.WebrequestHandler :type :type)))))
114114

115+
(Given "^I call the add-missing-libspec callback directly with mock data to require schema.test"
116+
(lambda ()
117+
(cljr--add-missing-libspec "schema.test/validate-schemas"
118+
(list (cljr--make-seeded-hash-table
119+
:name 'schema.test :type :ns)))))
120+
115121
(Then "^the file should be named \"\\([^\"]+\\)\"$"
116122
(lambda (file-name-postfix)
117123
(assert (s-ends-with? file-name-postfix (buffer-file-name)) nil "Expected %S to end with %S" (buffer-file-name) file-name-postfix)))

0 commit comments

Comments
 (0)