Skip to content

Commit 9b235c1

Browse files
committed
fix active environment path change handling in Python extension with new API
1 parent 0f97972 commit 9b235c1

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/extension/common/python.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
// Licensed under the MIT License.
33

44
/* eslint-disable @typescript-eslint/naming-convention */
5-
import { Environment, EnvironmentPath, PythonExtension, Resource } from '@vscode/python-extension';
5+
import {
6+
ActiveEnvironmentPathChangeEvent,
7+
Environment,
8+
EnvironmentPath,
9+
PythonExtension,
10+
Resource,
11+
} from '@vscode/python-extension';
612
import { commands, EventEmitter, extensions, Uri, Event, Disposable } from 'vscode';
713
import { createDeferred } from './utils/async';
814
import { traceError, traceLog } from './log/logging';
@@ -48,8 +54,16 @@ export async function initializePython(disposables: Disposable[]): Promise<void>
4854

4955
if (api) {
5056
disposables.push(
51-
api.environments.onDidChangeActiveEnvironmentPath((e) => {
52-
onDidChangePythonInterpreterEvent.fire({ path: [e.path], resource: e.resource?.uri });
57+
api.environments.onDidChangeActiveEnvironmentPath((e: ActiveEnvironmentPathChangeEvent) => {
58+
let resourceUri: Uri | undefined;
59+
if (e.resource instanceof Uri) {
60+
resourceUri = e.resource;
61+
}
62+
if (e.resource && 'uri' in e.resource) {
63+
// WorkspaceFolder type
64+
resourceUri = e.resource.uri;
65+
}
66+
onDidChangePythonInterpreterEvent.fire({ path: [e.path], resource: resourceUri });
5367
}),
5468
);
5569

0 commit comments

Comments
 (0)