Skip to content

Commit 5b49842

Browse files
eleanorjboydCopilot
andcommitted
cleanup
Co-authored-by: Copilot <copilot@github.com>
1 parent 07bde98 commit 5b49842

1 file changed

Lines changed: 8 additions & 33 deletions

File tree

src/features/interpreterSelection.ts

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ export async function applyInitialEnvironmentSelection(
290290
`[interpreterSelection] Applying initial environment selection for ${folders.length} workspace folder(s)`,
291291
);
292292

293-
// Checkpoint 1: env selection starting — managers are registered
294293
sendTelemetryEvent(EventNames.ENV_SELECTION_STARTED, activationToReadyDurationMs, {
295294
registeredManagerCount: envManagers.managers.length,
296295
registeredManagerIds: envManagers.managers.map((m) => m.id).join(','),
@@ -314,17 +313,13 @@ export async function applyInitialEnvironmentSelection(
314313
);
315314
allErrors.push(...errors);
316315

317-
// Checkpoint 2: priority chain resolved — which path?
318-
const isPathA = result.environment !== undefined;
319-
320-
// Get the specific environment if not already resolved
321316
const env = result.environment ?? (await result.manager.get(folder.uri));
322317

323318
sendTelemetryEvent(EventNames.ENV_SELECTION_RESULT, scopeStopWatch.elapsedTime, {
324319
scope: 'workspace',
325320
prioritySource: result.source,
326321
managerId: result.manager.id,
327-
resolutionPath: isPathA ? 'envPreResolved' : 'managerDiscovery',
322+
resolutionPath: result.environment ? 'envPreResolved' : 'managerDiscovery',
328323
hasPersistedSelection: env !== undefined,
329324
});
330325

@@ -344,16 +339,8 @@ export async function applyInitialEnvironmentSelection(
344339
}
345340
}
346341

347-
// Global scope: resolve a fallback Python environment for files opened OUTSIDE all
348-
// workspace folders (e.g., /tmp/script.py). This is NOT a workspace folder — every
349-
// workspace folder was already fully resolved and cached in the for-loop above,
350-
// so switching between workspace folders is unaffected by whether this runs now or later.
351-
//
352-
// When at least one workspace folder resolved, we defer global scope to the background
353-
// so it doesn't block post-selection startup (clearHangWatchdog, terminal init, telemetry).
354-
// Errors inside resolveGlobalScope are handled internally:
355-
// - Setting resolution errors (bad paths, unknown managers) → notifyUserOfSettingErrors
356-
// - Unexpected crashes → logged via traceError, never silently swallowed
342+
// Resolve global scope (fallback for files outside workspace folders).
343+
// Deferred to background when a workspace folder already resolved.
357344
const resolveGlobalScope = async (): Promise<SettingResolutionError[]> => {
358345
try {
359346
const globalStopWatch = new StopWatch();
@@ -365,17 +352,17 @@ export async function applyInitialEnvironmentSelection(
365352
api,
366353
);
367354

368-
const isPathA = result.environment !== undefined;
369355
const env = result.environment ?? (await result.manager.get(undefined));
370356

371357
sendTelemetryEvent(EventNames.ENV_SELECTION_RESULT, globalStopWatch.elapsedTime, {
372358
scope: 'global',
373359
prioritySource: result.source,
374360
managerId: result.manager.id,
375-
resolutionPath: isPathA ? 'envPreResolved' : 'managerDiscovery',
361+
resolutionPath: result.environment ? 'envPreResolved' : 'managerDiscovery',
376362
hasPersistedSelection: env !== undefined,
377363
});
378364

365+
// Cache only — NO settings.json write
379366
await envManagers.setEnvironments('global', env, false);
380367

381368
traceInfo(`[interpreterSelection] global: ${env?.displayName ?? 'none'} (source: ${result.source})`);
@@ -388,13 +375,7 @@ export async function applyInitialEnvironmentSelection(
388375
};
389376

390377
if (workspaceFolderResolved) {
391-
// At least one workspace folder got a non-undefined environment (in multi-root,
392-
// ANY folder succeeding is sufficient). ALL workspace folder envs are already
393-
// active via setEnvironment calls in the loop — switching between folders in a
394-
// multi-root workspace is not affected by deferring the global scope.
395-
// Defer global scope to a background task so we don't block post-selection
396-
// startup work in extension.ts (clearHangWatchdog, terminal init, telemetry).
397-
// Global errors are notified separately since we can't aggregate with workspace errors.
378+
// Defer global scope so it doesn't block post-selection startup.
398379
traceInfo('[interpreterSelection] Workspace env resolved, deferring global scope to background');
399380
resolveGlobalScope()
400381
.then(async (globalErrors) => {
@@ -404,11 +385,7 @@ export async function applyInitialEnvironmentSelection(
404385
})
405386
.catch((err) => traceError(`[interpreterSelection] Background global scope resolution failed: ${err}`));
406387
} else {
407-
// Either: (a) no workspace folders are open, (b) every folder resolved with
408-
// env=undefined (no Python found), or (c) every folder threw an error.
409-
// In all cases the global environment is the user's primary fallback,
410-
// so we must await it before returning. Errors are aggregated with workspace
411-
// errors so notifyUserOfSettingErrors can dedupe across both scopes.
388+
// No workspace folder resolved — global scope is the primary fallback, must await.
412389
const globalErrors = await resolveGlobalScope();
413390
allErrors.push(...globalErrors);
414391
}
@@ -418,9 +395,7 @@ export async function applyInitialEnvironmentSelection(
418395
await notifyUserOfSettingErrors(allErrors);
419396
}
420397

421-
// Checkpoint 3: env selection function returning — duration measures blocking time only.
422-
// If globalScopeDeferred=true, the global scope is still running in the background
423-
// and its duration is NOT included in this measurement.
398+
// Duration measures blocking time only (excludes deferred global scope).
424399
sendTelemetryEvent(EventNames.ENV_SELECTION_COMPLETED, selectionStopWatch.elapsedTime, {
425400
globalScopeDeferred: workspaceFolderResolved,
426401
workspaceFolderCount: folders.length,

0 commit comments

Comments
 (0)