@@ -5,6 +5,7 @@ import { injectable } from 'inversify';
5
5
import * as vscode from 'vscode' ;
6
6
import { IExtensionSingleActivationService } from '../activation/types' ;
7
7
import { DiscoveryVariants } from '../common/experiments/groups' ;
8
+ import { IDisposableRegistry } from '../common/types' ;
8
9
import { getVersionString , parseVersion } from '../common/utils/version' ;
9
10
import {
10
11
CONDA_ENV_FILE_SERVICE ,
@@ -152,6 +153,7 @@ class ComponentAdapter implements IComponentAdapter, IExtensionSingleActivationS
152
153
// The adapter only wraps one thing: the component API.
153
154
private readonly api : IPythonEnvironments ,
154
155
private readonly environmentsSecurity : IEnvironmentsSecurity ,
156
+ private readonly disposables : IDisposableRegistry ,
155
157
) { }
156
158
157
159
public async activate ( ) : Promise < void > {
@@ -161,6 +163,14 @@ class ComponentAdapter implements IComponentAdapter, IExtensionSingleActivationS
161
163
inExperiment ( DiscoveryVariants . discoveryWithoutFileWatching ) ,
162
164
] ,
163
165
) ) . includes ( true ) ;
166
+ this . disposables . push ( this . api . onChanged ( ( e ) => {
167
+ const query = {
168
+ kinds : e . kind ? [ e . kind ] : undefined ,
169
+ searchLocations : e . searchLocation ? { roots : [ e . searchLocation ] } : undefined
170
+ } ;
171
+ // Trigger a background refresh of the environments.
172
+ getEnvs ( this . api . iterEnvs ( query ) ) . ignoreErrors ( ) ;
173
+ } ) ) ;
164
174
}
165
175
166
176
// IInterpreterLocatorProgressHandler
@@ -409,10 +419,11 @@ export function registerNewDiscoveryForIOC(
409
419
serviceManager : IServiceManager ,
410
420
api : IPythonEnvironments ,
411
421
environmentsSecurity : EnvironmentsSecurity ,
422
+ disposables : IDisposableRegistry
412
423
) : void {
413
424
serviceManager . addSingletonInstance < IComponentAdapter > (
414
425
IComponentAdapter ,
415
- new ComponentAdapter ( api , environmentsSecurity ) ,
426
+ new ComponentAdapter ( api , environmentsSecurity , disposables ) ,
416
427
) ;
417
428
serviceManager . addBinding ( IComponentAdapter , IExtensionSingleActivationService ) ;
418
429
}
0 commit comments