66
77import { inject , injectable , named } from 'inversify' ;
88import { dirname } from 'path' ;
9- import { EventEmitter , Extension , Memento , Uri , workspace , type Event } from 'vscode' ;
9+ import { EventEmitter , Extension , Memento , Uri , workspace , Event } from 'vscode' ;
1010import type { SemVer } from 'semver' ;
1111import { IContextKeyManager , IWorkspaceService } from '../common/application/types' ;
1212import { JUPYTER_EXTENSION_ID , PYLANCE_EXTENSION_ID } from '../common/constants' ;
@@ -172,7 +172,6 @@ export class JupyterExtensionIntegration {
172172 }
173173}
174174
175-
176175export interface JupyterPythonEnvironmentApi {
177176 /**
178177 * This event is triggered when the environment associated with a Jupyter Notebook or Interactive Window changes.
@@ -189,64 +188,72 @@ export interface JupyterPythonEnvironmentApi {
189188 ) :
190189 | undefined
191190 | {
192- /**
193- * The ID of the environment.
194- */
195- readonly id : string ;
196- /**
197- * Path to environment folder or path to python executable that uniquely identifies an environment. Environments
198- * lacking a python executable are identified by environment folder paths, whereas other envs can be identified
199- * using python executable path.
200- */
201- readonly path : string ;
202- } ;
191+ /**
192+ * The ID of the environment.
193+ */
194+ readonly id : string ;
195+ /**
196+ * Path to environment folder or path to python executable that uniquely identifies an environment. Environments
197+ * lacking a python executable are identified by environment folder paths, whereas other envs can be identified
198+ * using python executable path.
199+ */
200+ readonly path : string ;
201+ } ;
203202}
204203
205-
206204@injectable ( )
207- export class JupyterExtensionPythonEnvironments extends DisposableBase implements JupyterPythonEnvironmentApi {
205+ export class JupyterExtensionPythonEnvironments extends DisposableBase implements JupyterPythonEnvironmentApi {
208206 private jupyterExtension ?: JupyterPythonEnvironmentApi ;
209207
210208 private readonly _onDidChangePythonEnvironment = this . _register ( new EventEmitter < Uri > ( ) ) ;
211209
212210 public readonly onDidChangePythonEnvironment = this . _onDidChangePythonEnvironment . event ;
213211
214- constructor (
215- @inject ( IExtensions ) private readonly extensions : IExtensions ,
216- ) {
212+ constructor ( @inject ( IExtensions ) private readonly extensions : IExtensions ) {
217213 super ( ) ;
218214 }
219215
220- public getPythonEnvironment ( uri : Uri ) : undefined |
221- {
222- /**
223- * The ID of the environment.
224- */
225- readonly id : string ;
226- /**
227- * Path to environment folder or path to python executable that uniquely identifies an environment. Environments
228- * lacking a python executable are identified by environment folder paths, whereas other envs can be identified
229- * using python executable path.
230- */
231- readonly path : string ;
232- } {
216+ public getPythonEnvironment (
217+ uri : Uri ,
218+ ) :
219+ | undefined
220+ | {
221+ /**
222+ * The ID of the environment.
223+ */
224+ readonly id : string ;
225+ /**
226+ * Path to environment folder or path to python executable that uniquely identifies an environment. Environments
227+ * lacking a python executable are identified by environment folder paths, whereas other envs can be identified
228+ * using python executable path.
229+ */
230+ readonly path : string ;
231+ } {
233232 return isJupyterResource ( uri ) ? this . getJupyterApi ( ) ?. getPythonEnvironment ( uri ) : undefined ;
234233 }
235234
236- private getJupyterApi ( ) {
235+ private getJupyterApi ( ) {
237236 if ( ! this . jupyterExtension ) {
238237 const api = this . extensions . getExtension < JupyterPythonEnvironmentApi > ( JUPYTER_EXTENSION_ID ) ?. exports ;
239238 if ( ! api ) {
240239 return undefined ;
241240 }
242241 this . jupyterExtension = api ;
243- this . _register ( api . onDidChangePythonEnvironment ( this . _onDidChangePythonEnvironment . fire , this . _onDidChangePythonEnvironment ) ) ;
242+ this . _register (
243+ api . onDidChangePythonEnvironment (
244+ this . _onDidChangePythonEnvironment . fire ,
245+ this . _onDidChangePythonEnvironment ,
246+ ) ,
247+ ) ;
244248 }
245249 return this . jupyterExtension ;
246250 }
247251}
248252
249253function isJupyterResource ( resource : Uri ) : boolean {
250254 // Jupyter extension only deals with Notebooks and Interactive Windows.
251- return resource . fsPath . endsWith ( '.ipynb' ) || workspace . notebookDocuments . some ( ( item ) => item . uri . toString ( ) === resource . toString ( ) ) ;
255+ return (
256+ resource . fsPath . endsWith ( '.ipynb' ) ||
257+ workspace . notebookDocuments . some ( ( item ) => item . uri . toString ( ) === resource . toString ( ) )
258+ ) ;
252259}
0 commit comments