@@ -20,21 +20,29 @@ import {
2020 SetEnvironmentScope ,
2121} from '../../api' ;
2222import { CondaStrings } from '../../common/localize' ;
23- import { traceError } from '../../common/logging' ;
23+ import { traceError , traceInfo } from '../../common/logging' ;
24+ import { StopWatch } from '../../common/stopWatch' ;
25+ import { EventNames } from '../../common/telemetry/constants' ;
26+ import { classifyError } from '../../common/telemetry/errorClassifier' ;
27+ import { sendTelemetryEvent } from '../../common/telemetry/sender' ;
2428import { createDeferred , Deferred } from '../../common/utils/deferred' ;
2529import { normalizePath } from '../../common/utils/pathUtils' ;
2630import { showErrorMessage , showInformationMessage , withProgress } from '../../common/window.apis' ;
31+ import { PythonProjectManager } from '../../internal.api' ;
2732import { getProjectFsPathForScope , tryFastPathGet } from '../common/fastPath' ;
2833import { NativePythonFinder } from '../common/nativePythonFinder' ;
29- import { CondaSourcingStatus } from './condaSourcingUtils' ;
34+ import { notifyMissingManagerIfDefault } from '../common/utils' ;
35+ import { constructCondaSourcingStatus , CondaSourcingStatus } from './condaSourcingUtils' ;
3036import {
3137 checkForNoPythonCondaEnvironment ,
3238 clearCondaCache ,
3339 createCondaEnvironment ,
3440 deleteCondaEnvironment ,
3541 generateName ,
42+ getConda ,
3643 getCondaForGlobal ,
3744 getCondaForWorkspace ,
45+ getCondaPathSetting ,
3846 getDefaultCondaPrefix ,
3947 quickCreateConda ,
4048 refreshCondaEnvs ,
@@ -61,6 +69,7 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
6169 private readonly nativeFinder : NativePythonFinder ,
6270 private readonly api : PythonEnvironmentApi ,
6371 public readonly log : LogOutputChannel ,
72+ private readonly projectManager ?: PythonProjectManager ,
6473 ) {
6574 this . name = 'conda' ;
6675 this . displayName = 'Conda' ;
@@ -87,8 +96,27 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
8796 }
8897
8998 this . _initialized = createDeferred ( ) ;
99+ const stopWatch = new StopWatch ( ) ;
100+ let result : 'success' | 'tool_not_found' | 'error' = 'success' ;
101+ let envCount = 0 ;
102+ let toolSource = 'none' ;
103+ let errorType : string | undefined ;
90104
91105 try {
106+ // Check if tool is findable before PET refresh (settings/cache/persistent state/PATH only, no PET).
107+ // Calling getConda() without a native finder skips the PET refresh path inside getCondaExecutable.
108+ const hasExplicitSetting = ! ! getCondaPathSetting ( ) ;
109+ let condaTool : string | undefined ;
110+ try {
111+ condaTool = await getConda ( ) ;
112+ } catch {
113+ condaTool = undefined ;
114+ }
115+ const preRefreshTool = condaTool ;
116+ if ( preRefreshTool ) {
117+ toolSource = hasExplicitSetting ? 'settings' : 'local' ;
118+ }
119+
92120 await withProgress (
93121 {
94122 location : ProgressLocation . Window ,
@@ -104,7 +132,47 @@ export class CondaEnvManager implements EnvironmentManager, Disposable {
104132 ) ;
105133 } ,
106134 ) ;
135+
136+ envCount = this . collection . length ;
137+
138+ // If tool wasn't found via local lookup, check if refresh discovered it via PET
139+ // (refreshCondaEnvs persists the conda path it found from native data).
140+ if ( ! preRefreshTool ) {
141+ try {
142+ condaTool = await getConda ( ) ;
143+ } catch {
144+ condaTool = undefined ;
145+ }
146+ toolSource = condaTool ? 'pet' : 'none' ;
147+ }
148+
149+ if ( toolSource === 'none' ) {
150+ result = 'tool_not_found' ;
151+ traceInfo ( 'Conda not found, conda features will be inactive.' ) ;
152+ if ( this . projectManager ) {
153+ await notifyMissingManagerIfDefault ( 'ms-python.python:conda' , this . projectManager , this . api ) ;
154+ }
155+ } else if ( condaTool ) {
156+ // Conda was found — populate sourcing information for activation/shell support.
157+ try {
158+ this . sourcingInformation = await constructCondaSourcingStatus ( condaTool ) ;
159+ traceInfo ( this . sourcingInformation . toString ( ) ) ;
160+ } catch ( ex ) {
161+ traceError ( 'Failed to construct conda sourcing status' , ex ) ;
162+ }
163+ }
164+ } catch ( ex ) {
165+ result = 'error' ;
166+ errorType = classifyError ( ex ) ;
167+ traceError ( 'Conda lazy initialization failed' , ex ) ;
107168 } finally {
169+ sendTelemetryEvent ( EventNames . MANAGER_LAZY_INIT , stopWatch . elapsedTime , {
170+ managerName : 'conda' ,
171+ result,
172+ envCount,
173+ toolSource,
174+ errorType,
175+ } ) ;
108176 this . _initialized . resolve ( ) ;
109177 }
110178 }
0 commit comments