cursive-ide / cursive

Cursive: The IDE for beautiful Clojure code
581 stars 7 forks source link

Automatic type hinting #1504

Open danielcompton opened 8 years ago

danielcompton commented 8 years ago

It would be handy if Cursive could flow types through from simple expressions into their call sites, e.g.

screenshot of intellij idea 25-08-16 10-56-02 am

I can think of a few possibilities here:

  1. Cursive automatically detects types and resolves them automatically, but reflection happens at runtime.
  2. Cursive detects types from simple expressions, and when they are being used in interop and causing reflection issues, offers a quick-fix to add a type hint at the root definition.

A related but separate issue is that a lot of the errors we get in our CLJS apps are when we deref what we think is a Reagent Reaction, but it has already been dereffed further up the call hierarchy. Having type checks like "is this var IDerefable?" when derefing would catch quite a few bugs for us.

EDIT: another common bug is mixing up maps and keywords the in functions like update, assoc, get e.t.c.

danielcompton commented 8 years ago

From Slack by @cursive-ide:

@danielcompton: Cursive actually already does flow that info, but currently models what Clojure does, and Clojure doesn’t automatically add a tag to def based on the type of a simple expression. Cursive could retain that info and prompt to add a hint, as you suggest.