44'use strict' ;
55
66import { noop } from 'lodash' ;
7+ import { Uri , Event } from 'vscode' ;
78import { IExtensionApi } from './apiTypes' ;
89import { isTestExecution } from './common/constants' ;
910import { IConfigurationService , Resource } from './common/types' ;
11+ import { IEnvironmentVariablesProvider } from './common/variables/types' ;
1012import { getDebugpyLauncherArgs , getDebugpyPackagePath } from './debugger/extension/adapter/remoteLaunchers' ;
1113import { IInterpreterService } from './interpreter/contracts' ;
1214import { IServiceContainer , IServiceManager } from './ioc/types' ;
@@ -22,7 +24,17 @@ export function buildApi(
2224 const interpreterService = serviceContainer . get < IInterpreterService > ( IInterpreterService ) ;
2325 serviceManager . addSingleton < JupyterExtensionIntegration > ( JupyterExtensionIntegration , JupyterExtensionIntegration ) ;
2426 const jupyterIntegration = serviceContainer . get < JupyterExtensionIntegration > ( JupyterExtensionIntegration ) ;
25- const api : IExtensionApi = {
27+ const envService = serviceContainer . get < IEnvironmentVariablesProvider > ( IEnvironmentVariablesProvider ) ;
28+ const api : IExtensionApi & {
29+ /**
30+ * @deprecated Temporarily exposed for Pylance until we expose this API generally. Will be removed in an
31+ * iteration or two.
32+ */
33+ pylance : {
34+ getPythonPathVar : ( resource ?: Uri ) => Promise < string | undefined > ;
35+ readonly onDidEnvironmentVariablesChange : Event < Uri | undefined > ;
36+ } ;
37+ } = {
2638 // 'ready' will propagate the exception, but we must log it here first.
2739 ready : ready . catch ( ( ex ) => {
2840 traceError ( 'Failure during activation.' , ex ) ;
@@ -65,6 +77,13 @@ export function buildApi(
6577 ? jupyterIntegration . showDataViewer . bind ( jupyterIntegration )
6678 : ( noop as any ) ,
6779 } ,
80+ pylance : {
81+ getPythonPathVar : async ( resource ?: Uri ) => {
82+ const envs = await envService . getEnvironmentVariables ( resource ) ;
83+ return envs . PYTHONPATH ;
84+ } ,
85+ onDidEnvironmentVariablesChange : envService . onDidEnvironmentVariablesChange ,
86+ } ,
6887 } ;
6988
7089 // In test environment return the DI Container.
0 commit comments