Skip to content

Commit f5c8f17

Browse files
committed
Merge pull request #323 from clojure-emacs/fix-am-vs-alias
[Fix #309] `am` uses alias for fully qualified ns
2 parents 050b9c2 + 76d6044 commit f5c8f17

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
@@ -14,7 +14,8 @@
1414

1515
### Bugs fixed
1616

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

2021
## 2.2.0

clj-refactor.el

+17-11
Original file line numberDiff line numberDiff line change
@@ -2977,14 +2977,20 @@ to create an alias or refer."
29772977
(save-excursion
29782978
(cljr--insert-in-ns ":require")
29792979
(let ((missing (format "%s" missing-symbol))
2980-
(alias? (cljr--qualified-symbol-p symbol)))
2981-
(if alias?
2982-
(cljr--insert-libspec-verbosely (format "[%s :as %s]" missing
2983-
(cljr--symbol-prefix symbol)))
2984-
(if (and (s-contains-p "." missing)
2985-
(s-uppercase? (s-left 1 (cljr--symbol-suffix missing))))
2986-
(cljr--insert-libspec-verbosely (cljr--symbol-prefix symbol))
2987-
(cljr--insert-libspec-verbosely (format "[%s :refer [%s]]"
2980+
(alias? (cljr--qualified-symbol-p symbol)))
2981+
(cond
2982+
;; defrecord / deftype where the package must be required
2983+
((and (s-contains-p "." missing)
2984+
(s-uppercase? (s-left 1 (cljr--symbol-suffix symbol))))
2985+
(cljr--insert-libspec-verbosely (cljr--symbol-prefix missing)))
2986+
;; Fully qualified symbol
2987+
((and (cljr--qualified-symbol-p symbol)
2988+
(string= (cljr--symbol-prefix symbol) missing))
2989+
(cljr--insert-libspec-verbosely missing))
2990+
(alias?
2991+
(cljr--insert-libspec-verbosely (format "[%s :as %s]" missing
2992+
(cljr--symbol-prefix symbol))))
2993+
(t (cljr--insert-libspec-verbosely (format "[%s :refer [%s]]"
29882994
missing symbol)))))))
29892995

29902996
(defun cljr--add-missing-libspec (symbol candidates)
@@ -2999,11 +3005,11 @@ to create an alias or refer."
29993005
;; In the line below we're assuming that all clojure code
30003006
;; will prefer - over _ when naming namespaces :(
30013007
(progn (cljr--insert-missing-require
3002-
(s-replace "_" "-" (format "%s" missing-symbol))
3003-
missing-symbol)
3008+
symbol
3009+
(s-replace "_" "-" (format "%s" missing-symbol)))
30043010
(cljr--insert-missing-import missing-symbol)))
30053011
((eq type :class) (cljr--insert-missing-import missing-symbol))
3006-
(t (error (format "Uknown type %s" type))))))
3012+
(t (error (format "Unknown type %s" type))))))
30073013

30083014
(defun cljr--symbol-suffix (symbol)
30093015
"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)