22// Licensed under the MIT License.
33
44/* eslint-disable @typescript-eslint/naming-convention */
5- import { commands , Disposable , Event , EventEmitter , extensions , Uri } from 'vscode' ;
5+ import { commands , Disposable , Event , EventEmitter , Uri } from 'vscode' ;
66import { traceError , traceLog } from './log/logging' ;
77import { PythonExtension , ResolvedEnvironment } from '@vscode/python-extension' ;
8- import { PythonEnvironmentsAPI } from '../typings/pythonEnvironments ' ;
8+ import { PythonEnvironmentApi , PythonEnvironments } from '@vscode/python-environments ' ;
99
1010export interface IInterpreterDetails {
1111 path ?: string [ ] ;
@@ -24,21 +24,16 @@ async function getPythonExtensionAPI(): Promise<PythonExtension | undefined> {
2424 return _api ;
2525}
2626
27- const PYTHON_ENVIRONMENTS_EXTENSION_ID = 'ms-python.vscode-python-envs' ;
28-
29- let _envsApi : PythonEnvironmentsAPI | undefined ;
30- async function getEnvironmentsExtensionAPI ( ) : Promise < PythonEnvironmentsAPI | undefined > {
27+ let _envsApi : PythonEnvironmentApi | undefined ;
28+ async function getEnvironmentsExtensionAPI ( ) : Promise < PythonEnvironmentApi | undefined > {
3129 if ( _envsApi ) {
3230 return _envsApi ;
3331 }
34- const extension = extensions . getExtension ( PYTHON_ENVIRONMENTS_EXTENSION_ID ) ;
35- if ( ! extension ) {
32+ try {
33+ _envsApi = await PythonEnvironments . api ( ) ;
34+ } catch {
3635 return undefined ;
3736 }
38- if ( ! extension . isActive ) {
39- await extension . activate ( ) ;
40- }
41- _envsApi = extension . exports as PythonEnvironmentsAPI ;
4237 return _envsApi ;
4338}
4439
@@ -70,7 +65,8 @@ export async function initializePython(disposables: Disposable[]): Promise<void>
7065 if ( api ) {
7166 disposables . push (
7267 api . environments . onDidChangeActiveEnvironmentPath ( ( e ) => {
73- onDidChangePythonInterpreterEvent . fire ( { path : [ e . path ] , resource : e . resource ?. uri } ) ;
68+ const resource = e . resource instanceof Uri ? e . resource : e . resource ?. uri ;
69+ onDidChangePythonInterpreterEvent . fire ( { path : [ e . path ] , resource } ) ;
7470 } ) ,
7571 ) ;
7672
0 commit comments