|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +import { Event, Uri } from 'vscode'; |
| 5 | +import { Resource } from './common/types'; |
| 6 | +import { IDataViewerDataProvider, IJupyterUriProvider } from './jupyter/types'; |
| 7 | + |
| 8 | +/* |
| 9 | + * Do not introduce any breaking changes to this API. |
| 10 | + * This is the public API for other extensions to interact with this extension. |
| 11 | + */ |
| 12 | + |
| 13 | +export interface IExtensionApi { |
| 14 | + /** |
| 15 | + * Promise indicating whether all parts of the extension have completed loading or not. |
| 16 | + * @type {Promise<void>} |
| 17 | + * @memberof IExtensionApi |
| 18 | + */ |
| 19 | + ready: Promise<void>; |
| 20 | + jupyter: { |
| 21 | + registerHooks(): void; |
| 22 | + }; |
| 23 | + debug: { |
| 24 | + /** |
| 25 | + * Generate an array of strings for commands to pass to the Python executable to launch the debugger for remote debugging. |
| 26 | + * Users can append another array of strings of what they want to execute along with relevant arguments to Python. |
| 27 | + * E.g `['/Users/..../pythonVSCode/pythonFiles/lib/python/debugpy', '--listen', 'localhost:57039', '--wait-for-client']` |
| 28 | + * @param {string} host |
| 29 | + * @param {number} port |
| 30 | + * @param {boolean} [waitUntilDebuggerAttaches=true] |
| 31 | + * @returns {Promise<string[]>} |
| 32 | + */ |
| 33 | + getRemoteLauncherCommand(host: string, port: number, waitUntilDebuggerAttaches: boolean): Promise<string[]>; |
| 34 | + |
| 35 | + /** |
| 36 | + * Gets the path to the debugger package used by the extension. |
| 37 | + * @returns {Promise<string>} |
| 38 | + */ |
| 39 | + getDebuggerPackagePath(): Promise<string | undefined>; |
| 40 | + }; |
| 41 | + /** |
| 42 | + * Return internal settings within the extension which are stored in VSCode storage |
| 43 | + */ |
| 44 | + settings: { |
| 45 | + /** |
| 46 | + * An event that is emitted when execution details (for a resource) change. For instance, when interpreter configuration changes. |
| 47 | + */ |
| 48 | + readonly onDidChangeExecutionDetails: Event<Uri | undefined>; |
| 49 | + /** |
| 50 | + * Returns all the details the consumer needs to execute code within the selected environment, |
| 51 | + * corresponding to the specified resource taking into account any workspace-specific settings |
| 52 | + * for the workspace to which this resource belongs. |
| 53 | + * @param {Resource} [resource] A resource for which the setting is asked for. |
| 54 | + * * When no resource is provided, the setting scoped to the first workspace folder is returned. |
| 55 | + * * If no folder is present, it returns the global setting. |
| 56 | + * @returns {({ execCommand: string[] | undefined })} |
| 57 | + */ |
| 58 | + getExecutionDetails( |
| 59 | + resource?: Resource, |
| 60 | + ): { |
| 61 | + /** |
| 62 | + * E.g of execution commands returned could be, |
| 63 | + * * `['<path to the interpreter set in settings>']` |
| 64 | + * * `['<path to the interpreter selected by the extension when setting is not set>']` |
| 65 | + * * `['conda', 'run', 'python']` which is used to run from within Conda environments. |
| 66 | + * or something similar for some other Python environments. |
| 67 | + * |
| 68 | + * @type {(string[] | undefined)} When return value is `undefined`, it means no interpreter is set. |
| 69 | + * Otherwise, join the items returned using space to construct the full execution command. |
| 70 | + */ |
| 71 | + execCommand: string[] | undefined; |
| 72 | + }; |
| 73 | + }; |
| 74 | + |
| 75 | + datascience: { |
| 76 | + /** |
| 77 | + * Launches Data Viewer component. |
| 78 | + * @param {IDataViewerDataProvider} dataProvider Instance that will be used by the Data Viewer component to fetch data. |
| 79 | + * @param {string} title Data Viewer title |
| 80 | + */ |
| 81 | + showDataViewer(dataProvider: IDataViewerDataProvider, title: string): Promise<void>; |
| 82 | + /** |
| 83 | + * Registers a remote server provider component that's used to pick remote jupyter server URIs |
| 84 | + * @param serverProvider object called back when picking jupyter server URI |
| 85 | + */ |
| 86 | + registerRemoteServerProvider(serverProvider: IJupyterUriProvider): void; |
| 87 | + }; |
| 88 | +} |
| 89 | + |
| 90 | +export interface InterpreterDetailsOptions { |
| 91 | + useCache: boolean; |
| 92 | +} |
| 93 | + |
| 94 | +export interface InterpreterDetails { |
| 95 | + path: string; |
| 96 | + version: string[]; |
| 97 | + environmentType: string[]; |
| 98 | + metadata: Record<string, unknown>; |
| 99 | +} |
| 100 | + |
| 101 | +export interface InterpretersChangedParams { |
| 102 | + path?: string; |
| 103 | + type: 'add' | 'remove' | 'update' | 'clear-all'; |
| 104 | +} |
| 105 | + |
| 106 | +export interface ActiveInterpreterChangedParams { |
| 107 | + interpreterPath?: string; |
| 108 | + resource?: Uri; |
| 109 | +} |
| 110 | + |
| 111 | +export interface IProposedExtensionAPI { |
| 112 | + environment: { |
| 113 | + /** |
| 114 | + * Returns the path to the python binary selected by the user or as in the settings. |
| 115 | + * This is just the path to the python binary, this does not provide activation or any |
| 116 | + * other activation command. The `resource` if provided will be used to determine the |
| 117 | + * python binary in a multi-root scenario. If resource is `undefined` then the API |
| 118 | + * returns what ever is set for the workspace. |
| 119 | + * @param resource : Uri of a file or workspace |
| 120 | + */ |
| 121 | + getActiveInterpreterPath(resource?: Resource): Promise<string | undefined>; |
| 122 | + /** |
| 123 | + * Returns details for the given interpreter. Details such as absolute interpreter path, |
| 124 | + * version, type (conda, pyenv, etc). Metadata such as `sysPrefix` can be found under |
| 125 | + * metadata field. |
| 126 | + * @param interpreterPath : Path of the interpreter whose details you need. |
| 127 | + * @param options : [optional] |
| 128 | + * * useCache : When true, cache is checked first for any data, returns even if there |
| 129 | + * is partial data. |
| 130 | + */ |
| 131 | + getInterpreterDetails( |
| 132 | + interpreterPath: string, |
| 133 | + options?: InterpreterDetailsOptions, |
| 134 | + ): Promise<InterpreterDetails | undefined>; |
| 135 | + /** |
| 136 | + * Returns paths to interpreters found by the extension at the time of calling. This API |
| 137 | + * will *not* trigger a refresh. If a refresh is going on it will *not* wait for the refresh |
| 138 | + * to finish. This will return what is known so far. To get complete list `await` on promise |
| 139 | + * returned by `getRefreshPromise()`. |
| 140 | + */ |
| 141 | + getInterpreterPaths(): Promise<string[] | undefined>; |
| 142 | + /** |
| 143 | + * Sets the active interpreter path for the python extension. Configuration target will |
| 144 | + * always be the workspace. |
| 145 | + * @param interpreterPath : Interpreter path to set for a given workspace. |
| 146 | + * @param resource : [optional] Uri of a file ro workspace to scope to a particular workspace |
| 147 | + * folder. |
| 148 | + */ |
| 149 | + setActiveInterpreter(interpreterPath: string, resource?: Resource): Promise<void>; |
| 150 | + /** |
| 151 | + * This API will re-trigger environment discovery. Extensions can wait on the returned |
| 152 | + * promise to get the updated interpreters list. If there is a refresh already going on |
| 153 | + * then it returns the promise for that refresh. |
| 154 | + */ |
| 155 | + refreshInterpreters(): Promise<string[] | undefined>; |
| 156 | + /** |
| 157 | + * Returns a promise for the ongoing refresh. Returns `undefined` if there are no active |
| 158 | + * refreshes going on. |
| 159 | + */ |
| 160 | + getRefreshPromise(): Promise<void> | undefined; |
| 161 | + /** |
| 162 | + * This event is triggered when the known interpreters list changes, like when a interpreter |
| 163 | + * is found, existing interpreter is removed, or some details changed on an interpreter. |
| 164 | + */ |
| 165 | + onDidInterpretersChanged: Event<InterpretersChangedParams[]>; |
| 166 | + /** |
| 167 | + * This event is triggered when the active interpreter changes. |
| 168 | + */ |
| 169 | + onDidActiveInterpreterChanged: Event<ActiveInterpreterChangedParams>; |
| 170 | + }; |
| 171 | +} |
0 commit comments