Skip to content

Commit 07a8272

Browse files
author
Kartik Raj
committed
Retrigger discovery in background if something has changed (#14944)
1 parent 984799a commit 07a8272

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/client/pythonEnvironments/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export function initialize(ext: ExtensionState): PythonEnvironments {
5555
ext.legacyIOC.serviceManager,
5656
api,
5757
environmentsSecurity,
58+
ext.disposables
5859
);
5960

6061
return api;

src/client/pythonEnvironments/legacyIOC.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { injectable } from 'inversify';
55
import * as vscode from 'vscode';
66
import { IExtensionSingleActivationService } from '../activation/types';
77
import { DiscoveryVariants } from '../common/experiments/groups';
8+
import { IDisposableRegistry } from '../common/types';
89
import { getVersionString, parseVersion } from '../common/utils/version';
910
import {
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
}

src/test/pythonEnvironments/legacyIOC.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ export function registerForIOC(
2323
serviceManager,
2424
instance(mock(PythonEnvironments)),
2525
instance(mock(EnvironmentsSecurity)),
26+
[]
2627
);
2728
}

0 commit comments

Comments
 (0)