Fork me on GitHub
#cursive
<
2022-04-03
>
kwladyka14:04:52

How to use Clojure to get hints for java interops? For example in java:

kwladyka14:04:39

Can I make it to show me the same what in pure Java? It will be so useful.

cfleming23:04:31

You’re comparing two different things there. One is the completion list for static methods, you can get that like this:

cfleming23:04:55

That looks pretty similar to me, one thing that is missing is types of fields, I can fix that.

cfleming23:04:45

Instance method completion can be obtained as you show in your example:

cfleming23:04:32

Here’s the equivalent in Java, which also looks pretty similar to me:

cfleming23:04:49

I wrote a bit about what’s required for Cursive to be able to do this completion here: https://clojureverse.org/t/analyzing-java-sources-class-files-using-javaparser-or-javap/8131/22?u=colinfleming. It hasn’t made it into the doc yet, unfortunately.

kwladyka07:04:14

Thank you. I have to catch better moment. Just sometimes it shows invalid hints and not show valid. But I don’t know how it works.

cfleming07:04:29

Ok, if you see anything invalid I’d definitely like to see it.

kwladyka22:04:29

Is a way to jump to the code .toEpochMilli (.toEpochMilli (first-timestamp-to-sync-db "HNT" "BUSD")) ? If I add type somewhere?

kwladyka22:04:56

also to show .toEpochMilli as a hint during typing?

cfleming09:04:32

.toEpochMilli needs to know what the type of the receiver is, in this case that’s (first-timestamp-to-sync-db "HNT" "BUSD"). There are two things that need to happen, first-timestamp-to-sync-db needs its return type hinted so that Cursive (and Clojure) knows what type it will return, and then you need to use one of the forms I discuss in the ClojureVerse thread to ensure that the receiver is present when completing the method.

kwladyka14:04:34

this is simple example, but sometimes classes are nested and editor doesn’t help at all

kwladyka14:04:27

sometime it works, sometimes not. I am not sure when, but I have constantly issues with this.