Skip to content

Commit

Permalink
Fix #288: escape regex when searching for completions in REPL (#289)
Browse files Browse the repository at this point in the history
* Fix #288: escape regex when searching for completions in REPL
  • Loading branch information
borkdude authored Dec 14, 2022
1 parent e2b5679 commit dfce022
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ For a list of breaking changes, check [here](#breaking-changes).

[Nbb](https://github.com/babashka/nbb): Scripting in Clojure on Node.js using [SCI](https://github.com/babashka/sci)

## 1.1.152

- [#288](https://github.com/babashka/nbb/issues/288): escape regex when searching for completions in REPL

## 1.1.151 (2022-12-01)

- Add support for executing function using [babashka.cli](https://github.com/babashka/cli):
Expand Down
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#_{:local/root "../babashka/sci"}
#_{:mvn/version "0.3.5"}
{:git/url "https://github.com/babashka/sci"
:git/sha "3d0a6e0ba050c288c5e5985423b77735eef9cf05"}
:git/sha "280865a9850d3befd5239bf42b3aa016230bc0c4"}
org.clojure/tools.cli {:mvn/version "1.0.214"}
com.cognitect/transit-cljs {:mvn/version "0.8.280"}
#_#_prismatic/schema {:mvn/version "1.3.0"}
Expand Down
15 changes: 15 additions & 0 deletions script/nbb_nrepl_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@
msg (read-reply in session @id)
status (:status msg)
_ (is (= ["done"] status))])
(bencode/write-bencode os {"op" "eval" "code" "(def *** 1)"
"session" session "id" (new-id!)})
(let [_ (read-reply in session @id)
msg (read-reply in session @id)
status (:status msg)
_ (is (= ["done"] status))])
(testing "SCI var completions"
(bencode/write-bencode os
{"op" "complete" "symbol" "nbb/"
Expand All @@ -189,6 +195,15 @@
completions (set (map read-msg completions))]
(is (contains? completions {:candidate "nbb/load-string", :ns "nbb.core"}))
(is (contains? completions {:candidate "nbb/await", :ns "nbb.core"}))))
(testing "special characters"
(bencode/write-bencode os
{"op" "complete" "symbol" "*"
"session" session "id" (new-id!)})
(let [msg (read-reply in session @id)
completions (:completions msg)
completions (set (map read-msg completions))]
(is (contains? completions {:candidate "***", :ns "user"}))
(is (contains? completions {:candidate "*print-readably*", :ns "clojure.core"}))))
(testing "JS import completions"
(bencode/write-bencode os
{"op" "complete" "symbol" "fs/"
Expand Down
5 changes: 4 additions & 1 deletion src/nbb/impl/repl_utils.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
syms (remove #(str/starts-with? (str %) "nbb.internal") syms)]
syms))

(defn literal-regex [s]
(re-pattern (str/replace s #"[.*+?^${}()|\[\]\\]" "\\$&")))

(defn match [_alias->ns ns->alias query [sym-ns sym-name qualifier]]
(let [pat (re-pattern query)]
(let [pat (literal-regex query)]
(or (when (and (= :unqualified qualifier) (re-find pat sym-name))
[sym-ns sym-name])
(when sym-ns
Expand Down

0 comments on commit dfce022

Please sign in to comment.