|
1 | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
2 | 2 | // Licensed under the MIT License. |
3 | 3 |
|
4 | | -import { CancellationToken, Event, Uri, WorkspaceFolder, QuickPickItem } from 'vscode'; |
| 4 | +import { CancellationToken, Event, Uri, WorkspaceFolder, QuickPickItem, extensions } from 'vscode'; |
5 | 5 |
|
6 | 6 | /* |
7 | 7 | * Do not introduce any breaking changes to this API. |
@@ -10,7 +10,6 @@ import { CancellationToken, Event, Uri, WorkspaceFolder, QuickPickItem } from 'v |
10 | 10 | export interface PythonExtension { |
11 | 11 | /** |
12 | 12 | * Promise indicating whether all parts of the extension have completed loading or not. |
13 | | - * @type {Promise<void>} |
14 | 13 | */ |
15 | 14 | ready: Promise<void>; |
16 | 15 | jupyter: { |
@@ -21,10 +20,9 @@ export interface PythonExtension { |
21 | 20 | * Generate an array of strings for commands to pass to the Python executable to launch the debugger for remote debugging. |
22 | 21 | * Users can append another array of strings of what they want to execute along with relevant arguments to Python. |
23 | 22 | * E.g `['/Users/..../pythonVSCode/pythonFiles/lib/python/debugpy', '--listen', 'localhost:57039', '--wait-for-client']` |
24 | | - * @param {string} host |
25 | | - * @param {number} port |
26 | | - * @param {boolean} [waitUntilDebuggerAttaches=true] |
27 | | - * @returns {Promise<string[]>} |
| 23 | + * @param host |
| 24 | + * @param port |
| 25 | + * @param waitUntilDebuggerAttaches Defaults to `true`. |
28 | 26 | */ |
29 | 27 | getRemoteLauncherCommand(host: string, port: number, waitUntilDebuggerAttaches: boolean): Promise<string[]>; |
30 | 28 |
|
@@ -38,8 +36,8 @@ export interface PythonExtension { |
38 | 36 | datascience: { |
39 | 37 | /** |
40 | 38 | * Launches Data Viewer component. |
41 | | - * @param {IDataViewerDataProvider} dataProvider Instance that will be used by the Data Viewer component to fetch data. |
42 | | - * @param {string} title Data Viewer title |
| 39 | + * @param dataProvider Instance that will be used by the Data Viewer component to fetch data. |
| 40 | + * @param title Data Viewer title |
43 | 41 | */ |
44 | 42 | showDataViewer(dataProvider: IDataViewerDataProvider, title: string): Promise<void>; |
45 | 43 | /** |
@@ -387,3 +385,23 @@ export type EnvironmentVariablesChangeEvent = { |
387 | 385 | */ |
388 | 386 | readonly env: EnvironmentVariables; |
389 | 387 | }; |
| 388 | + |
| 389 | +export const PVSC_EXTENSION_ID = 'ms-python.python'; |
| 390 | + |
| 391 | +// eslint-disable-next-line @typescript-eslint/no-namespace |
| 392 | +export namespace PythonExtension { |
| 393 | + /** |
| 394 | + * Returns the API exposed by the Python extension in VS Code. |
| 395 | + */ |
| 396 | + export async function api(): Promise<PythonExtension> { |
| 397 | + const extension = extensions.getExtension(PVSC_EXTENSION_ID); |
| 398 | + if (extension === undefined) { |
| 399 | + throw new Error(`Python extension is not installed or is disabled`); |
| 400 | + } |
| 401 | + if (!extension.isActive) { |
| 402 | + await extension.activate(); |
| 403 | + } |
| 404 | + const pythonApi: PythonExtension = extension.exports; |
| 405 | + return pythonApi; |
| 406 | + } |
| 407 | +} |