Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert JS-style typings to native TS in @vscode/python-extension #21692

Merged
merged 2 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Comment on lines +388 to +407
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is meant to be here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it makes it easier to copy the types from api/types.ts (internal) to npm package types defined in main.ts. Any changes are to be propogated to main.ts which has this helper function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ok, just checking as this was meant to be a types only change

Loading