Is it possible to call a function within the VS Code Live Preview Extension from my own extension to begin serving a new root without adding a folder to VS Code's workspace? If so, is it also possible to call a function within the VS Code Live Preview Extension from my extension to launch an in-VS Code browser to a file under that new root?

What I'm trying to do:

I have been doing a LOT of Rust programming recently. The Rust distribution includes rustdoc which pulls comments out of Rust source code and converts those to documentation which is then automatically published on docs.rs (among many other ways those docs are used). The more I work on those docs, the more it bothered me that I have to switch between VS Code, a command prompt to fire off cargo doc, and an external browser to view the results. What I want is to be able to click a button above the Rust file I am editing to have it open a preview of the rustdocs to the right in VS Code.

What I've tried so far:

I wrote a quick VS Code extension that fires off cargo doc either by a manual command, whenever a Rust file is saved, or upon any change to a Rust file (user configurable). I then created a webview within my extension and was able to display the generated rustdoc preview...but all of the images, CSS files, and the like fail to load.

enter image description here

From doing a lot of reading in VS Code's API documentation, it appears this is an intentional limitation of webviews to prevent access to files on the local filesystem. While there are ways around it by specifying every directory that files might be shared from, that sounds like a very brittle solution that would break any time my generated rustdocs create a different directory for one or more of the linked to files.

My current thinking:

I feel like I'm reinventing the wheel. The Live Server, Five Server, and Live Preview extensions all create a web server in the background that can be viewed as a preview from within VS Code. Rather than me continuing to bash my head against this problem... Can I use one of those three extensions from within my extension to start a web server with the root at <project folder>\target\doc and then also use one of those extensions to open a browser preview of a file at <project folder>\target\doc\<package name>\index.html?

I already know I can require another extension from within my extension by adding that extension to my extenson manifest under extensionDependencies. I'm just diving into the code of those extensions and feeling more than a little buried as far as how to call into them. VS Code's API docs state that the activate function can return an API to allow other extensions to call some of it's functionality, but it doesn't look like any of those three extensions did that so I'll be left using back doors into them if I can use them at all.

I also found I can call any commands that another extension pushes with vscode.commands.executeCommand but that still leaves me reading the code of those extensions to try to figure out what to call and what parameters to pass and since it doesn't appear that any of them were intended to be used this way, there doesn't appear to be much in the way of documentation.

Thank you in advance for pointing me in the right direction on this one. If I get this working, I'm hoping to eventually contribute it to something like rust-analyzer so no one else needs to reinvent this wheel.

0

There are 0 answers