Skip to content

Commit 8933ef8

Browse files
activate extension
1 parent e63c0d2 commit 8933ef8

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/extension/common/python.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,24 @@
33

44
/* eslint-disable @typescript-eslint/naming-convention */
55
import { Environment, EnvironmentPath, PythonExtension, Resource } from '@vscode/python-extension';
6-
import { commands, extensions, Uri } from 'vscode';
6+
import { commands, EventEmitter, extensions, Uri, Event, Disposable } from 'vscode';
77
import { createDeferred } from './utils/async';
8+
import { traceError, traceLog } from './log/logging';
89

910
interface IExtensionApi {
1011
ready: Promise<void>;
1112
settings: {
1213
getExecutionDetails(resource?: Resource): { execCommand: string[] | undefined };
1314
};
1415
}
16+
1517
export interface IInterpreterDetails {
1618
path?: string[];
1719
resource?: Uri;
1820
}
21+
22+
const onDidChangePythonInterpreterEvent = new EventEmitter<IInterpreterDetails>();
23+
export const onDidChangePythonInterpreter: Event<IInterpreterDetails> = onDidChangePythonInterpreterEvent.event;
1924
async function activateExtension() {
2025
const extension = extensions.getExtension('ms-python.python');
2126
if (extension) {
@@ -33,9 +38,29 @@ async function getPythonExtensionAPI(): Promise<IExtensionApi | undefined> {
3338

3439
async function getPythonExtensionEnviromentAPI(): Promise<PythonExtension> {
3540
// Load the Python extension API
41+
await activateExtension();
3642
return await PythonExtension.api();
3743
}
3844

45+
export async function initializePython(disposables: Disposable[]): Promise<void> {
46+
try {
47+
const api = await getPythonExtensionEnviromentAPI();
48+
49+
if (api) {
50+
disposables.push(
51+
api.environments.onDidChangeActiveEnvironmentPath((e) => {
52+
onDidChangePythonInterpreterEvent.fire({ path: [e.path], resource: e.resource?.uri });
53+
}),
54+
);
55+
56+
traceLog('Waiting for interpreter from python extension.');
57+
onDidChangePythonInterpreterEvent.fire(await getInterpreterDetails());
58+
}
59+
} catch (error) {
60+
traceError('Error initializing python: ', error);
61+
}
62+
}
63+
3964
export async function runPythonExtensionCommand(command: string, ...rest: any[]) {
4065
await activateExtension();
4166
return await commands.executeCommand(command, ...rest);

0 commit comments

Comments
 (0)