-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add preview API #813
Merged
Merged
Add preview API #813
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jjallaire
approved these changes
Jul 1, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sufficiently conversant in the internals to really comment, but in any case LGTM.
After this is merged here are the outstanding would allow me to ship the Quarto extension to the marketplace w/ Positron support:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change adds an API, service, and user interface for Positron's Preview panel.
The Preview API is modeled closely after VS Code's existing
WebviewPanel
API. Rather than try to co-opt that API to work in the Preview pane, which would have involved a lot of internal changes to VS Code's API to add new types and special cases, I've chosen to implement our own parallel API so we can discard the irrelevant options and add preview-specific logic.Though we have our own
PreviewPanel
class, the actualWebView
inside the panel that hosts the content is not a special Positron type; it is a standard VS CodeWebView
. This makes thePreviewPanel
a sort of cousin of several other APIs that handle webviews.Because Positron's API and VS Code's API are completely separate, getting them to use the same backend for WebViews was challenging. This PR takes the (possibly controversial) approach of punching a hole in the
RpcProtocol
--getRaw()
-- that allows Positron's API to extract the actors created when VS Code's API initializes.The user interface uses React, like our other view panes do, with hooks to repaint the pane when previews are opened/closed. Because you can't really attach/detach a WebView without losing content and state, we rely on VS Code's
IOverlayWebview
, which effectively paints the webview on top of an existing DOM element using absolute positioning. This, unfortunately, requires us to redraw the preview container every time its size or position changes.Note that the Preview service lives in
/contrib/
since it interacts heavily with webviews (which are also a contrib).The Preview API includes some interactive demos you can run from the Zed console. Here are the new commands:
preview open
will open the Preview pane.preview show
will reveal the Preview pane if it is currently closed.preview status
will show the current status of the preview, including whether there is currently a preview and whether it is visible.preview close
will close the preview if it's open.preview message
will send a postMessage to the preview pane, which will appear in the pane itself.