Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix completion of Java packages/classes on Windows. #79

Merged
merged 4 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/compliment/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@
(not (.contains file "$")))]
(.. (if (.startsWith file File/separator)
(.substring file 1) file)
(replace ".class" "") (replace File/separator ".")))
(replace ".class" "")
;; Address the issue #79 , on Windows, for prefix such
;; as "java.util.", the list of candidates was empty.
(replace "/" ".")))
peterwang marked this conversation as resolved.
Show resolved Hide resolved
(group-by #(subs % 0 (max (.indexOf ^String % ".") 0)))))))

(defn namespaces-on-classpath
Expand All @@ -208,7 +211,7 @@
(not (.startsWith file "META-INF")))
:let [[_ ^String nsname] (re-matches #"[^\w]?(.+)\.clj" file)]
:when nsname]
(.. nsname (replace File/separator ".") (replace "_" "-")))))))
(.. nsname (replace "/" ".") (replace "_" "-")))))))

(defn project-resources
"Returns a list of all non-code files in the current project."
Expand All @@ -219,5 +222,7 @@
^String file (list-files path false)
:when (not (or (empty? file) (.endsWith file ".clj")
(.endsWith file ".jar") (.endsWith file ".class")))]
(if (.startsWith file File/separator)
(.substring file 1) file)))))
;; resource pathes always use "/" regardless of platform
(.. (if (.startsWith file File/separator)
(.substring file 1) file)
(replace File/separator "/"))))))
peterwang marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 5 additions & 3 deletions test/compliment/sources/t_ns_mappings.clj
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@
(doall (src/candidates "freq" (-ns) nil)))
=> [{:candidate "frequencies", :type :function, :ns "clojure.core"
:arglists ["[coll]"]
:doc "clojure.core/frequencies\n([coll])
Returns a map from distinct items in coll to the number of times
they appear.\n"}])
:doc (clojure.string/join
(System/lineSeparator)
["clojure.core/frequencies" "([coll])"
" Returns a map from distinct items in coll to the number of times
they appear." ""])}])

(fact "inside (ns ...) vars are looked up only from :used namespace"
(strip-tags
Expand Down