|
3 | 3 |
|
4 | 4 | import { injectable } from 'inversify';
|
5 | 5 | import * as vscode from 'vscode';
|
| 6 | +import { createDeferred } from '../common/utils/async'; |
6 | 7 | import { Architecture } from '../common/utils/platform';
|
7 | 8 | import { getVersionString, parseVersion } from '../common/utils/version';
|
8 | 9 | import {
|
@@ -293,14 +294,39 @@ class ComponentAdapter implements IComponentAdapter {
|
293 | 294 | }
|
294 | 295 | }
|
295 | 296 |
|
| 297 | + const deferred = createDeferred<PythonEnvironment[]>(); |
296 | 298 | const envs: PythonEnvironment[] = [];
|
| 299 | + const executableToLegacy: Record<string, PythonEnvironment> = {}; |
297 | 300 | 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 | + |
298 | 321 | let res = await iterator.next();
|
299 | 322 | while (!res.done) {
|
300 |
| - envs.push(convertEnvInfo(res.value)); |
| 323 | + const env = convertEnvInfo(res.value); |
| 324 | + envs.push(env); |
| 325 | + executableToLegacy[env.path] = env; |
301 | 326 | res = await iterator.next(); // eslint-disable-line no-await-in-loop
|
302 | 327 | }
|
303 |
| - return envs; |
| 328 | + |
| 329 | + return deferred.promise; |
304 | 330 | }
|
305 | 331 | }
|
306 | 332 |
|
|
0 commit comments