From 067c1e2727f3305129690d884a816cb043640252 Mon Sep 17 00:00:00 2001 From: "Ankush Pala ankush@lastmileai.dev" <> Date: Fri, 23 Feb 2024 11:31:39 -0500 Subject: [PATCH] [vscode] Don't block on Python Initialization This diff removes the await statement on the initialize python flow when resolving a custom editor, to ensure that it is not blocking. Now, only the aiconfig server is blocked on python initialization. The webview server is not blocked. Previously this was blocking the webview and not letting the webview server start. ## Testplan https://github.com/lastmile-ai/aiconfig/assets/141073967/ee180bb4-7fb7-40c6-a33e-b7dc3546ae70 --- vscode-extension/src/aiConfigEditor.ts | 60 +++++++++++++------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/vscode-extension/src/aiConfigEditor.ts b/vscode-extension/src/aiConfigEditor.ts index bdbf14686..9bb552456 100644 --- a/vscode-extension/src/aiConfigEditor.ts +++ b/vscode-extension/src/aiConfigEditor.ts @@ -103,40 +103,42 @@ export class AIConfigEditorProvider implements vscode.CustomTextEditorProvider { updateWebview(); // Do not start the server until we ensure the Python setup is ready - await initializePythonFlow(this.context, this.extensionOutputChannel); - - // 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 (startedServer) => { - editorServer = startedServer; - - this.aiconfigEditorManager.addEditor( - new AIConfigEditorState( - document, - webviewPanel, - startedServer, - this.aiconfigEditorManager - ) - ); + initializePythonFlow(this.context, this.extensionOutputChannel).then( + async () => { + // 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 (startedServer) => { + editorServer = startedServer; + + this.aiconfigEditorManager.addEditor( + new AIConfigEditorState( + document, + webviewPanel, + startedServer, + this.aiconfigEditorManager + ) + ); - // Wait for server ready - await waitUntilServerReady(startedServer.url); + // Wait for server ready + await waitUntilServerReady(startedServer.url); - // Now set up the server with the latest document content - await this.startServerWithRetry( - startedServer.url, - document, - webviewPanel - ); + // Now set up the server with the latest document content + await this.startServerWithRetry( + startedServer.url, + document, + webviewPanel + ); - // Inform the webview of the server URL - if (!isWebviewDisposed) { - webviewPanel.webview.postMessage({ - type: "set_server_url", - url: startedServer.url, + // Inform the webview of the server URL + if (!isWebviewDisposed) { + webviewPanel.webview.postMessage({ + type: "set_server_url", + url: startedServer.url, + }); + } }); } - }); + ); // Hook up event handlers so that we can synchronize the webview with the text document. //