diff --git a/src/client/browser/api.ts b/src/client/browser/api.ts new file mode 100644 index 000000000000..0536cbadb0bb --- /dev/null +++ b/src/client/browser/api.ts @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +'use strict'; + +import { BaseLanguageClient } from 'vscode-languageclient'; +import { LanguageClient } from 'vscode-languageclient/browser'; +import { PYTHON_LANGUAGE } from '../common/constants'; + +export interface IBrowserExtensionApi { + /** + * @deprecated Temporarily exposed for Pylance until we expose this API generally. Will be removed in an + * iteration or two. + */ + pylance: { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + createClient(...args: any[]): BaseLanguageClient; + start(client: BaseLanguageClient): Promise; + stop(client: BaseLanguageClient): Promise; + }; +} + +export function buildApi(): IBrowserExtensionApi { + const api: IBrowserExtensionApi = { + pylance: { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + createClient: (...args: any[]): BaseLanguageClient => + new LanguageClient(PYTHON_LANGUAGE, 'Python Language Server', args[0], args[1]), + start: (client: BaseLanguageClient): Promise => client.start(), + stop: (client: BaseLanguageClient): Promise => client.stop(), + }, + }; + + return api; +} diff --git a/src/client/browser/extension.ts b/src/client/browser/extension.ts index 5a0e8ae5ee14..e1ee59a677e4 100644 --- a/src/client/browser/extension.ts +++ b/src/client/browser/extension.ts @@ -11,6 +11,7 @@ import { AppinsightsKey, PYLANCE_EXTENSION_ID } from '../common/constants'; import { EventName } from '../telemetry/constants'; import { createStatusItem } from './intellisenseStatus'; import { PylanceApi } from '../activation/node/pylanceApi'; +import { buildApi, IBrowserExtensionApi } from './api'; interface BrowserConfig { distUrl: string; // URL to Pylance's dist folder. @@ -19,11 +20,11 @@ interface BrowserConfig { let languageClient: LanguageClient | undefined; let pylanceApi: PylanceApi | undefined; -export async function activate(context: vscode.ExtensionContext): Promise { +export async function activate(context: vscode.ExtensionContext): Promise { const pylanceExtension = vscode.extensions.getExtension(PYLANCE_EXTENSION_ID); if (pylanceExtension) { await runPylance(context, pylanceExtension); - return; + return buildApi(); } const changeDisposable = vscode.extensions.onDidChange(async () => { @@ -33,6 +34,8 @@ export async function activate(context: vscode.ExtensionContext): Promise await runPylance(context, newPylanceExtension); } }); + + return buildApi(); } export async function deactivate(): Promise {