Coder Social home page Coder Social logo

vs-code-preview-html's Introduction

vs-code-preview-html

This is a demo to see what is possible with respect to extending VS Code with custom UI. This is a simple extension that inserts custom UI in an editor pane by doing the following:

  • Starts a WebSocketServer on an ephemeral port when the extension is activated.
  • Once the server is initialized, the extension finds out which port is being used and creates a TextDocumentContentProvider that returns custom HTML with the port number embedded in it.
  • We call vscode.previewHtml with a URI that is associated with our TextDocumentContentProvider.
  • An embedded pane is loaded with our HTML, which loads some JavaScript that creates a new WebSocket that connects to the WebSocketServer.

Once this connection is established, the unprivileged, embedded pane can make requests to the privileged extension host. Using this mechanism, it seems like we can define a protocol on this channel that enables RPCs, registering subscriptions, etc.

Notable Drawbacks

  • The only place we can add UI to VS Code is in one of these editor panes. We cannot, for example, add a pane to the bottom of the window like the debug console or a dialog like the command palette.
  • Although sandboxing my UI should make VS Code overall more performant, it is certainly inconvenient being unable to share memory between the extension host and the embedded pane. All data must be serialized/deserialized between the two.
  • I could not develop this extension using Flow. I wasn't keen to use TypeScript, so I ended up sticking to raw JavaScript.

vs-code-preview-html's People

Contributors

bolinfest avatar

Stargazers

Stefan Goessner avatar Will Binns-Smith avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

hansonw

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.