Fork me on GitHub
#joyride
<
2023-01-12
>
dangercoder17:01:30

Is it possible to use extensions.getExtension('myExtension') from joyride or is it only available when building vscode extensions?

dangercoder17:01:31

(.getExtension (.-extensions vscode) "myExtension")

borkdude17:01:18

(vscode/extensions.getExtension ..) should also work

pez17:01:31

Yes, that's how you do it. I'd use (vscode/extensions.getExtension "myExtension"). There is an example in the default user activate script. https://github.com/BetterThanTomorrow/joyride/blob/master/assets/getting-started-content/user/user_activate.cljs#L101

dangercoder17:01:06

awesome, thanks!

borkdude17:01:38

you'll even get auto-completions for vscode/ext.. and vscode/extensions.get...

metal 4
pez17:01:40

If this is not in an activation script you need it, @UBN9SNVB4, you can also use the special extension require syntax to get the extension's API. (ns ... (:require ["" :as my-extension])) There's an example here: https://github.com/BetterThanTomorrow/joyride/blob/master/examples/.joyride/scripts/joyride_api.cljs#L3

dangercoder19:01:01

is there a nifty way to find all public properties of a vscode extension? I tried via the repl but it always returns #js ["id" "extensionUri" "extensionPath" "packageJSON" "extensionKind" "isFromDifferentExtensionHost"]

pez19:01:34

This is a bit limited in Joyride. What public properties are you missing there?

dangercoder19:01:45

I expected e.g the joyride to show the joyride keys (e.g. isActive) when I tried to list all object keys

dangercoder19:01:55

I simply want to list all props for any extension which I can use to do stuff 😄

pez20:01:51

I don't know why isActive doesn't show with js-keys. Or, rather, why the object does not include it, which you can see if you try

(js/JSON.parse (js/JSON.stringify joy))
There's something special about some of the properties.

borkdude20:01:23

Maybe (js/Object.getOwnPropertyNames ..)?

pez20:01:25

Please file an issue about it, @UBN9SNVB4. I think there should be something we could do about it.

👍 2
pez20:01:18

getOwnProperties is what we use for completions, isn't it, @U04V15CAJ? In any case it shows the same as js-keys does.

borkdude20:01:16

I think so, check the impl if you want to be sure

pez21:01:31

Thanks! I think the behaviour of js-keys might be defined in a way that Joyride should not change. The problem rather is that we lack a way to see all properties.

borkdude21:01:49

it's not clear to me what the expected behavior is. what is the JS invocation with the expected output?

pez21:01:13

@U04V15CAJ. The node repl shows all the properties for these objects. The expected behaviour is that we can see them from the Joyride REPL somehow. At least that's what I am lacking.

dangercoder21:01:13

e.g. (.-isActive joyride) is not returned. But it's there.

borkdude11:01:55

but what is the equivalent JS invocation that does show these? joyride supports JS scripts now - is it possible to make a repro in .js that does work?

pez15:01:29

I can get the missing properties like so:

(ns joyride.js-completions
  (:require ["repl" :as node-repl]
            ["vscode" :as vscode]))

(comment
  (def !completions (atom []))
  (defn completions-cb [err result]
    (if err
      (js/console.error err)
      (reset! !completions (-> result js->clj first))))

  (def repl (.start node-repl))
  (def context (.-context repl))
  (unchecked-set context "ext" (vscode/extensions.getExtension "betterthantomorrow.joyride"))
  (defn complete [s]
    (.completer repl s completions-cb  context)
    @!completions)

  (complete "ext.") => ["ext.__proto__"
                        "ext.hasOwnProperty"
                        "ext.isPrototypeOf"
                        "ext.propertyIsEnumerable"
                        "ext.toLocaleString"
                        "ext.toString"
                        "ext.valueOf"
                        ""
                        "ext.activate"
                        "ext.constructor"
                        "ext.exports"
                        "ext.isActive"
                        ""
                        "ext.extensionKind"
                        "ext.extensionPath"
                        "ext.extensionUri"
                        "ext.id"
                        "ext.isFromDifferentExtensionHost"
                        "ext.packageJSON"]
  :rcf)

pez15:01:24

(I did this in the joyride source code, but should work in Joyride as well?)