Skip to content

Commit c6dbff8

Browse files
authored
Wait for pylance instead of failing in the browser (#17033) (#17036)
1 parent ecfd3ba commit c6dbff8

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/client/browser/extension.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,28 @@ interface BrowserConfig {
1717

1818
export async function activate(context: vscode.ExtensionContext): Promise<void> {
1919
// Run in a promise and return early so that VS Code can go activate Pylance.
20-
runPylance(context);
21-
}
2220

23-
async function runPylance(context: vscode.ExtensionContext): Promise<void> {
2421
const pylanceExtension = vscode.extensions.getExtension<ILSExtensionApi>(PYLANCE_EXTENSION_ID);
25-
const pylanceApi = await pylanceExtension?.activate();
26-
if (!pylanceApi?.languageServerFolder) {
22+
if (pylanceExtension) {
23+
runPylance(context, pylanceExtension);
24+
return;
25+
}
26+
27+
const changeDisposable = vscode.extensions.onDidChange(() => {
28+
const newPylanceExtension = vscode.extensions.getExtension<ILSExtensionApi>(PYLANCE_EXTENSION_ID);
29+
if (newPylanceExtension) {
30+
changeDisposable.dispose();
31+
runPylance(context, newPylanceExtension);
32+
}
33+
});
34+
}
35+
36+
async function runPylance(
37+
context: vscode.ExtensionContext,
38+
pylanceExtension: vscode.Extension<ILSExtensionApi>,
39+
): Promise<void> {
40+
const pylanceApi = await pylanceExtension.activate();
41+
if (!pylanceApi.languageServerFolder) {
2742
throw new Error('Could not find Pylance extension');
2843
}
2944

0 commit comments

Comments
 (0)