Skip to content

Commit

Permalink
Guard against namespace aliases with no namespace
Browse files Browse the repository at this point in the history
When completing keywords, the presence of double colons and a slash
assumed that there was a namespace alias separating the two. We catch
the (infrequent) situation of that not being the case, as this threw
an error when the user was typing
  • Loading branch information
Dan Sutton committed Apr 2, 2017
1 parent 8efaee8 commit 14042ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/compliment/sources/keywords.clj
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
"Returns a list of alias-qualified double-colon keywords (like ::str/foo),
where alias has to be registered in the given namespace."
[prefix ns]
(let [[_ alias prefix] (re-matches #"::([^/]+)/(.*)" prefix)
alias-ns-name (str (resolve-namespace (symbol alias) ns))]
(for [[kw _] (keywords-table)
:when (= (namespace kw) alias-ns-name)
:when (.startsWith (name kw) prefix)]
(tagged-candidate (str "::" alias "/" (name kw))))))
(when-let [[_ alias prefix] (re-matches #"::([^/]+)/(.*)" prefix)]
(let [alias-ns-name (str (resolve-namespace (symbol alias) ns))]
(for [[kw _] (keywords-table)
:when (= (namespace kw) alias-ns-name)
:when (.startsWith (name kw) prefix)]
(tagged-candidate (str "::" alias "/" (name kw)))))))

(defn candidates
[^String prefix, ns _]
Expand Down
6 changes: 5 additions & 1 deletion test/compliment/sources/t_keywords.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@
(fact "keyword candidates have a special tag"
(do (str :deprecated)
(src/candidates ":depr" *ns* nil))
=> [{:candidate ":deprecated", :type :keyword}]))
=> [{:candidate ":deprecated", :type :keyword}])

(fact "namespace aliases without namespace are handled"
(do (src/candidates "::/" *ns* nil)
=> nil)))

0 comments on commit 14042ff

Please sign in to comment.