alexander-yakushev / compliment

Clojure completion library that you deserve

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Unmunge" deftype field names

tsdh opened this issue · comments

When you have a Clojure type like

(deftype Foo [x-y] ...)

then (.x completes to (.x_y instead of (.x-y. That's because for a deftype a class is generated, and the field names of the class are the "munged" names of the deftype's fields, i.e., hypens are replaced with underscores.

In Clojure on the JVM, (.x_y foo) actually works but it relies on this very implementation detail and is not portable to the CLR or ClojureScript. Thus, it's better to use (.x-y foo) as this is the documented way to access fields of a deftype.

So it would be nice if CIDER could directly suggest the correct version when completing. The fact that can be exploited is that all classes (and only those) generated for a deftype implement clojure.lang.IType (see https://github.com/clojure/clojure/blob/master/src/clj/clojure/core_deftype.clj#L396). Therefore, I suggest to "unmunge" field names of classes implementing IType.

So everything that comes from deftype implements IType. Can we be reasonably sure that noone implements IType on their own?

Yes, we may assume that. IType is just a marker interface for exactly this purpose.

Yeah, that'd be nice.

Didn't even take 8 years 🎉