Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

Commit

Permalink
[Fix #332] Handle namespace symbols containing numbers
Browse files Browse the repository at this point in the history
This patch also refactors the common parts of the symbol-capturing regex in a
separate var shared between ns and suffix detection.
  • Loading branch information
arichiardi committed Jan 25, 2018
1 parent 6edca6f commit d6462af
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- Load required macro namespaces when reading analysis cache ([#308](https://github.com/anmonteiro/lumo/issues/308)).
- Don't look for the REPL history file in the user's home directory if one doesn't exist ([#309](https://github.com/anmonteiro/lumo/issues/309)).
- Use `tools.reader` with the unicode literal / cljs.core/bit-or warning ([#341](https://github.com/anmonteiro/lumo/issues/341)).
- Auto-completion fails with numbers in ns names ([#332](https://github.com/anmonteiro/lumo/issues/332))

### Changes

Expand Down
6 changes: 4 additions & 2 deletions src/cljs/snapshot/lumo/repl.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1438,14 +1438,16 @@
(map str (keys special-doc-map))
(map str (keys repl-special-doc-map))))])))

(def ^:private completion-symbol-regex "[a-zA-Z-.<>_*=&?$%!]{1}[a-zA-Z0-9-.<>_*=&?%$!']")

(defn ^:export get-completions
[line cb]
(if-some [js-matches (re-find #"js/(\S*)$" line)]
(js/$$LUMO_GLOBALS.getJSCompletions line (second js-matches) cb)
(let [top-level? (boolean (re-find #"^\s*\(\s*[^()\s]*$" line))
skip-suffix-check? (or (= "(" line) (string/ends-with? line "/") (empty? line))
ns-alias (second (re-find #"\(*(\b[a-zA-Z-.<>*=&?]+)/[a-zA-Z-]*$" line))
line-match-suffix (first (re-find #"^:$|:?([a-zA-Z-.<>_*=&?]{1}[a-zA-Z0-9-.'<>_*=&?]*|^\(/)$" line))
ns-alias (second (re-find (js/RegExp. (str "\\(*(\\b" completion-symbol-regex "+)/[a-zA-Z-]*$")) line))
line-match-suffix (first (re-find (js/RegExp. (str "^:$|:?(" completion-symbol-regex "*|^\\(/)$")) line))
line-prefix (subs line 0 (- (count line) (count line-match-suffix)))
completions (reduce (fn [ret item]
(doto ret
Expand Down
13 changes: 11 additions & 2 deletions src/test/lumo/lumo/repl_tests.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,17 @@
(testing "prefix filtering"
(with-redefs [lumo/get-namespace (fn []
'{:defs {red6hlolli {:name cljs.user/red6hlolli}}})]
(is-contains-completion "red6" "red6hlolli")))))

(is-contains-completion "red6" "red6hlolli")))
(testing "LUMO-332"
(with-redefs [lumo/get-namespace (fn [ns]
'{:name foo-1.core
:defs {xyz {:name foo-1.core/xyz}}
:uses {foo-1 foo-1.core}
:requires {foo-1.core foo-1.core}})
lumo/all-ns (fn []
'(foo-1.core))]
(is-contains-completion "foo-1.co" "foo-1.core")
(is-contains-completion "foo-1.core/" "foo-1.core/xyz")))))


(deftest test-root-resource
Expand Down

0 comments on commit d6462af

Please sign in to comment.