Fork me on GitHub
#joyride
<
2022-05-30
>
pez08:05:03

New Joyride out: https://github.com/BetterThanTomorrow/joyride/releases/tag/v0.0.13 It reduces the amount of boilerplate when consuming the exported API of an extension. See attached snippet for some code exercising the new require API. • Updated API docs: https://github.com/BetterThanTomorrow/joyride/blob/master/doc/api.md • Updated Calva Extension API wrapper example: https://github.com/BetterThanTomorrow/joyride/blob/master/examples/.joyride/scripts/z_joylib/calva_api.cljs

🎉 2
borkdude08:05:42

Looking good :)

borkdude08:05:44

@U0ETXRFEW I have an idea for this

(p/then (fn [v]
                (.appendLine oc (.-result v)))
stuff. Would it be an idea to be able to set *print-fn* to (.appendLine oc ....)?

borkdude08:05:22

Then you can just use:

(println v)

borkdude08:05:58

Or perhaps we can set prn / println by default to go to joyride's output channel? Bad idea?

borkdude08:05:04

Or ... joyride could offer a function for printing to the output channel 💡

borkdude08:05:18

joyride/prn + joyride/println

borkdude08:05:45

(p/then joyride/println)

pez08:05:22

I like the idea to make it a joyride.core facility. I think many shadow-cljs users will expect println to go to the console/the repl output.

borkdude08:05:40

joyride API function it is

pez08:05:04

The user space solution you suggested, can I do it without wrapping the code in binding stuff?

borkdude08:05:23

And people can do:

(binding [*print-fn* joyride/println] ...) 
in their scripts, yes

borkdude08:05:52

Yes, you can use alter-var-root to permanently set it

borkdude08:05:14

hmm, that might not work

borkdude08:05:23

anyway, we can make that work ;)

pez08:05:52

> hmm, that might not work clj-kondo complains 😃

Unresolved symbol: alter-var-rootclj-kondo(unresolved-symbol)
And also I get weird results:
ERROR: Run User Script... Failed: my_lib.cljs No protocol method IVar.getRawRoot defined for type function: function shadow$cljs$devtools$client$env$set_print_fns_BANG__$_repl_print_fn(s){
(msg_fn.cljs$core$IFn$_invoke$arity$2 ? msg_fn.cljs$core$IFn$_invoke$arity$2(new cljs.core.Keyword(null,"stdout","stdout",-531490018),s) : msg_fn.call(null,new cljs.core.Keyword(null,"stdout","stdout",-531490018),s));

if(cljs.core.truth_((function (){var and__4251__auto__ = original_print_fn;
if(cljs.core.truth_(and__4251__auto__)){
return cljs.core.not_EQ_.cljs$core$IFn$_invoke$arity$2(s,"\n");
} else {
return and__4251__auto__;
}
})())){
return (original_print_fn.cljs$core$IFn$_invoke$arity$1 ? original_print_fn.cljs$core$IFn$_invoke$arity$1(s) : original_print_fn.call(null,s));
} else {
return null;
}
}

borkdude08:05:26

You need to write (alter-var-root #'*print-fn* ...)

borkdude08:05:45

clj-kondo assumes that CLJS has no alter-var-root which is true for normal CLJS ;)

borkdude08:05:05

We can maybe hide this behind joyride.core/set-print-fn

seancorfield17:05:12

I updated my Joyride scripts in my vscode-calva-setup repo to take advantage of this simpler approach -- very nice!!

borkdude17:05:07

I was thinking that when the order becomes a problem, maybe the alias + refers could act lazily and will look themselves up in the extension on the first call. But so far I haven't heard a report that this was a problem.

borkdude17:05:24

order as in: joyride gets loaded before any other extension you are requiring

seancorfield19:05:53

☝️:skin-tone-2: Hmm, I hadn't considered that order of requires might be problematic... I like to keep mine strictly alpha order which would put all the string imports above the actual namespaces, and "ext://.." above "vscode"...

seancorfield19:05:39

(ns javadoc
  (:require ["$v0.repl" :refer [evaluateCode]]
            ["vscode" :as vscode]
            [clojure.edn :as edn]
            [clojure.string :as str]
            [promesa.core :as p]))
Are you saying there are potential problems doing ☝️:skin-tone-2: that @U04V15CAJ?

seancorfield19:05:09

(I'm not even requiring any joyride namespaces, I just realized)

borkdude19:05:56

@U04V70XH6 I don't know in what order joyride is loaded compared to calva. So if joyride is loaded first and this is in your activation script, the calva extension may not be there yet. The order in joyride scripts does not matter.

borkdude19:05:28

I'm still wondering if this is a problem or not, I'm not sure

seancorfield19:05:27

Ah, OK, then I won't worry. My activation script is pretty much empty. Does the activate.cljs even need to require "vscode", joyride.core, or promesa.core?

seancorfield19:05:01

(I've deleted everything except that :require for now)

borkdude19:05:55

I don't know what people will typically need in their activation scripts. But if you only load extension functions while everything is up and running, then there is nothing to worry about

pez19:05:39

So far I have never seen Calva not being loaded when Joyride runs the activate.cljs scripts. I recall something about that * activation event being necessary to stop VS Code from switching to the Joyride output channel. That * event is called StartUp in the VS Code docs. > The * activation event is emitted and interested extensions will be activated whenever VS Code starts up. Which is a bit confusing, because it seems to guarantee that Joyride will be active before most other extensions. At least those that are slower to start, which Calva is. https://code.visualstudio.com/api/references/activation-events#Start-up

pez19:05:29

We'll see if we run into problems or not with this. Maybe we should debug log from both Calva and Joyride at activation time to see what that gives. I could debug log from Paste Replace as well, since it is super lightweight and quick to start.

pez19:05:59

You don't need any activation script at all, @U04V70XH6, but you probably know that. 😃

seancorfield19:05:21

Yeah, but if there's no script, it'll create one, right? So I guess the minimal script to prevent that is (ns activate) 🙂

seancorfield19:05:06

I just wasn't sure if, in adding the auto-creation of activate.cljs, you were relying on Joyride actually executing it to set something up in Joyride itself these days.

borkdude20:05:16

I tried to talk @U0ETXRFEW out of auto-creating things and stealing focus of the output window but to no avail ;P

pez20:05:30

Yes, you're right, @U04V70XH6, a minimal script is needed to not trigger the Getting Started stuff.

pez20:05:19

We should probably create a more useful activate.cljs skeleton. Like the one in one of the examples.

pez20:05:41

Haha, @U04V15CAJ, you were the only one suggesting that, and since you are not a VS Code user anyway, it shouldn't be bothering you. 😃

pez20:05:35

@U04V70XH6, good that you also moved your use of evaluateCode to the repl submodule. I'll be getting rid of the top level one soon.

borkdude20:05:25

I don't think I was the only one suggesting that, but I could be wrong ;-)

borkdude20:05:57

https://github.com/BetterThanTomorrow/joyride/issues/65 Yeah, I just don't like tools that steal focus of other tools, I get a bit annoyed by it, even if you can turn it off. And it's not true that I'm not using VSCode, I do use it, just not as my primary editor.

pez20:05:15

Yes, some other people requested a way to turn it off, and we provided that. I think it's fine with one seldom-user who is still annoyed that he had to switch it off. 😃

seancorfield20:05:49

I think I complained about stealing focus? 🙂

pez20:05:24

Yes, you were one of the people asking for a way to turn it off.

seancorfield21:05:59

I wouldn't go so far as to say I was "annoyed" that I had to switch it off but, perhaps, "somewhat miffed"? :rolling_on_the_floor_laughing:

😆 1
borkdude21:05:15

Personally I would have taken that as a hint that people don't like that behavior by default, but we have different opinions and that's fine.

pez21:05:48

I see it as a trade-off. A demo and a getting-started point on one side, some miff/annoyance on the other.

borkdude21:05:33

I also see it as a trade-off but my trade-off would be on the side of not creating noise/files in a project. E.g. a link to examples in the output window (while not stealing focus, VSCode users know how to find that window?) would be another solution. But it's not a big deal, I can live with it ;)

seancorfield21:05:29

> VSCode users know how to find that window I don't think that's true for beginners. Heck, I open the output/log window so rarely I still go through the command palette because I can never remember the hot key! 🙂

pez21:05:37

To my experience tons of VS Code users do not know how to find output channels. Others do not realize they should look for it. I've had the output channel of Calva not default pop open for long periods enough not to consider going back to such a default again. A whole category of support questions are almost completely removed by the current default.

borkdude21:05:54

Fair enough

orestis05:05:41

Re not needing an activation script, don't I need one to require my library and use fn invocations in my commands?

orestis05:05:50

I prefer that to user scripts

pez05:05:32

@U7PBP4UVA I also prefer to invoke functions rather than scripts from my keyboard shortcuts. So that's a good use for the activation script for me too.

borkdude05:05:57

Why do you need an activation script for that?

pez05:05:16

So that something has required the namespace from where I invoke the functions. Like with this example: https://github.com/BetterThanTomorrow/joyride/tree/master/examples#restarting-clojure-lsp

borkdude05:05:28

I don't think you have to require namespaces ahead of time for this, they can be just in time loaded

orestis06:05:23

It would be possible if we could pass in a function as a namespaced symbol, then it could be required-resolved. Right now you pass a form to be evaluated. I don't know if sci supports require-resolve though?

borkdude06:05:23

It does right now, but when we move to async eval then require becomes async. Supporting a function symbol + args seems like a more robust approach

borkdude06:05:32

However if you take into account now that requiring-resolve becomes async, then you can also start using it now

borkdude06:05:36

But if you just write a top level require followed by the function expression this should work either way

pez06:05:36

Yes, if you also put the require in the shortcut, then that works as well.

orestis07:05:10

Ah, that's nice to know. I'll try out the new APIs and this later today.

pez07:05:33

I like to keep my shortcut definitions short, though, so adding (require ...) to all of them is not up my alley. 😃

borkdude07:05:10

A small price to pay when it comes to extension loading order troubles but whatever you fancy ;-) (and you can always migrate to explicit require later when you have such troubles)

pez11:05:15

This convenience require is just a small thing. But not being able to use extension APIs from my activate.cljs would be a big problem. Still haven't seen it happen, which is a bit strange.

seancorfield17:05:26

This has been a great thread! I think I might overhaul my current Calva/Joyride config to work more like a library that gets required in activate.cljs and switch over to the joyride.runCode approach, even for a lot of my custom REPL command snippets -- because it'll be easier to build complex code strings in Joyride/sci that just having big blobs in my settings.json file: https://github.com/seancorfield/vscode-calva-setup/blob/develop/settings.json#L217

seancorfield17:05:39

I guess it also makes it less likely that people's Joyride scripts will collide since they can be namespaced (I'll probably split mine up into seancorfield.test, seancorfield.portal, etc).

borkdude17:05:17

Yes, just note that requiring early vs requiring on demand may cause some friction with extension order. But you can deal with that when that happens

1
borkdude17:05:28

You could of course define a macro in your library code which requires just in time ;)