Skip to content

Complete local bindings for ClojureScript files #766

@iarenaza

Description

@iarenaza

Expected behavior

When editing a ClojureScript file, CIDER-based completion offers local binding names (the function name and argument names if inside the function, the let-like block bindings if inside a let-like block, etc). Just like it happens when editing a Clojure file.

Actual behavior

It doesn't offer any local binding names as completion candidates. The root of the problem is that cider.nrepl.middleware.complete/cljs-sources only includes ::suitable-sources/cljs-source as a possible source. And suitable doesn't perform any local binding analysis.

But given that the local binding analysis done in compliment.sources.local-bindings namespace doesn't perform any evaluation or execution of the context form (thus it's independent of the actual host platform differences), we can use that same source for ClojureScript local bindings completion. I have tested it locally and it works as expected, without any side effects.

I have a pull request that I will attach in a few minutes implementing the suggested feature.

Steps to reproduce the problem

Create a ClojureScript REPL using you favorite technology (figwheel-main, shadow-cljs, etc), and connect to it. Enable completion in CIDER following the documentation. Make sure you don't have lsp completion enabled (this could mess with CIDER completion).

Once connected, open a .cljs (or .cljc) file and type the following form. Place the cursor where the '|' character is in the form below:

(let [foobar "foobar"
      foobaz "foobaz"]
  |
)

Start typing 'fooba'. The autocompletion feature should offer you both foobar and foobaz as completion candidates (and tell you their kind, that they are variables in this case). But it doesn't (it does in this is a .clj file, and you have an active Clojure REPL connection).

Environment & Version information

CIDER version

1.6.0

cider-nrepl version

0.29.0

nREPL version

1.0.0

Java version

openjdk version "17.0.4" 2022-07-19
OpenJDK Runtime Environment Temurin-17.0.4+8 (build 17.0.4+8)
OpenJDK 64-Bit Server VM Temurin-17.0.4+8 (build 17.0.4+8, mixed mode, sharing)

Operating system

Debian GNU/Linux Bullseye

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions