From 1c9406da5a55f78c9f70d3ea42056eb61aa5148a Mon Sep 17 00:00:00 2001 From: Peter Wang Date: Thu, 9 Sep 2021 09:41:30 +0800 Subject: [PATCH 1/4] Fix completion of Java packages/classes on Windows. Since file pathes inside jar files contain '/' instead of `File/separator', '/' also should be replaced with '.' Before this fix, completion of java packages such as java.util.*, java.nio.* does not work, it works now. --- src/compliment/utils.clj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compliment/utils.clj b/src/compliment/utils.clj index 4018d58..90dfe07 100644 --- a/src/compliment/utils.clj +++ b/src/compliment/utils.clj @@ -195,7 +195,8 @@ (not (.contains file "$")))] (.. (if (.startsWith file File/separator) (.substring file 1) file) - (replace ".class" "") (replace File/separator "."))) + (replace ".class" "") (replace File/separator ".") + (replace "/" "."))) (group-by #(subs % 0 (max (.indexOf ^String % ".") 0))))))) (defn namespaces-on-classpath From 47254a89efd212de5ddeec85d2fe041736fb72da Mon Sep 17 00:00:00 2001 From: Peter Wang Date: Thu, 9 Sep 2021 19:16:45 +0800 Subject: [PATCH 2/4] Add inline comment for the change. --- src/compliment/utils.clj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/compliment/utils.clj b/src/compliment/utils.clj index 90dfe07..2057df5 100644 --- a/src/compliment/utils.clj +++ b/src/compliment/utils.clj @@ -196,6 +196,8 @@ (.. (if (.startsWith file File/separator) (.substring file 1) file) (replace ".class" "") (replace File/separator ".") + ;; Address the issue #79 , on Windows, for prefix such + ;; as "java.util.", the list of candidates was empty. (replace "/" "."))) (group-by #(subs % 0 (max (.indexOf ^String % ".") 0))))))) From d2863106e598ced53567af4c64ef00a0e7cff236 Mon Sep 17 00:00:00 2001 From: Peter Wang Date: Fri, 10 Sep 2021 08:55:09 +0800 Subject: [PATCH 3/4] Fix issues related to File/separator on Windows. --- src/compliment/utils.clj | 10 ++++++---- test/compliment/sources/t_ns_mappings.clj | 8 +++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/compliment/utils.clj b/src/compliment/utils.clj index 2057df5..5cc9159 100644 --- a/src/compliment/utils.clj +++ b/src/compliment/utils.clj @@ -195,7 +195,7 @@ (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 "/" "."))) @@ -211,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." @@ -222,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 "/")))))) diff --git a/test/compliment/sources/t_ns_mappings.clj b/test/compliment/sources/t_ns_mappings.clj index f6c93ac..7ecf360 100644 --- a/test/compliment/sources/t_ns_mappings.clj +++ b/test/compliment/sources/t_ns_mappings.clj @@ -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 From 629ecddcda2c91150b9a6926e6fd526efa5b85f9 Mon Sep 17 00:00:00 2001 From: Peter Wang Date: Fri, 10 Sep 2021 09:25:16 +0800 Subject: [PATCH 4/4] use resource-separator for path separator within resources and .jar files. --- src/compliment/utils.clj | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/compliment/utils.clj b/src/compliment/utils.clj index 5cc9159..601322e 100644 --- a/src/compliment/utils.clj +++ b/src/compliment/utils.clj @@ -13,6 +13,12 @@ candidates they should attach . Should be a set of keywords." nil) +(def resource-separator + "The path separator used within resources and .jar files. + +Note that should always have the same value, regardless of OS." + "/") + (defn fuzzy-matches? "Tests if symbol matches the prefix when symbol is split into parts on separator." @@ -198,7 +204,7 @@ (replace ".class" "") ;; Address the issue #79 , on Windows, for prefix such ;; as "java.util.", the list of candidates was empty. - (replace "/" "."))) + (replace resource-separator "."))) (group-by #(subs % 0 (max (.indexOf ^String % ".") 0))))))) (defn namespaces-on-classpath @@ -211,7 +217,7 @@ (not (.startsWith file "META-INF"))) :let [[_ ^String nsname] (re-matches #"[^\w]?(.+)\.clj" file)] :when nsname] - (.. nsname (replace "/" ".") (replace "_" "-"))))))) + (.. nsname (replace resource-separator ".") (replace "_" "-"))))))) (defn project-resources "Returns a list of all non-code files in the current project." @@ -225,4 +231,4 @@ ;; resource pathes always use "/" regardless of platform (.. (if (.startsWith file File/separator) (.substring file 1) file) - (replace File/separator "/")))))) + (replace File/separator resource-separator))))))