Skip to content
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

[rfc] Show readonly Editor Before Server Is Started #1306

Merged
merged 2 commits into from
Feb 23, 2024
Merged

Conversation

rholinshead
Copy link
Contributor

@rholinshead rholinshead commented Feb 23, 2024

[rfc] Show readonly Editor Before Server Is Started

[rfc] Show readonly Editor Before Server Is Started

Currently when opening an aiconfig file, the file contents / editor webview are not rendered at all until the server is started (or attempted to start). This is because the webview isn't rendered until resolveCustomTextEditor returns, and we are awaiting a few server-initialization-related calls within the function.

To fix, we can move the startEditorServer into a regular .then, which will call the Promise without blocking. Within the .then we can handle the resolved promise as normal and do the other things that depend on the server process running.

Another thing worth mentioning is that we previously required the server url to set up the csp for the webview HTML. I'm not sure if we actually need to set the connect-src vscode-webview at all (didn't seem to make a difference when testing) but for now, just setting to accept any localhost port instead of being dependent on server.

We can immediately set the webview content and see it rendered (in readonly mode by default):

Screen.Recording.2024-02-22.at.9.20.20.PM.mov

NOTE: This currently results in a notification, 'Error loading models' since the (readonly) editor is attempting to load the models before the server is set up. There is a simple fix needed in the editor to address that, so I'll do that and update the package for use in the vscode extension before landing this


Stack created with Sapling. Best reviewed with ReviewStack.

Copy link
Contributor

@saqadri saqadri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! The flow makes sense to me. We can test it out tomorrow.

this.startEditorServer(document).then(async (editorServer) => {
editorServer = editorServer;

this.aiconfigEditorManager.addEditor(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine, but might be worth having an update when an editor server is created for aiConfigManager to update its state. Because technically aiConfigManager should keep track of all open editors irrespective of the server.

Not blocking for this diff since this is the same functionality as before


// Start the AIConfig editor server process. Don't await at the top level here since that blocks the
// webview render (which happens only when resolveCustomTextEditor returns)
this.startEditorServer(document).then(async (editorServer) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a .error as well? Ideally with some kind of retry?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can also be future diffs

@@ -579,7 +575,7 @@ export class AIConfigEditorProvider implements vscode.CustomTextEditorProvider {
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data: http: https: 'self'; media-src data: http: https: 'self'; connect-src vscode-webview: ${editorServer.url} http: https:; style-src 'unsafe-inline' ${webview.cspSource} https://cdn.jsdelivr.net/npm/[email protected] https://cdn.jsdelivr.net/npm/[email protected]/min/vs/editor/editor.main.css; script-src 'nonce-${nonce}' vscode-resource: https: http: https://cdn.jsdelivr.net/npm/[email protected] https://cdn.jsdelivr.net; font-src https://cdn.jsdelivr.net/npm/[email protected]/min/vs/base/browser/ui/codicons/codicon/codicon.ttf; worker-src blob:;">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data: http: https: 'self'; media-src data: http: https: 'self'; connect-src vscode-webview: http://localhost:* http: https:; style-src 'unsafe-inline' ${webview.cspSource} https://cdn.jsdelivr.net/npm/[email protected] https://cdn.jsdelivr.net/npm/[email protected]/min/vs/editor/editor.main.css; script-src 'nonce-${nonce}' vscode-resource: https: http: https://cdn.jsdelivr.net/npm/[email protected] https://cdn.jsdelivr.net; font-src https://cdn.jsdelivr.net/npm/[email protected]/min/vs/base/browser/ui/codicons/codicon/codicon.ttf; worker-src blob:;">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ok, I vaguely remember running into CSP issues for the server but maybe that was a different issue. Makes sense to leave it for localhost but also feel free to remove if we want to try that out

rholinshead added a commit that referenced this pull request Feb 23, 2024
# [editor][ez] Don't Fetch Models in ReadOnly

Surfaced from error in
#1306; currently we're
attempting to load the models when a getModels callback is provided,
even if the editor is readOnly. If it's readOnly, there's no model
selector to show so no need to fetch the models

## Before:
![Screenshot 2024-02-22 at 9 36 47
PM](https://github.com/lastmile-ai/aiconfig/assets/5060851/7eaa2f8d-54d1-453a-991f-597b657ee9be)

## After:
![Screenshot 2024-02-22 at 9 37 27
PM](https://github.com/lastmile-ai/aiconfig/assets/5060851/a41adc3a-7bb3-41be-acbf-0e9da0e2a1c5)
Ryan Holinshead added 2 commits February 22, 2024 21:49
# [rfc] Show readonly Editor Before Server Is Started

Currently when opening an aiconfig file, the file contents / editor webview are not rendered at all until the server is started (or attempted to start). This is because the webview isn't rendered until `resolveCustomTextEditor` returns, and we are awaiting a few server-initialization-related calls within the function.

To fix, we can move the `startEditorServer` into a regular `.then`, which will call the Promise without blocking. Within the `.then` we can handle the resolved promise as normal and do the other things that depend on the server process running.

Another thing worth mentioning is that we previously required the server url to set up the csp for the webview HTML. I'm not sure if we actually need to set the `connect-src vscode-webview` at all (didn't seem to make a difference when testing) but for now, just setting to accept any localhost port instead of being dependent on server.

We can immediately set the webview content and see it rendered (in readonly mode by default):

https://github.com/lastmile-ai/aiconfig/assets/5060851/2bf8cd4a-2b4d-4aea-ad1e-8f15f245ba65


NOTE: This currently results in a notification, 'Error loading models' since the (readonly) editor is attempting to load the models before the server is set up. There is a simple fix needed in the editor to address that, so I'll do that and update the package for use in the vscode extension before landing this
@rholinshead
Copy link
Contributor Author

rebased onto updated package so the models error no longer happens:

Screen.Recording.2024-02-22.at.9.51.16.PM.mov

Going to land and can address feedback (existing behaviour improvements) in a follow-up tomorrow

@rholinshead rholinshead merged commit d78c298 into main Feb 23, 2024
1 check passed
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants