From 744be86b7103bb940955d743d41d29729342379b Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 19 Aug 2021 09:57:40 -0700 Subject: [PATCH] Wait for pylance instead of failing in the browser (#17033) --- src/client/browser/extension.ts | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/client/browser/extension.ts b/src/client/browser/extension.ts index 4b27ad2a0f7e..94e86603565a 100644 --- a/src/client/browser/extension.ts +++ b/src/client/browser/extension.ts @@ -17,13 +17,28 @@ interface BrowserConfig { export async function activate(context: vscode.ExtensionContext): Promise { // Run in a promise and return early so that VS Code can go activate Pylance. - runPylance(context); -} -async function runPylance(context: vscode.ExtensionContext): Promise { const pylanceExtension = vscode.extensions.getExtension(PYLANCE_EXTENSION_ID); - const pylanceApi = await pylanceExtension?.activate(); - if (!pylanceApi?.languageServerFolder) { + if (pylanceExtension) { + runPylance(context, pylanceExtension); + return; + } + + const changeDisposable = vscode.extensions.onDidChange(() => { + const newPylanceExtension = vscode.extensions.getExtension(PYLANCE_EXTENSION_ID); + if (newPylanceExtension) { + changeDisposable.dispose(); + runPylance(context, newPylanceExtension); + } + }); +} + +async function runPylance( + context: vscode.ExtensionContext, + pylanceExtension: vscode.Extension, +): Promise { + const pylanceApi = await pylanceExtension.activate(); + if (!pylanceApi.languageServerFolder) { throw new Error('Could not find Pylance extension'); }