4
4
'use strict' ;
5
5
6
6
import { noop } from 'lodash' ;
7
+ import { Uri , Event } from 'vscode' ;
7
8
import { IExtensionApi } from './apiTypes' ;
8
9
import { isTestExecution } from './common/constants' ;
9
10
import { IConfigurationService , Resource } from './common/types' ;
11
+ import { IEnvironmentVariablesProvider } from './common/variables/types' ;
10
12
import { getDebugpyLauncherArgs , getDebugpyPackagePath } from './debugger/extension/adapter/remoteLaunchers' ;
11
13
import { IInterpreterService } from './interpreter/contracts' ;
12
14
import { IServiceContainer , IServiceManager } from './ioc/types' ;
@@ -22,7 +24,17 @@ export function buildApi(
22
24
const interpreterService = serviceContainer . get < IInterpreterService > ( IInterpreterService ) ;
23
25
serviceManager . addSingleton < JupyterExtensionIntegration > ( JupyterExtensionIntegration , JupyterExtensionIntegration ) ;
24
26
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
+ } = {
26
38
// 'ready' will propagate the exception, but we must log it here first.
27
39
ready : ready . catch ( ( ex ) => {
28
40
traceError ( 'Failure during activation.' , ex ) ;
@@ -65,6 +77,13 @@ export function buildApi(
65
77
? jupyterIntegration . showDataViewer . bind ( jupyterIntegration )
66
78
: ( noop as any ) ,
67
79
} ,
80
+ pylance : {
81
+ getPythonPathVar : async ( resource ?: Uri ) => {
82
+ const envs = await envService . getEnvironmentVariables ( resource ) ;
83
+ return envs . PYTHONPATH ;
84
+ } ,
85
+ onDidEnvironmentVariablesChange : envService . onDidEnvironmentVariablesChange ,
86
+ } ,
68
87
} ;
69
88
70
89
// In test environment return the DI Container.
0 commit comments