-
Notifications
You must be signed in to change notification settings - Fork 41
Don't block on global scope during ext startup #1456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
eleanorjboyd
wants to merge
7
commits into
microsoft:main
Choose a base branch
from
eleanorjboyd:able-badger
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+337
−29
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
70932d6
defer global search if venv discovered
eleanorjboyd dddc872
feat: add telemetry for monitoring
eleanorjboyd 40fd6c1
Merge branch 'main' into able-badger
eleanorjboyd 56fd76c
fixes
eleanorjboyd 07bde98
Merge branch 'main' into able-badger
eleanorjboyd 5b49842
cleanup
eleanorjboyd aab1027
fix
eleanorjboyd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -290,14 +290,16 @@ export async function applyInitialEnvironmentSelection( | |
| `[interpreterSelection] Applying initial environment selection for ${folders.length} workspace folder(s)`, | ||
| ); | ||
|
|
||
| // Checkpoint 1: env selection starting — managers are registered | ||
| sendTelemetryEvent(EventNames.ENV_SELECTION_STARTED, activationToReadyDurationMs, { | ||
| registeredManagerCount: envManagers.managers.length, | ||
| registeredManagerIds: envManagers.managers.map((m) => m.id).join(','), | ||
| workspaceFolderCount: folders.length, | ||
| }); | ||
|
|
||
| const allErrors: SettingResolutionError[] = []; | ||
| let workspaceFolderResolved = false; | ||
| let resolvedFolderCount = 0; | ||
| const selectionStopWatch = new StopWatch(); | ||
|
|
||
| for (const folder of folders) { | ||
| try { | ||
|
|
@@ -311,23 +313,24 @@ export async function applyInitialEnvironmentSelection( | |
| ); | ||
| allErrors.push(...errors); | ||
|
|
||
| // Checkpoint 2: priority chain resolved — which path? | ||
| const isPathA = result.environment !== undefined; | ||
|
|
||
| // Get the specific environment if not already resolved | ||
| const env = result.environment ?? (await result.manager.get(folder.uri)); | ||
|
|
||
| sendTelemetryEvent(EventNames.ENV_SELECTION_RESULT, scopeStopWatch.elapsedTime, { | ||
| scope: 'workspace', | ||
| prioritySource: result.source, | ||
| managerId: result.manager.id, | ||
| resolutionPath: isPathA ? 'envPreResolved' : 'managerDiscovery', | ||
| resolutionPath: result.environment ? 'envPreResolved' : 'managerDiscovery', | ||
| hasPersistedSelection: env !== undefined, | ||
| }); | ||
|
|
||
| // Cache only — NO settings.json write (shouldPersistSettings = false) | ||
| await envManagers.setEnvironment(folder.uri, env, false); | ||
|
|
||
| if (env) { | ||
| workspaceFolderResolved = true; | ||
| resolvedFolderCount++; | ||
| } | ||
|
|
||
| traceInfo( | ||
| `[interpreterSelection] ${folder.name}: ${env?.displayName ?? 'none'} (source: ${result.source})`, | ||
| ); | ||
|
|
@@ -336,38 +339,69 @@ export async function applyInitialEnvironmentSelection( | |
| } | ||
| } | ||
|
|
||
| // Also apply initial selection for global scope (no workspace folder) | ||
| // This ensures defaultInterpreterPath is respected even without a workspace | ||
| try { | ||
| const globalStopWatch = new StopWatch(); | ||
| const { result, errors } = await resolvePriorityChainCore(undefined, envManagers, undefined, nativeFinder, api); | ||
| allErrors.push(...errors); | ||
| // Resolve global scope (fallback for files outside workspace folders). | ||
| // Deferred to background when a workspace folder already resolved. | ||
| const resolveGlobalScope = async (): Promise<SettingResolutionError[]> => { | ||
| try { | ||
| const globalStopWatch = new StopWatch(); | ||
| const { result, errors: globalErrors } = await resolvePriorityChainCore( | ||
| undefined, | ||
| envManagers, | ||
| undefined, | ||
| nativeFinder, | ||
| api, | ||
| ); | ||
|
|
||
| const isPathA = result.environment !== undefined; | ||
| const env = result.environment ?? (await result.manager.get(undefined)); | ||
|
|
||
| // Get the specific environment if not already resolved | ||
| const env = result.environment ?? (await result.manager.get(undefined)); | ||
| sendTelemetryEvent(EventNames.ENV_SELECTION_RESULT, globalStopWatch.elapsedTime, { | ||
| scope: 'global', | ||
| prioritySource: result.source, | ||
| managerId: result.manager.id, | ||
| resolutionPath: result.environment ? 'envPreResolved' : 'managerDiscovery', | ||
| hasPersistedSelection: env !== undefined, | ||
| }); | ||
|
|
||
| sendTelemetryEvent(EventNames.ENV_SELECTION_RESULT, globalStopWatch.elapsedTime, { | ||
| scope: 'global', | ||
| prioritySource: result.source, | ||
| managerId: result.manager.id, | ||
| resolutionPath: isPathA ? 'envPreResolved' : 'managerDiscovery', | ||
| hasPersistedSelection: env !== undefined, | ||
| }); | ||
| // Cache only — NO settings.json write | ||
| await envManagers.setEnvironments('global', env, false); | ||
|
|
||
| // Cache only — NO settings.json write (shouldPersistSettings = false) | ||
| await envManagers.setEnvironments('global', env, false); | ||
| traceInfo(`[interpreterSelection] global: ${env?.displayName ?? 'none'} (source: ${result.source})`); | ||
|
|
||
| traceInfo(`[interpreterSelection] global: ${env?.displayName ?? 'none'} (source: ${result.source})`); | ||
| } catch (err) { | ||
| traceError(`[interpreterSelection] Failed to set global environment: ${err}`); | ||
| return globalErrors; | ||
| } catch (err) { | ||
| traceError(`[interpreterSelection] Failed to set global environment: ${err}`); | ||
| return []; | ||
| } | ||
| }; | ||
|
|
||
| if (workspaceFolderResolved) { | ||
| // Defer global scope so it doesn't block post-selection startup. | ||
| traceInfo('[interpreterSelection] Workspace env resolved, deferring global scope to background'); | ||
| resolveGlobalScope() | ||
| .then(async (globalErrors) => { | ||
| if (globalErrors.length > 0) { | ||
| await notifyUserOfSettingErrors(globalErrors); | ||
| } | ||
| }) | ||
| .catch((err) => traceError(`[interpreterSelection] Background global scope resolution failed: ${err}`)); | ||
| } else { | ||
| // No workspace folder resolved — global scope is the primary fallback, must await. | ||
| const globalErrors = await resolveGlobalScope(); | ||
| allErrors.push(...globalErrors); | ||
| } | ||
|
|
||
| // Notify user if any settings could not be applied | ||
| // Notify user if any settings could not be applied (workspace + global when awaited) | ||
| if (allErrors.length > 0) { | ||
| await notifyUserOfSettingErrors(allErrors); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be producing duplicate dialogs as the await notifyUserOfSettingErrors(globalErrors) at the same time? |
||
| } | ||
|
|
||
| // Duration measures blocking time only (excludes deferred global scope). | ||
| sendTelemetryEvent(EventNames.ENV_SELECTION_COMPLETED, selectionStopWatch.elapsedTime, { | ||
| globalScopeDeferred: workspaceFolderResolved, | ||
| workspaceFolderCount: folders.length, | ||
| resolvedFolderCount, | ||
| settingErrorCount: allErrors.length, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.