Skip to content

Commit

Permalink
Convert JS-style typings to native TS in @vscode/python-extension (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik Raj committed Jul 25, 2023
1 parent 8b9bca1 commit d673004
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
14 changes: 5 additions & 9 deletions pythonExtensionApi/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { CancellationToken, Event, Uri, WorkspaceFolder, QuickPickItem, extensio
export interface PythonExtension {
/**
* Promise indicating whether all parts of the extension have completed loading or not.
* @type {Promise<void>}
*/
ready: Promise<void>;
jupyter: {
Expand All @@ -21,10 +20,9 @@ export interface PythonExtension {
* Generate an array of strings for commands to pass to the Python executable to launch the debugger for remote debugging.
* Users can append another array of strings of what they want to execute along with relevant arguments to Python.
* E.g `['/Users/..../pythonVSCode/pythonFiles/lib/python/debugpy', '--listen', 'localhost:57039', '--wait-for-client']`
* @param {string} host
* @param {number} port
* @param {boolean} [waitUntilDebuggerAttaches=true]
* @returns {Promise<string[]>}
* @param host
* @param port
* @param waitUntilDebuggerAttaches Defaults to `true`.
*/
getRemoteLauncherCommand(host: string, port: number, waitUntilDebuggerAttaches: boolean): Promise<string[]>;

Expand All @@ -38,8 +36,8 @@ export interface PythonExtension {
datascience: {
/**
* Launches Data Viewer component.
* @param {IDataViewerDataProvider} dataProvider Instance that will be used by the Data Viewer component to fetch data.
* @param {string} title Data Viewer title
* @param dataProvider Instance that will be used by the Data Viewer component to fetch data.
* @param title Data Viewer title
*/
showDataViewer(dataProvider: IDataViewerDataProvider, title: string): Promise<void>;
/**
Expand Down Expand Up @@ -316,7 +314,6 @@ export type EnvironmentPath = {
* was contributed.
*/
export type EnvironmentTools = KnownEnvironmentTools | string;

/**
* Tools or plugins the Python extension currently has built-in support for. Note this list is expected to shrink
* once tools have their own separate extensions.
Expand All @@ -335,7 +332,6 @@ export type KnownEnvironmentTools =
* Type of the environment. It can be {@link KnownEnvironmentTypes} or custom string which was contributed.
*/
export type EnvironmentType = KnownEnvironmentTypes | string;

/**
* Environment types the Python extension is aware of. Note this list is expected to shrink once tools have their
* own separate extensions, in which case they're expected to provide the type themselves.
Expand Down
34 changes: 26 additions & 8 deletions src/client/api/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { CancellationToken, Event, Uri, WorkspaceFolder, QuickPickItem } from 'vscode';
import { CancellationToken, Event, Uri, WorkspaceFolder, QuickPickItem, extensions } from 'vscode';

/*
* Do not introduce any breaking changes to this API.
Expand All @@ -10,7 +10,6 @@ import { CancellationToken, Event, Uri, WorkspaceFolder, QuickPickItem } from 'v
export interface PythonExtension {
/**
* Promise indicating whether all parts of the extension have completed loading or not.
* @type {Promise<void>}
*/
ready: Promise<void>;
jupyter: {
Expand All @@ -21,10 +20,9 @@ export interface PythonExtension {
* Generate an array of strings for commands to pass to the Python executable to launch the debugger for remote debugging.
* Users can append another array of strings of what they want to execute along with relevant arguments to Python.
* E.g `['/Users/..../pythonVSCode/pythonFiles/lib/python/debugpy', '--listen', 'localhost:57039', '--wait-for-client']`
* @param {string} host
* @param {number} port
* @param {boolean} [waitUntilDebuggerAttaches=true]
* @returns {Promise<string[]>}
* @param host
* @param port
* @param waitUntilDebuggerAttaches Defaults to `true`.
*/
getRemoteLauncherCommand(host: string, port: number, waitUntilDebuggerAttaches: boolean): Promise<string[]>;

Expand All @@ -38,8 +36,8 @@ export interface PythonExtension {
datascience: {
/**
* Launches Data Viewer component.
* @param {IDataViewerDataProvider} dataProvider Instance that will be used by the Data Viewer component to fetch data.
* @param {string} title Data Viewer title
* @param dataProvider Instance that will be used by the Data Viewer component to fetch data.
* @param title Data Viewer title
*/
showDataViewer(dataProvider: IDataViewerDataProvider, title: string): Promise<void>;
/**
Expand Down Expand Up @@ -387,3 +385,23 @@ export type EnvironmentVariablesChangeEvent = {
*/
readonly env: EnvironmentVariables;
};

export const PVSC_EXTENSION_ID = 'ms-python.python';

// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace PythonExtension {
/**
* Returns the API exposed by the Python extension in VS Code.
*/
export async function api(): Promise<PythonExtension> {
const extension = extensions.getExtension(PVSC_EXTENSION_ID);
if (extension === undefined) {
throw new Error(`Python extension is not installed or is disabled`);
}
if (!extension.isActive) {
await extension.activate();
}
const pythonApi: PythonExtension = extension.exports;
return pythonApi;
}
}

0 comments on commit d673004

Please sign in to comment.