forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.ts
More file actions
76 lines (72 loc) · 3.31 KB
/
api.ts
File metadata and controls
76 lines (72 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { noop } from 'lodash';
import { IExtensionApi } from './apiTypes';
import { isTestExecution } from './common/constants';
import { IConfigurationService, Resource } from './common/types';
import { getDebugpyLauncherArgs, getDebugpyPackagePath } from './debugger/extension/adapter/remoteLaunchers';
import { IInterpreterService } from './interpreter/contracts';
import { IServiceContainer, IServiceManager } from './ioc/types';
import { JupyterExtensionIntegration } from './jupyter/jupyterIntegration';
import { traceError } from './logging';
export function buildApi(
ready: Promise<any>,
serviceManager: IServiceManager,
serviceContainer: IServiceContainer,
): IExtensionApi {
const configurationService = serviceContainer.get<IConfigurationService>(IConfigurationService);
const interpreterService = serviceContainer.get<IInterpreterService>(IInterpreterService);
serviceManager.addSingleton<JupyterExtensionIntegration>(JupyterExtensionIntegration, JupyterExtensionIntegration);
const jupyterIntegration = serviceContainer.get<JupyterExtensionIntegration>(JupyterExtensionIntegration);
const api: IExtensionApi = {
// 'ready' will propagate the exception, but we must log it here first.
ready: ready.catch((ex) => {
traceError('Failure during activation.', ex);
return Promise.reject(ex);
}),
jupyter: {
registerHooks: () => jupyterIntegration.integrateWithJupyterExtension(),
},
debug: {
async getRemoteLauncherCommand(
host: string,
port: number,
waitUntilDebuggerAttaches: boolean = true,
): Promise<string[]> {
return getDebugpyLauncherArgs({
host,
port,
waitUntilDebuggerAttaches,
});
},
async getDebuggerPackagePath(): Promise<string | undefined> {
return getDebugpyPackagePath();
},
},
settings: {
onDidChangeExecutionDetails: interpreterService.onDidChangeInterpreterConfiguration,
getExecutionDetails(resource?: Resource) {
const pythonPath = configurationService.getSettings(resource).pythonPath;
// If pythonPath equals an empty string, no interpreter is set.
return { execCommand: pythonPath === '' ? undefined : [pythonPath] };
},
},
// These are for backwards compatibility. Other extensions are using these APIs and we don't want
// to force them to move to the jupyter extension ... yet.
datascience: {
registerRemoteServerProvider: jupyterIntegration
? jupyterIntegration.registerRemoteServerProvider.bind(jupyterIntegration)
: (noop as any),
showDataViewer: jupyterIntegration
? jupyterIntegration.showDataViewer.bind(jupyterIntegration)
: (noop as any),
},
};
// In test environment return the DI Container.
if (isTestExecution()) {
(api as any).serviceContainer = serviceContainer;
(api as any).serviceManager = serviceManager;
}
return api;
}