<commit_before>// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import * as vscode from 'vscode';
import TelemetryReporter from 'vscode-extension-telemetry';
import { LanguageClientOptions, State } from 'vscode-languageclient';
import { LanguageClient } from 'vscode-languageclient/browser';
import { LanguageClientMiddlewareBase } from '../activation/languageClientMiddlewareBase';
import { ILSExtensionApi } from '../activation/node/languageServerFolderService';
import { LanguageServerType } from '../activation/types';
import { AppinsightsKey, PVSC_EXTENSION_ID, PYLANCE_EXTENSION_ID } from '../common/constants';
import { EventName } from '../telemetry/constants';

interface BrowserConfig {
    distUrl: string; // URL to Pylance's dist folder.
}

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

async function runPylance(context: vscode.ExtensionContext): Promise<void> {
    const pylanceExtension = vscode.extensions.getExtension<ILSExtensionApi>(PYLANCE_EXTENSION_ID);
    const pylanceApi = await pylanceExtension?.activate();
    if (!pylanceApi?.languageServerFolder) {
        throw new Error('Could not find Pylance extension');
    }<commit_msg>Wait for pylance instead of failing in the browser (#17033)<commit_after>// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import * as vscode from 'vscode';
import TelemetryReporter from 'vscode-extension-telemetry';
import { LanguageClientOptions, State } from 'vscode-languageclient';
import { LanguageClient } from 'vscode-languageclient/browser';
import { LanguageClientMiddlewareBase } from '../activation/languageClientMiddlewareBase';
import { ILSExtensionApi } from '../activation/node/languageServerFolderService';
import { LanguageServerType } from '../activation/types';
import { AppinsightsKey, PVSC_EXTENSION_ID, PYLANCE_EXTENSION_ID } from '../common/constants';
import { EventName } from '../telemetry/constants';

interface BrowserConfig {
    distUrl: string; // URL to Pylance's dist folder.
}

export async function activate(context: vscode.ExtensionContext): Promise<void> {
    // Run in a promise and return early so that VS Code can go activate Pylance.

    const pylanceExtension = vscode.extensions.getExtension<ILSExtensionApi>(PYLANCE_EXTENSION_ID);
    if (pylanceExtension) {
        runPylance(context, pylanceExtension);
        return;
    }

    const changeDisposable = vscode.extensions.onDidChange(() => {
        const newPylanceExtension = vscode.extensions.getExtension<ILSExtensionApi>(PYLANCE_EXTENSION_ID);
        if (newPylanceExtension) {
            changeDisposable.dispose();
            runPylance(context, newPylanceExtension);
        }
    });
}

async function runPylance(
    context: vscode.ExtensionContext,
    pylanceExtension: vscode.Extension<ILSExtensionApi>,
): Promise<void> {
    const pylanceApi = await pylanceExtension.activate();
    if (!pylanceApi.languageServerFolder) {
        throw new Error('Could not find Pylance extension');
    }
{'fraction_non_alphanumeric': 0.10127765659083826, 'fraction_numerical': 0.0015581177937052041, 'mean_word_length': 4.711743772241993, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7297219', 'n_tokens_mistral': 920, 'n_tokens_neox': 893, 'n_words': 237}