6
6
import { inject , injectable } from 'inversify' ;
7
7
import { Event , EventEmitter , Uri } from 'vscode' ;
8
8
import { IWorkspaceService } from '../../common/application/types' ;
9
+ import { DiscoveryUsingWorkers } from '../../common/experiments/groups' ;
9
10
import '../../common/extensions' ;
10
11
import { IFileSystem } from '../../common/platform/types' ;
11
- import { IPersistentState , IPersistentStateFactory , Resource } from '../../common/types' ;
12
+ import { IExperimentService , IPersistentState , IPersistentStateFactory , Resource } from '../../common/types' ;
12
13
import { createDeferred , Deferred } from '../../common/utils/async' ;
13
14
import { compareSemVerLikeVersions } from '../../pythonEnvironments/base/info/pythonVersion' ;
15
+ import { ProgressReportStage } from '../../pythonEnvironments/base/locator' ;
14
16
import { PythonEnvironment } from '../../pythonEnvironments/info' ;
15
17
import { sendTelemetryEvent } from '../../telemetry' ;
16
18
import { EventName } from '../../telemetry/constants' ;
@@ -44,6 +46,7 @@ export class InterpreterAutoSelectionService implements IInterpreterAutoSelectio
44
46
@inject ( IInterpreterComparer ) private readonly envTypeComparer : IInterpreterComparer ,
45
47
@inject ( IInterpreterAutoSelectionProxyService ) proxy : IInterpreterAutoSelectionProxyService ,
46
48
@inject ( IInterpreterHelper ) private readonly interpreterHelper : IInterpreterHelper ,
49
+ @inject ( IExperimentService ) private readonly experimentService : IExperimentService ,
47
50
) {
48
51
proxy . registerInstance ! ( this ) ;
49
52
}
@@ -183,7 +186,7 @@ export class InterpreterAutoSelectionService implements IInterpreterAutoSelectio
183
186
184
187
private getAutoSelectionQueriedOnceState ( ) : IPersistentState < boolean | undefined > {
185
188
const key = `autoSelectionInterpretersQueriedOnce` ;
186
- return this . stateFactory . createWorkspacePersistentState ( key , undefined ) ;
189
+ return this . stateFactory . createGlobalPersistentState ( key , undefined ) ;
187
190
}
188
191
189
192
/**
@@ -199,22 +202,44 @@ export class InterpreterAutoSelectionService implements IInterpreterAutoSelectio
199
202
private async autoselectInterpreterWithLocators ( resource : Resource ) : Promise < void > {
200
203
// Do not perform a full interpreter search if we already have cached interpreters for this workspace.
201
204
const queriedState = this . getAutoSelectionInterpretersQueryState ( resource ) ;
202
- if ( queriedState . value !== true && resource ) {
205
+ const globalQueriedState = this . getAutoSelectionQueriedOnceState ( ) ;
206
+ if ( globalQueriedState . value && queriedState . value !== true && resource ) {
203
207
await this . interpreterService . triggerRefresh ( {
204
208
searchLocations : { roots : [ resource ] , doNotIncludeNonRooted : true } ,
205
209
} ) ;
206
210
}
207
211
208
- const globalQueriedState = this . getAutoSelectionQueriedOnceState ( ) ;
209
- if ( ! globalQueriedState . value ) {
210
- // Global interpreters are loaded the first time an extension loads, after which we don't need to
211
- // wait on global interpreter promise refresh.
212
- await this . interpreterService . refreshPromise ;
213
- }
214
- const interpreters = this . interpreterService . getInterpreters ( resource ) ;
212
+ const inExperiment = this . experimentService . inExperimentSync ( DiscoveryUsingWorkers . experiment ) ;
215
213
const workspaceUri = this . interpreterHelper . getActiveWorkspaceUri ( resource ) ;
214
+ let recommendedInterpreter : PythonEnvironment | undefined ;
215
+ if ( inExperiment ) {
216
+ if ( ! globalQueriedState . value ) {
217
+ // Global interpreters are loaded the first time an extension loads, after which we don't need to
218
+ // wait on global interpreter promise refresh.
219
+ // Do not wait for validation of all interpreters to finish, we only need to validate the recommended interpreter.
220
+ await this . interpreterService . getRefreshPromise ( { stage : ProgressReportStage . allPathsDiscovered } ) ;
221
+ }
222
+ let interpreters = this . interpreterService . getInterpreters ( resource ) ;
223
+
224
+ recommendedInterpreter = this . envTypeComparer . getRecommended ( interpreters , workspaceUri ?. folderUri ) ;
225
+ const details = recommendedInterpreter
226
+ ? await this . interpreterService . getInterpreterDetails ( recommendedInterpreter . path )
227
+ : undefined ;
228
+ if ( ! details || ! recommendedInterpreter ) {
229
+ await this . interpreterService . refreshPromise ; // Interpreter is invalid, wait for all of validation to finish.
230
+ interpreters = this . interpreterService . getInterpreters ( resource ) ;
231
+ recommendedInterpreter = this . envTypeComparer . getRecommended ( interpreters , workspaceUri ?. folderUri ) ;
232
+ }
233
+ } else {
234
+ if ( ! globalQueriedState . value ) {
235
+ // Global interpreters are loaded the first time an extension loads, after which we don't need to
236
+ // wait on global interpreter promise refresh.
237
+ await this . interpreterService . refreshPromise ;
238
+ }
239
+ const interpreters = this . interpreterService . getInterpreters ( resource ) ;
216
240
217
- const recommendedInterpreter = this . envTypeComparer . getRecommended ( interpreters , workspaceUri ?. folderUri ) ;
241
+ recommendedInterpreter = this . envTypeComparer . getRecommended ( interpreters , workspaceUri ?. folderUri ) ;
242
+ }
218
243
if ( ! recommendedInterpreter ) {
219
244
return ;
220
245
}
0 commit comments