anmonteiro / lumo

Fast, cross-platform, standalone ClojureScript environment
Eclipse Public License 1.0
1.88k stars 84 forks source link

Create new top-level function to describe REPL-capabilities #111

Open slipset opened 7 years ago

slipset commented 7 years ago

In working on http://github.com/clojure-emacs/inf-clojure I see that we need to take different code-paths depending on which REPL we're interacting with. example:

(defcustom inf-clojure-completion-form-lumo
  "(doall (map str (lumo.repl/get-completions \"%s\")))\n"
  "Lumo form to query inferior Clojure for completion candidates."
  :type 'string
  :package-version '(inf-clojure . "2.0.0"))

(defcustom inf-clojure-completion-form-planck
  "(planck.repl/get-completions \"%s\")\n"
  "Planck form to query inferior Clojure for completion candidates."
  :type 'string
  :package-version '(inf-clojure . "2.0.0"))

(defun inf-clojure-completion-form ()
  "Return the form to query inferior Clojure for a var's documentation.
If you are using REPL types, it will pickup the most approapriate
`inf-clojure-completion-form` variant."
  (pcase (inf-clojure--set-repl-type (inf-clojure-proc))
    (`lumo inf-clojure-completion-form-lumo)
    (`planck inf-clojure-completion-form-planck)
    (_ inf-clojure-completion-form)))

If each REPL had a function like capabilities, which delivered a map (or something) which described the capabilities of the REPL along with the functions to invoke for those capabilities, the life of tools like inf-clojure would be simpler.

https://github.com/mfikes/planck/issues/466

arichiardi commented 7 years ago

this is good, but then all the repls should agree on this protocol -- Sent from my Android device with K-9 Mail. Please excuse my brevity.

arichiardi commented 7 years ago

Great proposal from @cgrand on Slack:

(cond
  (find-ns 'lumo.repl) :lumo
  (find-ns 'planck.repl) :lumo
  :else :clj)
cgrand commented 7 years ago

Currently find-ns has undesirable side-effects. (See https://dev.clojure.org/jira/browse/CLJS-2088) This expression should be safe:

(cond
  (find-ns 'clojure.java.io) :clj
  (find-ns 'clojure.clr.io) :cljr
  (find-ns 'lumo.repl$macros) :lumo
  (find-ns 'planck.repl$macros) :planck
  (find-ns 'cljs.core$macros) :cljs-js
  (find-ns 'cljs.core) :cljs-jvm
  :else :unknown)