Fork me on GitHub
#joyride
<
2022-05-27
>
orestis08:05:10

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)))

orestis08:05:31

That yields:

orestis08:05:57

@U04V70XH6 perhaps something for you, with all your custom commands. Sometimes it's nice to browse 🙂

pez08:05:11

This is wonderful! @U04V15CAJ 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.

orestis08:05:49

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...

pez08:05:27

I wonder what the portal extension does...

pez08:05:38

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.

pez08:05:46

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

pez08:05:55

You beat me to it.

pez08:05:52

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

orestis08:05:04

Cool trick!

pez08:05:32

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 .

pez08:05:45

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

mauricio.szabo15:05:00

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?

pez16:05:31

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.szabo17:05:03

WOW, something is REALLY WEIRD!

mauricio.szabo17:05:30

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

pez19:05:55

Yeah, what could be going on there?

mauricio.szabo19:05:17

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.szabo19:05:08

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.szabo19:05:19

And Javascript needs to use return facepalm

pez20:05:19

Been there. Done that. 😀

mauricio.szabo01:05:18

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