babashka-sci-dev

flowthing 2022-09-11T11:49:16.793859Z

Would it be possible for Babashka to expose a list of the classes/interfaces it supports somehow? Basically the equivalent of (concat (keys babashka.impl.classes/base-custom-map) babashka.impl.classes/java-net-http-classes (:all babashka.impl.classes/classes)) or something along those lines. Or does it already?

borkdude 2022-09-11T11:51:14.210369Z

you mean programmatically?

flowthing 2022-09-11T11:51:21.431919Z

Yes.

borkdude 2022-09-11T11:51:40.366469Z

clojure supports (ns-imports *ns*) which bb does too, but this doesn't give you everything. so I think we'd have to invent something custom for it, right?

flowthing 2022-09-11T11:52:24.069269Z

I think so, yeah. With Clojure, I use java.lang.module.ModuleFinder to list all Java base classes/interfaces etc. So I’m looking for something similar here.

borkdude 2022-09-11T11:52:31.584809Z

babashka.classes/all-classes or so?

flowthing 2022-09-11T11:52:41.406509Z

Yes, something like that.

borkdude 2022-09-11T11:53:34.314109Z

we could also expose the reflection config json which is already part of the resources

borkdude 2022-09-11T11:53:52.657849Z

which would be the most accurate way since it reflects what is available in bb

flowthing 2022-09-11T11:54:09.814219Z

Indeed. 👍

borkdude 2022-09-11T11:54:41.515339Z

this is pretty easy to do, just add the resource as a built-in similar to how it's done in clj-kondo

borkdude 2022-09-11T11:54:56.499719Z

clj-kondo has several built-in transit files

flowthing 2022-09-11T11:56:29.948829Z

Cool. 👍 This wouldn’t affect binary size, either, since reflection.json is already baked in, but how about memory use? I’m guessing not?

borkdude 2022-09-11T12:02:28.774379Z

yes, and also the accompanying graal settings

flowthing 2022-09-11T12:03:59.933249Z

> reflection config json which is already part of the resources So can I already access that JSON file somehow in the current Babashka version?

borkdude 2022-09-11T12:10:58.965449Z

no, you need to expose the json file as part of the binary, like in clj-kondo

borkdude 2022-09-11T12:11:34.676049Z

not everything in the classpath is automatically included in the binary

borkdude 2022-09-11T12:13:58.049929Z

and probably we have to tweak the io/resource implementation also a bit to fall back on the clojure version of io/resource

flowthing 2022-09-11T12:21:49.150969Z

I see. 👍

flowthing 2022-09-11T12:22:54.114759Z

I can give that a shot locally.

flowthing 2022-09-11T12:23:21.184499Z

See if that’ll give me everything I need.

flowthing 2022-09-11T17:54:59.633559Z

Simply exposing babashka.impl.classes/all-methods would actually give me all I need, I think. Of course, I don’t know whether that makes for a sensible API. Could also add a wrapper that just does (map (fn [{:keys [class name]}] (symbol (.getName class) name)) (babashka.classes/all-methods)) to get a list of fully-qualified symbols.

flowthing 2022-09-11T17:56:22.502669Z

So it’s all there already, would just need to figure out an API that makes sense and expose it.

borkdude 2022-09-11T17:57:40.276269Z

do you mean all-classes?

flowthing 2022-09-11T17:59:43.381259Z

No, all-methods. That way I could offer auto-completion for those (and only those) methods Babashka actually supports.

flowthing 2022-09-11T18:00:25.800319Z

I’ll take the “fully-qualified symbol” suggestion above back, though — that only makes sense for static methods.

flowthing 2022-09-11T18:01:13.442229Z

Hmm, except that I would also need a way to distinguish between static and instance methods…

flowthing 2022-09-11T18:01:38.271999Z

Well, that should be doable, too.

flowthing 2022-09-11T18:02:00.168829Z

I’ll look into it some more.

borkdude 2022-09-11T18:04:47.395279Z

all-methods doesn't make sense to me

borkdude 2022-09-11T18:05:00.831589Z

if I give you all classes, you can derive all methods from that

borkdude 2022-09-11T18:05:31.855529Z

I think for now you could just make a one-one snapsnot of all classes in bb and keep that around in your tool?

flowthing 2022-09-11T18:35:32.069509Z

> if I give you all classes, you can derive all methods from that Right, that’s true. 👍

flowthing 2022-09-11T18:35:44.788129Z

> I think for now you could just make a one-one snapsnot of all classes in bb and keep that around in your tool? Yes, that’s the plan.

flowthing 2022-09-11T18:37:21.225749Z

> if I give you all classes, you can derive all methods from that > Except that that will also return methods Babashka doesn’t actually support, right? (Not that this is necessarily a problem — I’m not sure yet which I’d prefer, to be honest.)