@@ -20,10 +20,11 @@ import {
2020 SetEnvironmentScope ,
2121} from '../../api' ;
2222import { CondaStrings } from '../../common/localize' ;
23- import { traceError , traceWarn } from '../../common/logging' ;
23+ import { traceError } from '../../common/logging' ;
2424import { createDeferred , Deferred } from '../../common/utils/deferred' ;
2525import { normalizePath } from '../../common/utils/pathUtils' ;
2626import { showErrorMessage , showInformationMessage , withProgress } from '../../common/window.apis' ;
27+ import { tryFastPathGet } from '../common/fastPath' ;
2728import { NativePythonFinder } from '../common/nativePythonFinder' ;
2829import { CondaSourcingStatus } from './condaSourcingUtils' ;
2930import {
@@ -260,54 +261,30 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
260261 }
261262 }
262263 async get ( scope : GetEnvironmentScope ) : Promise < PythonEnvironment | undefined > {
263- // Fast path: if init hasn't completed yet and we have a persisted env, resolve it
264- // directly without waiting for full discovery
265- if ( ( ! this . _initialized || ! this . _initialized . completed ) && scope instanceof Uri ) {
266- const project = this . api . getPythonProject ( scope ) ;
267- const fsPath = project ?. uri . fsPath ?? scope . fsPath ;
268- const persistedPath = await getCondaForWorkspace ( fsPath ) ;
269-
270- if ( persistedPath ) {
271- try {
272- const resolved = await resolveCondaPath ( persistedPath , this . nativeFinder , this . api , this . log , this ) ;
273- if ( resolved ) {
274- // Ensure full init is running in background (may already be in progress)
275- if ( ! this . _initialized ) {
276- this . _initialized = createDeferred ( ) ;
277- withProgress (
278- { location : ProgressLocation . Window , title : CondaStrings . condaDiscovering } ,
279- async ( ) => {
280- this . collection = await refreshCondaEnvs (
281- false ,
282- this . nativeFinder ,
283- this . api ,
284- this . log ,
285- this ,
286- ) ;
287- await this . loadEnvMap ( ) ;
288- this . _onDidChangeEnvironments . fire (
289- this . collection . map ( ( e ) => ( {
290- environment : e ,
291- kind : EnvironmentChangeKind . add ,
292- } ) ) ,
293- ) ;
294- } ,
295- ) . then (
296- ( ) => this . _initialized ! . resolve ( ) ,
297- ( err ) => {
298- traceError ( `[conda] Background initialization failed: ${ err } ` ) ;
299- this . _initialized ! . resolve ( ) ;
300- } ,
301- ) ;
302- }
303- return resolved ;
304- }
305- } catch ( err ) {
306- traceWarn (
307- `[conda] Fast path resolve failed for '${ persistedPath } ', falling back to full init: ${ err } ` ,
264+ const fastResult = await tryFastPathGet ( {
265+ initialized : this . _initialized ,
266+ scope,
267+ label : 'conda' ,
268+ getProjectFsPath : ( s ) => this . api . getPythonProject ( s ) ?. uri . fsPath ?? s . fsPath ,
269+ getPersistedPath : ( fsPath ) => getCondaForWorkspace ( fsPath ) ,
270+ resolve : ( p ) => resolveCondaPath ( p , this . nativeFinder , this . api , this . log , this ) ,
271+ startBackgroundInit : ( ) =>
272+ withProgress ( { location : ProgressLocation . Window , title : CondaStrings . condaDiscovering } , async ( ) => {
273+ this . collection = await refreshCondaEnvs ( false , this . nativeFinder , this . api , this . log , this ) ;
274+ await this . loadEnvMap ( ) ;
275+ this . _onDidChangeEnvironments . fire (
276+ this . collection . map ( ( e ) => ( {
277+ environment : e ,
278+ kind : EnvironmentChangeKind . add ,
279+ } ) ) ,
308280 ) ;
309- }
281+ } ) ,
282+ } ) ;
283+ if ( fastResult ) {
284+ if ( fastResult . newDeferred ) {
285+ this . _initialized = fastResult . newDeferred ;
310286 }
287+ return fastResult . env ;
311288 }
312289
313290 await this . initialize ( ) ;
0 commit comments