Skip to content

Commit c04c6f5

Browse files
Handle iterator.onUpdated in ComponentAdapter.getInterpreters().
1 parent 4271fd4 commit c04c6f5

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/client/pythonEnvironments/legacyIOC.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import { injectable } from 'inversify';
55
import * as vscode from 'vscode';
6+
import { createDeferred } from '../common/utils/async';
67
import { Architecture } from '../common/utils/platform';
78
import { getVersionString, parseVersion } from '../common/utils/version';
89
import {
@@ -293,14 +294,39 @@ class ComponentAdapter implements IComponentAdapter {
293294
}
294295
}
295296

297+
const deferred = createDeferred<PythonEnvironment[]>();
296298
const envs: PythonEnvironment[] = [];
299+
const executableToLegacy: Record<string, PythonEnvironment> = {};
297300
const iterator = this.api.iterEnvs(query);
301+
302+
if (iterator.onUpdated !== undefined) {
303+
iterator.onUpdated((event) => {
304+
if (event === null) {
305+
deferred.resolve(envs);
306+
} else {
307+
// Replace the old one.
308+
const old = executableToLegacy[event.old.executable.filename];
309+
if (old !== undefined) {
310+
const index = envs.indexOf(old);
311+
if (index !== -1) {
312+
envs[index] = convertEnvInfo(event.new);
313+
}
314+
}
315+
}
316+
});
317+
} else {
318+
deferred.resolve(envs);
319+
}
320+
298321
let res = await iterator.next();
299322
while (!res.done) {
300-
envs.push(convertEnvInfo(res.value));
323+
const env = convertEnvInfo(res.value);
324+
envs.push(env);
325+
executableToLegacy[env.path] = env;
301326
res = await iterator.next(); // eslint-disable-line no-await-in-loop
302327
}
303-
return envs;
328+
329+
return deferred.promise;
304330
}
305331
}
306332

0 commit comments

Comments
 (0)