Permalink
Browse files

autocomplete

  • Loading branch information...
viebel committed Dec 5, 2018
1 parent 9360548 commit 38885d7c4d0b2d3816a0a30815455a460ccadd15
Showing with 23,387 additions and 22,883 deletions.
  1. +8 −12 src/klipse_clj/lang/clojure.cljs
  2. +202 −2 src/klipse_clj/repl.cljs
  3. +1 −1 target/public/cljs-out/dev/cljs/analyzer.cljc.cache.json
  4. +1,704 −1,704 target/public/cljs-out/dev/cljs/analyzer.js
  5. +1 −1 target/public/cljs-out/dev/cljs/analyzer.js.map
  6. +1 −1 target/public/cljs-out/dev/cljs/analyzer/api.cljc.cache.json
  7. +50 −50 target/public/cljs-out/dev/cljs/analyzer/api.js
  8. +1 −1 target/public/cljs-out/dev/cljs/analyzer/api.js.map
  9. +1 −1 target/public/cljs-out/dev/cljs/compiler.cljc.cache.json
  10. +1,874 −1,874 target/public/cljs-out/dev/cljs/compiler.js
  11. +1 −1 target/public/cljs-out/dev/cljs/compiler.js.map
  12. +1 −1 target/public/cljs-out/dev/cljs/core$macros.cljc.cache.json
  13. +2,314 −2,314 target/public/cljs-out/dev/cljs/core$macros.js
  14. +1 −1 target/public/cljs-out/dev/cljs/core$macros.js.map
  15. +1 −1 target/public/cljs-out/dev/cljs/core/async.cljs.cache.json
  16. +3,756 −3,755 target/public/cljs-out/dev/cljs/core/async.js
  17. +1 −1 target/public/cljs-out/dev/cljs/core/async.js.map
  18. +7 −7 target/public/cljs-out/dev/cljs/core/async/impl/buffers.js
  19. +1 −1 target/public/cljs-out/dev/cljs/core/async/impl/buffers.js.map
  20. +1 −1 target/public/cljs-out/dev/cljs/core/async/impl/channels.cljs.cache.json
  21. +142 −142 target/public/cljs-out/dev/cljs/core/async/impl/channels.js
  22. +1 −1 target/public/cljs-out/dev/cljs/core/async/impl/channels.js.map
  23. +7 −7 target/public/cljs-out/dev/cljs/core/async/impl/dispatch.js
  24. +1 −1 target/public/cljs-out/dev/cljs/core/async/impl/dispatch.js.map
  25. +1 −1 target/public/cljs-out/dev/cljs/core/async/impl/ioc_helpers.cljs.cache.json
  26. +92 −92 target/public/cljs-out/dev/cljs/core/async/impl/ioc_helpers.js
  27. +1 −1 target/public/cljs-out/dev/cljs/core/async/impl/ioc_helpers.js.map
  28. +2 −2 target/public/cljs-out/dev/cljs/core/async/impl/protocols.js
  29. +1 −1 target/public/cljs-out/dev/cljs/core/async/impl/protocols.js.map
  30. +57 −57 target/public/cljs-out/dev/cljs/core/async/impl/timers.js
  31. +1 −1 target/public/cljs-out/dev/cljs/core/async/impl/timers.js.map
  32. +2 −2 target/public/cljs-out/dev/cljs/env.js
  33. +1 −1 target/public/cljs-out/dev/cljs/env.js.map
  34. +1 −1 target/public/cljs-out/dev/cljs/js.cljs.cache.json
  35. +551 −551 target/public/cljs-out/dev/cljs/js.js
  36. +1 −1 target/public/cljs-out/dev/cljs/js.js.map
  37. +1 −1 target/public/cljs-out/dev/cljs/pprint.cljs.cache.json
  38. +2,100 −2,100 target/public/cljs-out/dev/cljs/pprint.js
  39. +1 −1 target/public/cljs-out/dev/cljs/pprint.js.map
  40. +123 −123 target/public/cljs-out/dev/cljs/reader.js
  41. +1 −1 target/public/cljs-out/dev/cljs/reader.js.map
  42. +1 −1 target/public/cljs-out/dev/cljs/repl.cljs.cache.json
  43. +144 −144 target/public/cljs-out/dev/cljs/repl.js
  44. +1 −1 target/public/cljs-out/dev/cljs/repl.js.map
  45. +816 −816 target/public/cljs-out/dev/cljs/source_map.js
  46. +1 −1 target/public/cljs-out/dev/cljs/source_map.js.map
  47. +16 −16 target/public/cljs-out/dev/cljs/source_map/base64_vlq.js
  48. +1 −1 target/public/cljs-out/dev/cljs/source_map/base64_vlq.js.map
  49. +1 −1 target/public/cljs-out/dev/cljs/spec/alpha.cljs.cache.json
  50. +1,404 −1,404 target/public/cljs-out/dev/cljs/spec/alpha.js
  51. +1 −1 target/public/cljs-out/dev/cljs/spec/alpha.js.map
  52. +682 −682 target/public/cljs-out/dev/cljs/spec/gen/alpha.js
  53. +1 −1 target/public/cljs-out/dev/cljs/spec/gen/alpha.js.map
  54. +1 −1 target/public/cljs-out/dev/cljs/stacktrace.cljc.cache.json
  55. +193 −193 target/public/cljs-out/dev/cljs/stacktrace.js
  56. +1 −1 target/public/cljs-out/dev/cljs/stacktrace.js.map
  57. +2 −2 target/public/cljs-out/dev/cljs/tagged_literals.js
  58. +1 −1 target/public/cljs-out/dev/cljs/tagged_literals.js.map
  59. +176 −176 target/public/cljs-out/dev/cljs/tools/reader.js
  60. +1 −1 target/public/cljs-out/dev/cljs/tools/reader.js.map
  61. +90 −90 target/public/cljs-out/dev/cljs/tools/reader/edn.js
  62. +1 −1 target/public/cljs-out/dev/cljs/tools/reader/edn.js.map
  63. +27 −27 target/public/cljs-out/dev/cljs/tools/reader/impl/commons.js
  64. +1 −1 target/public/cljs-out/dev/cljs/tools/reader/impl/commons.js.map
  65. +85 −85 target/public/cljs-out/dev/cljs/tools/reader/impl/errors.js
  66. +1 −1 target/public/cljs-out/dev/cljs/tools/reader/impl/errors.js.map
  67. +2 −2 target/public/cljs-out/dev/cljs/tools/reader/impl/inspect.js
  68. +1 −1 target/public/cljs-out/dev/cljs/tools/reader/impl/inspect.js.map
  69. +1 −1 target/public/cljs-out/dev/cljs/tools/reader/impl/utils.cljs.cache.json
  70. +49 −49 target/public/cljs-out/dev/cljs/tools/reader/impl/utils.js
  71. +1 −1 target/public/cljs-out/dev/cljs/tools/reader/impl/utils.js.map
  72. +10 −10 target/public/cljs-out/dev/cljs/tools/reader/reader_types.js
  73. +1 −1 target/public/cljs-out/dev/cljs/tools/reader/reader_types.js.map
  74. +1 −1 target/public/cljs-out/dev/cljs_http/client.cljs.cache.json
  75. +285 −285 target/public/cljs-out/dev/cljs_http/client.js
  76. +1 −1 target/public/cljs-out/dev/cljs_http/client.js.map
  77. +1 −1 target/public/cljs-out/dev/cljs_http/core.cljs.cache.json
  78. +185 −185 target/public/cljs-out/dev/cljs_http/core.js
  79. +1 −1 target/public/cljs-out/dev/cljs_http/core.js.map
  80. +1 −1 target/public/cljs-out/dev/cljs_http/util.cljs.cache.json
  81. +24 −24 target/public/cljs-out/dev/cljs_http/util.js
  82. +1 −1 target/public/cljs-out/dev/cljs_http/util.js.map
  83. +1 −1 target/public/cljs-out/dev/cljsc_opts.edn
  84. +14 −14 target/public/cljs-out/dev/clojure/data.js
  85. +1 −1 target/public/cljs-out/dev/clojure/data.js.map
  86. +87 −87 target/public/cljs-out/dev/clojure/set.js
  87. +1 −1 target/public/cljs-out/dev/clojure/set.js.map
  88. +50 −50 target/public/cljs-out/dev/clojure/string.js
  89. +1 −1 target/public/cljs-out/dev/clojure/string.js.map
  90. +8 −8 target/public/cljs-out/dev/clojure/walk.js
  91. +1 −1 target/public/cljs-out/dev/clojure/walk.js.map
  92. +98 −98 target/public/cljs-out/dev/clojure/zip.js
  93. +1 −1 target/public/cljs-out/dev/clojure/zip.js.map
  94. +1 −1 target/public/cljs-out/dev/cognitect/transit.cljs.cache.json
  95. +249 −249 target/public/cljs-out/dev/cognitect/transit.js
  96. +1 −1 target/public/cljs-out/dev/cognitect/transit.js.map
  97. +9 −9 target/public/cljs-out/dev/devtools/async.js
  98. +1 −1 target/public/cljs-out/dev/devtools/async.js.map
  99. +38 −38 target/public/cljs-out/dev/devtools/core.js
  100. +1 −1 target/public/cljs-out/dev/devtools/core.js.map
  101. +133 −133 target/public/cljs-out/dev/devtools/format.js
  102. +1 −1 target/public/cljs-out/dev/devtools/format.js.map
  103. +36 −36 target/public/cljs-out/dev/devtools/formatters.js
  104. +1 −1 target/public/cljs-out/dev/devtools/formatters.js.map
  105. +52 −52 target/public/cljs-out/dev/devtools/formatters/budgeting.js
  106. +1 −1 target/public/cljs-out/dev/devtools/formatters/budgeting.js.map
  107. +21 −21 target/public/cljs-out/dev/devtools/formatters/core.js
  108. +1 −1 target/public/cljs-out/dev/devtools/formatters/core.js.map
  109. +10 −10 target/public/cljs-out/dev/devtools/formatters/helpers.js
  110. +1 −1 target/public/cljs-out/dev/devtools/formatters/helpers.js.map
  111. +277 −277 target/public/cljs-out/dev/devtools/formatters/markup.js
  112. +1 −1 target/public/cljs-out/dev/devtools/formatters/markup.js.map
  113. +34 −34 target/public/cljs-out/dev/devtools/formatters/printing.js
  114. +1 −1 target/public/cljs-out/dev/devtools/formatters/printing.js.map
  115. +12 −12 target/public/cljs-out/dev/devtools/formatters/state.js
  116. +1 −1 target/public/cljs-out/dev/devtools/formatters/state.js.map
  117. +182 −182 target/public/cljs-out/dev/devtools/formatters/templating.js
  118. +1 −1 target/public/cljs-out/dev/devtools/formatters/templating.js.map
  119. +15 −15 target/public/cljs-out/dev/devtools/hints.js
  120. +1 −1 target/public/cljs-out/dev/devtools/hints.js.map
  121. +1 −1 target/public/cljs-out/dev/devtools/munging.cljs.cache.json
  122. +150 −150 target/public/cljs-out/dev/devtools/munging.js
  123. +1 −1 target/public/cljs-out/dev/devtools/munging.js.map
  124. +12 −12 target/public/cljs-out/dev/devtools/prefs.js
  125. +1 −1 target/public/cljs-out/dev/devtools/prefs.js.map
  126. +15 −15 target/public/cljs-out/dev/devtools/reporter.js
  127. +1 −1 target/public/cljs-out/dev/devtools/reporter.js.map
  128. +1 −1 target/public/cljs-out/dev/devtools/toolbox.cljs.cache.json
  129. +25 −25 target/public/cljs-out/dev/devtools/toolbox.js
  130. +1 −1 target/public/cljs-out/dev/devtools/toolbox.js.map
  131. +98 −98 target/public/cljs-out/dev/devtools/util.js
  132. +1 −1 target/public/cljs-out/dev/devtools/util.js.map
  133. +1 −1 target/public/cljs-out/dev/figwheel/core.cljc.cache.json
  134. +291 −291 target/public/cljs-out/dev/figwheel/core.js
  135. +1 −1 target/public/cljs-out/dev/figwheel/core.js.map
  136. +1 −1 target/public/cljs-out/dev/figwheel/repl.cljc.cache.json
  137. +384 −384 target/public/cljs-out/dev/figwheel/repl.js
  138. +1 −1 target/public/cljs-out/dev/figwheel/repl.js.map
  139. +1 −1 target/public/cljs-out/dev/figwheel/tools/heads_up.cljs.cache.json
  140. +231 −231 target/public/cljs-out/dev/figwheel/tools/heads_up.js
  141. +1 −1 target/public/cljs-out/dev/figwheel/tools/heads_up.js.map
  142. +1 −1 target/public/cljs-out/dev/gadjett/collections.cljc.cache.json
  143. +194 −194 target/public/cljs-out/dev/gadjett/collections.js
  144. +1 −1 target/public/cljs-out/dev/gadjett/collections.js.map
  145. +16 −16 target/public/cljs-out/dev/gadjett/core_fn.js
  146. +1 −1 target/public/cljs-out/dev/gadjett/core_fn.js.map
  147. +8 −12 target/public/cljs-out/dev/klipse_clj/lang/clojure.cljs
  148. +1 −1 target/public/cljs-out/dev/klipse_clj/lang/clojure.cljs.cache.json
  149. +1,166 −1,224 target/public/cljs-out/dev/klipse_clj/lang/clojure.js
  150. +1 −1 target/public/cljs-out/dev/klipse_clj/lang/clojure.js.map
  151. +148 −148 target/public/cljs-out/dev/klipse_clj/lang/clojure/guard.js
  152. +1 −1 target/public/cljs-out/dev/klipse_clj/lang/clojure/guard.js.map
  153. +1 −1 target/public/cljs-out/dev/klipse_clj/lang/clojure/io.cljs.cache.json
  154. +857 −857 target/public/cljs-out/dev/klipse_clj/lang/clojure/io.js
  155. +1 −1 target/public/cljs-out/dev/klipse_clj/lang/clojure/io.js.map
  156. +202 −2 target/public/cljs-out/dev/klipse_clj/repl.cljs
  157. +1 −1 target/public/cljs-out/dev/klipse_clj/repl.cljs.cache.json
  158. +371 −202 target/public/cljs-out/dev/klipse_clj/repl.js
  159. +1 −1 target/public/cljs-out/dev/klipse_clj/repl.js.map
  160. +1 −1 target/public/cljs-out/dev/no/en/core.cljc.cache.json
  161. +112 −112 target/public/cljs-out/dev/no/en/core.js
  162. +1 −1 target/public/cljs-out/dev/no/en/core.js.map
  163. +1 −1 target/public/cljs-out/dev/parinfer/indent_mode.cljc.cache.json
  164. +197 −197 target/public/cljs-out/dev/parinfer/indent_mode.js
  165. +1 −1 target/public/cljs-out/dev/parinfer/indent_mode.js.map
  166. +1 −1 target/public/cljs-out/dev/parinfer/paren_mode.cljc.cache.json
  167. +95 −95 target/public/cljs-out/dev/parinfer/paren_mode.js
  168. +1 −1 target/public/cljs-out/dev/parinfer/paren_mode.js.map
  169. +54 −54 target/public/cljs-out/dev/parinfer/reader.js
  170. +1 −1 target/public/cljs-out/dev/parinfer/reader.js.map
  171. +106 −106 target/public/cljs-out/dev/parinfer_codemirror/editor.js
  172. +1 −1 target/public/cljs-out/dev/parinfer_codemirror/editor.js.map
  173. +44 −44 target/public/cljs-out/dev/parinfer_codemirror/editor_support.js
  174. +1 −1 target/public/cljs-out/dev/parinfer_codemirror/editor_support.js.map
  175. +4 −4 target/public/cljs-out/dev/parinfer_codemirror/example.js
  176. +1 −1 target/public/cljs-out/dev/parinfer_codemirror/example.js.map
@@ -9,7 +9,7 @@
[cljs.tagged-literals :as tags]
[goog.dom :as gdom]
[clojure.string :refer [blank?]]
[klipse-clj.repl :refer [st create-state-compile current-ns-eval current-ns-compile reset-ns-eval! reset-ns-compile!]]
[klipse-clj.repl :refer [get-completions current-alias-map st create-state-compile current-ns-eval current-ns-compile reset-ns-eval! reset-ns-compile!]]
[klipse-clj.lang.clojure.guard :refer [min-max-eval-duration my-emits watchdog]]
[klipse-clj.lang.clojure.io :as io]
[clojure.pprint :as pprint]
@@ -37,18 +37,11 @@
(<! (core-eval-an-exp my-macros {:st @st :ns current-ns-eval})))))
(defn create-state-eval []
(go
(when (nil? @st)
(if @st
(go @st)
(do
(reset! st (cljs/empty-state))
(<! (init-custom-macros)))
@st))
(defn- current-alias-map
[ns]
(->> (merge (get-in @@st [::ana/namespaces ns :requires])
(get-in @@st [::ana/namespaces ns :require-macros]))
(remove (fn [[k v]] (= k v)))
(into {})))
(init-custom-macros))))
(defn display [value {:keys [print-length beautify-strings]}]
(with-redefs [*print-length* print-length]
@@ -205,6 +198,9 @@
(gdom/setTextContent container (str (:error res))))
res)
(def completions get-completions)
(defn core-eval [s opts]
(go
(try
@@ -25,7 +25,7 @@
(reset! current-ns-compile 'cljs.user))
(def st (atom nil))
(defonce st (atom nil))
(defn reset-state-eval! []
(reset! st nil))
@@ -40,6 +40,10 @@
(defn reset-state-compile! []
(reset! st-compile nil))
(defn- add-macros-suffix
[sym]
(symbol (str (name sym) "$macros")))
(defn eval-form
([form]
(eval-form (.-name *ns*)))
@@ -261,4 +265,200 @@
(get-var (get-aenv)
(symbol (str (:ns var)) (str fname))))
:arglists (seq sigs)}]))
(into {})))))))))
(into {})))))))))
(defn- completion-candidates-for-ns
[ns-sym allow-private?]
(if (string/starts-with? (str ns-sym) "goog")
(if (find-ns ns-sym)
(into [] (js-keys (.getObjectByName js/goog (str ns-sym))))
[])
(map (comp str key)
(into []
(comp
(filter (if allow-private?
identity
#(not (:private (val %)))))
(remove #(:anonymous (val %))))
(apply merge
((juxt :defs :macros)
(get-namespace ns-sym)))))))
(defn- completion-candidates-for-current-ns []
(let [cur-ns @current-ns-eval]
(into (completion-candidates-for-ns cur-ns true)
(comp (mapcat keys) (map str))
((juxt :renames :rename-macros :uses :use-macros) (get-namespace cur-ns)))))
(defn- is-completion?
[match-suffix candidate]
(let [escaped-suffix (string/replace match-suffix #"[-\/\\^$*+?.()|\[\]{}]" "\\$&")]
(re-find (js/RegExp. (str "^" escaped-suffix) "i") candidate)))
(def ^:private keyword-completions
[:require :require-macros :import
:refer :refer-macros :include-macros
:refer-clojure :exclude
:keys :strs :syms
:as :or
:pre :post
:let :when :while
:clj :cljs
:default
:else
:gen-class
:keywordize-keys
:req :req-un :opt :opt-un
:args :ret :fn])
(def ^:private namespace-completion-exclusions
'[planck.from.io.aviso.ansi
planck.pprint.code
planck.pprint.data
planck.bundle
planck.closure
planck.js-deps
planck.repl
planck.repl-resources
planck.themes
clojure.core.rrb-vector
clojure.core.rrb-vector.interop
clojure.core.rrb-vector.nodes
clojure.core.rrb-vector.protocols
clojure.core.rrb-vector.rrbt
clojure.core.rrb-vector.transients
clojure.core.rrb-vector.trees
cognitect.transit
fipp.deque
fipp.engine
fipp.visit
lazy-map.core
cljs.source-map
cljs.source-map.base64
cljs.source-map.base64-vlq
cljs.tools.reader.impl.commons
cljs.tools.reader.impl.utils
cljs.stacktrace])
(def ^:private namespace-completion-additons
'[clojure.core
clojure.test
clojure.spec.alpha
clojure.spec.test.alpha
clojure.spec.gen.alpha
clojure.pprint])
(defn- all-ns
"Returns a sequence of all namespaces."
[]
(keys (::ana/namespaces @@st)))
(defn- current-alias-map
([] (current-alias-map @current-ns-eval))
([ns]
(->> (merge (get-in @@st [::ana/namespaces ns :requires])
(get-in @@st [::ana/namespaces ns :require-macros]))
(remove (fn [[k v]] (= k v)))
(into {}))))
(defn- namespace-completions
[]
(->> (all-ns)
(map #(drop-macros-suffix (str %)))
(remove (into #{} (map str namespace-completion-exclusions)))
(concat (map str namespace-completion-additons))
sort
distinct))
(defn- expand-typed-ns
"Expand the typed namespace symbol to a known namespace, consulting current
namespace aliases if necessary."
[alias]
(let [alias (if (symbol-identical? alias 'clojure.core)
'cljs.core
alias)]
(or (get-in st [:cljs.analyzer/namespaces alias :name])
(alias (current-alias-map))
alias)))
(defn- completion-candidates
[top-form? typed-ns]
(set (if typed-ns
(let [expanded-ns (expand-typed-ns (symbol typed-ns))]
(concat
(completion-candidates-for-ns expanded-ns false)
(completion-candidates-for-ns (add-macros-suffix expanded-ns) false)))
(concat
(map str keyword-completions)
(namespace-completions)
(map #(str % "/") (keys (current-alias-map)))
(completion-candidates-for-ns 'cljs.core false)
(completion-candidates-for-ns 'cljs.core$macros false)
(completion-candidates-for-current-ns)
(when top-form?
(concat
(map str (keys special-doc-map))
(map str (keys repl-special-doc-map))))))))
(defn- longest-common-prefix
[strings]
(let [minl (apply min (map count strings))]
(loop [l minl]
(if (> l 0)
(if (every? #{(subs (first strings) 0 l)}
(map #(subs % 0 l) (rest strings)))
(subs (first strings) 0 l)
(recur (dec l)))
""))))
(defn- spec-registered-keywords
[ns]
(eduction
(filter keyword?)
(filter #(= (str ns) (namespace %)))
(keys (s/registry))))
(defn- local-keyword-str
[kw]
(str "::" (name kw)))
(defn- local-keyword
"Returns foo for ::foo, otherwise nil"
[buffer]
(second (re-find #"::([a-zA-Z-]*)$" buffer)))
(defn- local-keyword-completions
[kw-name]
(let [kw-source (str "::" kw-name)]
(clj->js (into [kw-source]
(sequence
(comp
(map local-keyword-str)
(filter #(string/starts-with? % kw-source)))
(spec-registered-keywords @current-ns-eval))))))
(defn get-completions
"Returns an array of the buffer-match-suffix, along with completions for the
entered text. If one completion is returned the line should be completed to
match it (in which the completion may actually only be a longest prefix from
the list of candiates), otherwise the list of completions should be
displayed."
[buffer]
(if (nil? @st)
(with-meta [buffer] {:ready false})
(if-let [kw-name (local-keyword buffer)]
(local-keyword-completions kw-name)
(let [top-form? (re-find #"^\s*\(\s*[^()\s]*$" buffer)
typed-ns (second (re-find #"\(*(\b[a-zA-Z0-9-.<>*=&?]+)/[a-zA-Z0-9-]*$" buffer))]
(let [buffer-match-suffix (first (re-find #":?([a-zA-Z0-9-.<>*=&?]*|^\(/)$" buffer))
completions (sort (filter (partial is-completion? buffer-match-suffix)
(completion-candidates top-form? typed-ns)))
common-prefix (longest-common-prefix completions)]
(with-meta
(if (or (empty? common-prefix)
(= common-prefix buffer-match-suffix))
(into [buffer-match-suffix] completions)
[buffer-match-suffix common-prefix])
{:ready true}))))))

Large diffs are not rendered by default.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 38885d7

Please sign in to comment.