@@ -5,6 +5,7 @@ import { injectable } from 'inversify';
55import * as vscode from 'vscode' ;
66import { IExtensionSingleActivationService } from '../activation/types' ;
77import { DiscoveryVariants } from '../common/experiments/groups' ;
8+ import { IDisposableRegistry } from '../common/types' ;
89import { getVersionString , parseVersion } from '../common/utils/version' ;
910import {
1011 CONDA_ENV_FILE_SERVICE ,
@@ -152,6 +153,7 @@ class ComponentAdapter implements IComponentAdapter, IExtensionSingleActivationS
152153 // The adapter only wraps one thing: the component API.
153154 private readonly api : IPythonEnvironments ,
154155 private readonly environmentsSecurity : IEnvironmentsSecurity ,
156+ private readonly disposables : IDisposableRegistry ,
155157 ) { }
156158
157159 public async activate ( ) : Promise < void > {
@@ -161,6 +163,14 @@ class ComponentAdapter implements IComponentAdapter, IExtensionSingleActivationS
161163 inExperiment ( DiscoveryVariants . discoveryWithoutFileWatching ) ,
162164 ] ,
163165 ) ) . 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+ } ) ) ;
164174 }
165175
166176 // IInterpreterLocatorProgressHandler
@@ -409,10 +419,11 @@ export function registerNewDiscoveryForIOC(
409419 serviceManager : IServiceManager ,
410420 api : IPythonEnvironments ,
411421 environmentsSecurity : EnvironmentsSecurity ,
422+ disposables : IDisposableRegistry
412423) : void {
413424 serviceManager . addSingletonInstance < IComponentAdapter > (
414425 IComponentAdapter ,
415- new ComponentAdapter ( api , environmentsSecurity ) ,
426+ new ComponentAdapter ( api , environmentsSecurity , disposables ) ,
416427 ) ;
417428 serviceManager . addBinding ( IComponentAdapter , IExtensionSingleActivationService ) ;
418429}
0 commit comments