cursive-ide / cursive

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

Add resolution for shadow.cljs.modern/defclass #2908

Open danielcompton opened 4 months ago

danielcompton commented 4 months ago

We're using Shadow-CLJS's modern/defclass for creating JS classes. In Cursive, the resolution doesn't quite work and so we get a lot of underlines in our code.

Would it be possible to add a custom resolution for this class? It is pretty close to deftype and extend-protocol, the main difference is that it has extends, field, and constructor which are defined without a protocol.

https://clojureverse.org/t/modern-js-with-cljs-class-and-template-literals/7450

(m/defclass Example
  (extends a-library/Thing)

  ;; fields don't need to match constructor args
  ;; and can have default values, initialized automatically
  ;; in the constructor, without default they need to be
  ;; set! or they'll default to undefined
  (field foo)
  (field bar "default value")

  (constructor [this some arg]
    (let [x (+ some arg)]
      (super x "something")
      (set! foo (calculate-something this x))))

  ;; for uses from within CLJS
  ;; just like extend-protocol/extend-type
  AProtocol
  (example-fn [this a b]
    (str foo bar a b))

  ;; for when a library will call thing.jsLibraryMethod(x)
  ;; and you are supposed to give it a thing implementing that
  Object
  (jsLibraryMethod [this x]
    foo))
Screenshot of IntelliJ IDEA at 23 May 2024 at 10_35_54 PM