Skip to content

Commit

Permalink
resolve: require quotes in alias
Browse files Browse the repository at this point in the history
  • Loading branch information
gregsh committed Nov 11, 2020
1 parent 7a063b3 commit 1c9f0e6
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
12 changes: 9 additions & 3 deletions src/lang/clojure-psi-fileimpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -666,9 +666,15 @@ private class NSReader(val helper: RoleHelper) {
val iterator = content.iterator()
val aliasSym = iterator.safeNext() as? CSymbol ?: return emptyList()
val nsSym = iterator.safeNext() as? CSymbol
val namespace = nsSym?.name ?: ""
setResolveTo(aliasSym, SymKey(aliasSym.name, namespace, "alias"))
setResolveTo(nsSym, SymKey(namespace, "", "ns"))
val aliasQuoted = aliasSym.fastFlags and FLAG_QUOTED != 0
val nsQuoted = nsSym.fastFlags and FLAG_QUOTED != 0
val namespace = if (nsQuoted) nsSym?.name ?: "" else ""
if (aliasQuoted) {
setResolveTo(aliasSym, SymKey(aliasSym.name, namespace, "alias"))
}
if (nsQuoted) {
setResolveTo(nsSym, SymKey(namespace, "", "ns"))
}
return listOf(Import("alias", namespace, aliasSym.name, aliasSym))
}

Expand Down
7 changes: 4 additions & 3 deletions testData/highlighting/ClojureFixes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
(defn allow-forward-decl-in-spec)
)
(do
(alias 'clojure.set-alias clojure.set)
(alias 'clojure.set-alias 'clojure.set)
(defn no-resolve-to-alias [] [<warning>clojure.set-alias</warning> clojure.set-alias/union])
)

Expand Down Expand Up @@ -140,6 +140,7 @@
(-> (Object.) .getClass .getName))

(do
(alias buz 'clojure.set)
(alias bar.buz 'clojure.core)
(alias <warning>bar</warning> <warning>clojure.set</warning>)
(alias 'buz 'clojure.set)
(alias 'bar.buz 'clojure.core)
(buz/union))
2 changes: 1 addition & 1 deletion testData/highlighting/ClojureLang.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,4 @@
/clojure/walk.clj 0 errors, 0 warnings, 0 dynamic
/clojure/xml.clj 0 errors, 0 warnings, 0 dynamic
/clojure/zip.clj 0 errors, 0 warnings, 0 dynamic
Total: 66 warnings, 77 dynamic in 43 files (757.47 kB)
Total: 66 warnings, 77 dynamic in 43 files (757.48 kB)
20 changes: 7 additions & 13 deletions testData/highlighting/ClojureScript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
3124: dynamic 'length'
11602: dynamic 'exists'
12525: dynamic 'exists'
/cljs/closure.clj 0 errors, 9 warnings, 43 dynamic
874: unable to resolve 'clojure.reflect'
/cljs/closure.clj 0 errors, 8 warnings, 43 dynamic
62592: unable to resolve 'read-str'
69334: unable to resolve 'write-str'
75708: unable to resolve 'read-str'
Expand Down Expand Up @@ -156,8 +155,7 @@
137090: dynamic 'slice'
141847: dynamic '-cljs$lang$macro'
143846: dynamic '-cljs$lang$macro'
/cljs/core.cljs 0 errors, 20 warnings, 864 dynamic
660: unable to resolve 'goog.Uri'
/cljs/core.cljs 0 errors, 19 warnings, 864 dynamic
33056: unable to resolve 'cljs.core.Var'
62372: unable to resolve 'goog.math.Integer'
62410: unable to resolve 'goog.math.Long'
Expand Down Expand Up @@ -813,8 +811,7 @@
6646: unable to resolve 'source-logging-push-back-reader'
/cljs/core/specs/alpha.cljc 0 errors, 1 warnings, 0 dynamic
6567: unable to resolve 'ns-special-form'
/cljs/core/specs/alpha.cljs 0 errors, 1 warnings, 0 dynamic
510: unable to resolve 'cljs.core.specs.alpha'
/cljs/core/specs/alpha.cljs 0 errors, 0 warnings, 0 dynamic
/cljs/env.cljc 0 errors, 0 warnings, 0 dynamic
/cljs/env/macros.clj 0 errors, 0 warnings, 0 dynamic
/cljs/externs.clj 0 errors, 0 warnings, 22 dynamic
Expand All @@ -841,8 +838,7 @@
10389: dynamic 'getName'
10592: dynamic 'getName'
/cljs/js.clj 0 errors, 0 warnings, 0 dynamic
/cljs/js.cljs 0 errors, 29 warnings, 47 dynamic
733: unable to resolve 'cljs.spec.alpha'
/cljs/js.cljs 0 errors, 28 warnings, 47 dynamic
2001: unable to resolve 'read'
4412: unable to resolve 'default-compiler-env'
9423: unable to resolve 'default-compiler-env'
Expand Down Expand Up @@ -1066,8 +1062,7 @@
52607: dynamic 'instanceMethod'
52656: dynamic 'instanceField'
64988: dynamic 'stack'
/cljs/repl.cljs 0 errors, 1 warnings, 3 dynamic
591: unable to resolve 'goog.string.format'
/cljs/repl.cljs 0 errors, 0 warnings, 3 dynamic
2861: dynamic 'name'
/cljs/repl/bootstrap.clj 0 errors, 0 warnings, 11 dynamic
966: dynamic 'isProvided__'
Expand Down Expand Up @@ -1396,8 +1391,7 @@
4575: dynamic 'open'
4635: dynamic 'send'
4806: dynamic 'toLowerCase'
/clojure/browser/repl.cljs 0 errors, 3 warnings, 83 dynamic
1341: unable to resolve 'cljs.repl'
/clojure/browser/repl.cljs 0 errors, 2 warnings, 83 dynamic
1368: unable to resolve 'HOST'
1399: unable to resolve 'PORT'
1772: dynamic 'json/serialize'
Expand Down Expand Up @@ -1484,4 +1478,4 @@
/clojure/zip.cljs 0 errors, 0 warnings, 0 dynamic
/process/env.cljs 0 errors, 1 warnings, 0 dynamic
541: unable to resolve 'NODE_ENV'
Total: 348 warnings, 1651 dynamic in 74 files (1.64 MB)
Total: 342 warnings, 1651 dynamic in 74 files (1.64 MB)
4 changes: 2 additions & 2 deletions tests/lang/completion-tests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import com.intellij.testFramework.fixtures.BasePlatformTestCase
class ClojureCompletionTest : BasePlatformTestCase() {
companion object {
val NS_KEY = "namespace/keyword"
val NS_ALIAS = "(alias 'namespace some-ns)"
val STR_ALIAS = "(alias 'str clojure.string)"
val NS_ALIAS = "(alias 'namespace 'some-ns)"
val STR_ALIAS = "(alias 'str 'clojure.string)"
}

override fun setUp() {
Expand Down
2 changes: 1 addition & 1 deletion tests/lang/usages-tests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import junit.framework.TestCase

class ClojureUsagesTest : BasePlatformTestCase() {
companion object {
const val NS_ALIAS = "(alias 'bar foo.bar)"
const val NS_ALIAS = "(alias 'bar 'foo.bar)"
}

fun testKeywordUsages1() = doTest("(let [{:keys [x y]} {:x| 42}] y)", 2)
Expand Down

0 comments on commit 1c9f0e6

Please sign in to comment.