joyride

orestis 2022-05-27T08:18:10.647979Z

Here's something I really enjoy:

(def custom-commands
  #js [#js {:label "Send Last Eval to Portal" :fn send-last-eval-to-portal}
       #js {:label "Evaluate top-level form to Portal" :fn send-toplevel-form-to-portal}
       #js {:label "Evaluate current form to Portal" :fn send-current-form-to-portal}
       #js {:label "Open Portal" :fn open-portal}
       #js {:label "Ensure Portal Open" :fn ensure-portal-open}
       #js {:label "Restart LSP" :fn restart-clojure-lsp}
       #js {:label "Say Hi" :fn #(info "Hi!")}])


(defn show-my-commands []
  (p/let [command (vscode/window.showQuickPick
                   custom-commands
                   #js{:title "Select a custom command"})]
    ((.-fn command)))

orestis 2022-05-27T08:18:31.757169Z

That yields:

orestis 2022-05-27T08:18:57.918499Z

@seancorfield perhaps something for you, with all your custom commands. Sometimes it's nice to browse πŸ™‚

pez 2022-05-27T08:27:11.827719Z

This is wonderful! @borkdude and I have discussed if we should provide some way to config things like this. Solving it in user space is awesome for now. If we one day want to add it to Joyride we will have different approaches to learn from.

orestis 2022-05-27T08:29:49.718069Z

Well sure I'd like to not have a custom keybinding for this πŸ™‚ The portal extension does something clever where it registers commands dynamically, so you can presumably eval the user/workspace activate scripts, and if I provide you with commands via an API, add them to the top-level command menu under Joyride:User...

pez 2022-05-27T08:31:27.270429Z

I wonder what the portal extension does...

pez 2022-05-27T08:33:38.730079Z

Calva does something for custom REPL command snippets, that I originally was planning to use for Joyride as well. In Calva we ”book bindings ahead”, a ton of them. Then the user can choose from those bindings when configuring snippets.

orestis 2022-05-27T08:35:44.957329Z

Hm, or does that have to be matched statically with https://github.com/djblue/portal/blob/master/extension-vscode/package.json ?

pez 2022-05-27T08:35:46.646939Z

Yes, but the command id still needs to be present in the extension manifest. Only the registration is dynamic. Afaiut.

pez 2022-05-27T08:35:55.737389Z

You beat me to it.

orestis 2022-05-27T08:35:59.801789Z

πŸ˜„

pez 2022-05-27T08:37:52.227989Z

See https://github.com/BetterThanTomorrow/calva/blob/dev/package.json#L2308 and some 300 lines for the crazy thing Calva does.

orestis 2022-05-27T08:40:04.572389Z

Cool trick!

pez 2022-05-27T08:46:32.815719Z

Before I employed that trick, what I did was to prefix commands automatically with the key. So then it would be almost like chord. If you add :key to your config structure there and prefix with it. Then you can use the shortcut you bind for bring up the menu, say cmd+f4, followed by typing the key, followed by enter. If the key is a, it becomes cmd+f4 a enter. Or the key slep for Send Last Eval to Portal, you would render it as slep: Send Last Eveal to Portal, and use it like cmd+f4 s l e p enter .

pez 2022-05-27T08:47:45.479639Z

In fact with the fuzzy search you often won't need a key like slep. The same ”chord” will do it anyway.

mauricio.szabo 2022-05-27T15:52:00.870169Z

Hey, @pez, a little help here if possible? I'm trying to make Clover play better with Joyride, but for some reason clover.exports is always nil. Do I need to do something special to export commands?

pez 2022-05-27T16:23:31.486779Z

You need to return the api in the activate function. So something like

(defn activate [context]
  ...
  {:fn1 fn1
   :fn2 fn2})
I think should work.

mauricio.szabo 2022-05-27T17:14:03.561779Z

WOW, something is REALLY WEIRD!

mauricio.szabo 2022-05-27T17:14:30.260119Z

First is logging with prn, second is with console.log

pez 2022-05-27T19:35:55.771439Z

Yeah, what could be going on there?

mauricio.szabo 2022-05-27T19:55:17.266099Z

It seems that if I try to log things that are functions it does not work. And no matter what I do, it does not expose any exports 😞

mauricio.szabo 2022-05-27T19:56:08.573059Z

Oh, wait... I got way sidetracked for the js/console.log issue that I forgot that I'm not exposing the ClojureScript code as the plug-in, I'm exposing a Javascript code that calls ClojureScript

mauricio.szabo 2022-05-27T19:56:19.906749Z

And Javascript needs to use return facepalm

pez 2022-05-27T20:42:19.461799Z

Been there. Done that. πŸ˜€

mauricio.szabo 2022-05-28T01:52:18.624379Z

By the way, I have no idea on why console.log does not print the keys when the values are functions, but anyway, it's working now! Thanks for the help!

πŸ™ 1