All Projects → rksm → Clj Suitable

rksm / Clj Suitable

Licence: mit
ClojureScript "IntelliSense" support for JS objects and their properties/methods. Via figwheel and Emacs CIDER.

Programming Languages

clojure
4091 projects
clojurescript
191 projects

Projects that are alternatives of or similar to Clj Suitable

Spiral
Emacs Clojure IDE based on UNREPL
Stars: ✭ 146 (+78.05%)
Mutual labels:  emacs, repl
ui5-schemas
🚀 UI5 Schemas allows you to develop SAPUI5/OpenUI5 XML at a maximum convenience. It downloads, upgrades and sets up SAPUI5/OpenUI5 XML schemas for a better development experience in your favorite IDE (if it is WebStorm ;).
Stars: ✭ 50 (-39.02%)
Mutual labels:  intellisense, code-completion
Nodejs Repl.el
Run Node.js REPL and communicate with the process
Stars: ✭ 163 (+98.78%)
Mutual labels:  emacs, repl
Eval In Repl
Consistent ESS-like eval interface for various REPLs
Stars: ✭ 130 (+58.54%)
Mutual labels:  emacs, repl
Figwheel Main
Figwheel Main provides tooling for developing ClojureScript applications
Stars: ✭ 514 (+526.83%)
Mutual labels:  tooling, repl
Nox
Nox is a lightweight, high-performance LSP client for Emacs
Stars: ✭ 181 (+120.73%)
Mutual labels:  code-completion, emacs
Crane
PHP Intellisense/code-completion for VS Code
Stars: ✭ 236 (+187.8%)
Mutual labels:  intellisense, code-completion
scope-capture-nrepl
nREPL middleware for scope-capture
Stars: ✭ 27 (-67.07%)
Mutual labels:  tooling, repl
Scope Capture
Project your Clojure(Script) REPL into the same context as your code when it ran
Stars: ✭ 392 (+378.05%)
Mutual labels:  tooling, repl
Dcd
The D Completion Daemon is an auto-complete program for the D programming language
Stars: ✭ 310 (+278.05%)
Mutual labels:  intellisense, code-completion
Vscode Intelephense
PHP intellisense for Visual Studio Code
Stars: ✭ 872 (+963.41%)
Mutual labels:  intellisense, code-completion
Robe
Code navigation, documentation lookup and completion for Ruby
Stars: ✭ 525 (+540.24%)
Mutual labels:  code-completion, emacs
Indium
A JavaScript development environment for Emacs
Stars: ✭ 1,058 (+1190.24%)
Mutual labels:  emacs, repl
Gistlyn
Run Roslyn Gists
Stars: ✭ 75 (-8.54%)
Mutual labels:  repl
Emacs Sql Indent
Syntax based indentation for SQL files inside GNU Emacs
Stars: ✭ 78 (-4.88%)
Mutual labels:  emacs
Boot Cljs Repl
Boot task providing a REPL for ClojureScript development.
Stars: ✭ 74 (-9.76%)
Mutual labels:  repl
Eziam Theme Emacs
A mostly grayscale theme for Emacs, inspired by Tao and Leuven.
Stars: ✭ 74 (-9.76%)
Mutual labels:  emacs
Omnia
Stars: ✭ 81 (-1.22%)
Mutual labels:  repl
Hexo.el
Use Hexo in Emacs elegantly
Stars: ✭ 78 (-4.88%)
Mutual labels:  emacs
Openwhisk Cli
Apache OpenWhisk Command Line Interface (CLI)
Stars: ✭ 73 (-10.98%)
Mutual labels:  tooling

suitable - ClojureScript Completion Toolkit

Clojars Project

suitable provides static and dynamic code completion for ClojureScript tools.

It integrates a) with the CLJS analyzer and using the compilation state for "static" symbol completion. This functionality was formerly part of compliment.

It b) can use a CLJS repl session to query and inspect JavaScript runtime state, allowing code completion for JavaScript objects and interfaces.

TODO: describe static completion / compliment feature

Dynamic code completion for CLJS repls

The dynamic code completion features allow for exploratory development by inspecting the runtime. For example you work with DOM objects but can't remember how to query for child elements. Type (.| js/document) (with | marking the postion of your cursor) and press TAB. Methods and properties of js/document will appear — including querySelector and querySelectorAll.

Dynamic code completion: BE AWARE OF THE SIDE EFFECTS

The dynamic code completion evaluates code on completion requests! It does this by trying to enumerate the properties of JavaScript objects, so in the example above it would fetch all properties of the js/document object. This might cause side effects: Even just reading property values of an object can run arbitrary code if that object defines getter functions.

Moreover, also chains of methods and properties will be evaluated upon completion requests. So for example, asking for completions for the code / cursor position (-> js/some-object (.deleteAllMyFilesAndStartAWar) .|) will evaluate the JavaScript code some-object.deleteAllMyFilesAndStartAWar()! This only applies to JavaSript interop code, i.e. JavaScript methods and properties. Pure ClojureScript is not inspected or evaluated. Please be aware of this behavior when using the dynamic code completion features.

Dynamic completion Demo

The animation shows how various properties and methods of the native DOM can be accessed (Tab is used to show completions for the expression at the cursor):

Setup

figwheel.main with rebel-readline

Please note that you need to use rebel-readline with figwheel for that to work. Plain repls have no completion feature.

Tools CLI

First make sure that the normal Tools CLI setup works.

Then modify deps.edn and dev.cljs.edn, you should end up with the files looking like below:

  • deps.edn
{:deps {com.bhauman/figwheel-main {:mvn/version "RELEASE"}
        com.bhauman/rebel-readline-cljs {:mvn/version "RELEASE"}}
 :paths ["src" "resources" "target"]
 :aliases {:suitable {:extra-deps {org.rksm/suitable {:mvn/version "RELEASE"}}
	              :main-opts ["-e" "(require,'suitable.hijack-rebel-readline-complete)"
                                  "-m" "figwheel.main"
                                  "--build" "dev" "--repl"]}}}
  • dev.cljs.edn
{:main example.core
 :preloads [suitable.js-introspection]}
  • src/example/core.cljs
(ns example.core)

You can now start a figwheel repl via clj -A:suitable and use TAB to complete.

leiningen

First make sure that the normal leiningen setup works.

Add [org.rksm/suitable "0.3.5"] to your dependencies vector.

Then you can start a repl with lein trampoline run -m suitable.figwheel.main -- -b dev -r

Emacs CIDER

Suitable is now a default middleware in CIDER (as of CIDER 0.22.0)! So no extra installation steps are required.

Custom nREPL server

To load suitable into a custom server you can load it using this monstrosity:

clj -Sdeps '{:deps {cider/cider-nrepl {:mvn/version "0.22.0"} cider/piggieback {:mvn/version"0.4.1"}}}' -m nrepl.cmdline --middleware "[cider.nrepl/cider-middleware,cider.piggieback/wrap-cljs-repl]"

Or from within Clojure:

(ns my-own-nrepl-server
  (:require cider.nrepl
            cider.piggieback
            nrepl.server))

(defn start-cljs-nrepl-server []
(let [middlewares (conj (map resolve cider.nrepl/cider-middleware)
                        #'cider.piggieback/wrap-cljs-repl)
      handler (apply nrepl.server/default-handler middlewares)]
  (nrepl.server/start-server :handler handler))

shadow-cljs + cider

Please see issue #2.

How does it work?

suitable uses the same input as the widely used compliment. This means it gets a prefix string and a context form from the tool it is connected to. For example you type (.l| js/console) with "|" marking where your cursor is. The input we get would then be: prefix = .l and context = (__prefix__ js/console).

suitable recognizes various ways how CLJS can access properties and methods, such as ., .., doto, and threading forms. Also direct global access is supported such as js/console.log. suitable will then figure out the expression that defines the "parent object" that the property / method we want to use belongs to. For the example above it would be js/console. The system then uses the EcmaScript property descriptor API to enumerate the object members. Those are converted into completion candidates and send back to the tooling.

License

This project is MIT licensed.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].