Fork me on GitHub
#vscode
<
2021-07-29
>
whacked02:07:50

has anybody played with webviews in vs code extensions with shadow-cljs / figwheel?

whacked02:07:13

I'm trying to get a browser repl connected to a vscode webview that runs shadow-cljs source

whacked02:07:56

I only have superficial knowledge of how the vscode extension scaffolding works, but it appears that it wants to load the js payload from a dynamically generated UUID. This is similar / same to how chrome/ff extensions work with some hashified resource locator inside the browser's own resource space. However, the UUID application also seems to rewrite the browser repl websocket server URL

whacked02:07:46

in other words when you set up a browser repl, an injected <ws://localhost:9630/api/remote-relay>... becomes <ws://some-long-uuid-string:9630/api/remote-relay>...

whacked02:07:43

If you have worked through this before, I'd be grateful for some pointers!

whacked03:07:14

Got it. The answer is to explicitly set :devtools-url inside the :devtools map for the shadow-cljs build configuration. When not set, it will derive the URL from a dynamic function call (`shadow.cljs.devtools.client.env.get_ws_relay_url`). I didn't look deeper but I am guessing the dynamic URL picks up host (in this case, vs-code-wrapped) information for the websocket server address, and adding the explicit setting probably forces it to be a string constant

whacked03:07:00

I hope this setup will allow faster vs code extension development. Set up the main extension instance to connect via cljs repl (https://github.com/Saikyun/cljs-vscode-extension-hello-world is a good guide). Then for webviews, with the configuration above, you can set up hot reload / browser-repl.