|
1 | 1 | import * as path from 'path'; |
2 | 2 | import { ConfigurationScope, ConfigurationTarget, Uri, WorkspaceConfiguration, WorkspaceFolder } from 'vscode'; |
3 | 3 | import { PythonProject } from '../../api'; |
4 | | -import { DEFAULT_ENV_MANAGER_ID, DEFAULT_PACKAGE_MANAGER_ID, SYSTEM_MANAGER_ID } from '../../common/constants'; |
| 4 | +import { DEFAULT_ENV_MANAGER_ID, DEFAULT_PACKAGE_MANAGER_ID } from '../../common/constants'; |
5 | 5 | import { traceError, traceInfo, traceVerbose, traceWarn } from '../../common/logging'; |
6 | | -import { getGlobalPersistentState } from '../../common/persistentState'; |
7 | 6 | import { normalizePath } from '../../common/utils/pathUtils'; |
8 | | -import { EventNames } from '../../common/telemetry/constants'; |
9 | | -import { sendTelemetryEvent } from '../../common/telemetry/sender'; |
10 | 7 | import * as workspaceApis from '../../common/workspace.apis'; |
11 | 8 | import { PythonProjectManager, PythonProjectSettings } from '../../internal.api'; |
12 | 9 |
|
@@ -584,93 +581,3 @@ export function getSettingUserScope<T>(section: string, key: string): T | undefi |
584 | 581 | } |
585 | 582 | return undefined; |
586 | 583 | } |
587 | | - |
588 | | -const MIGRATION_KEY = 'globalSettingsMigration.systemEnvManagerRemoved'; |
589 | | - |
590 | | -/** |
591 | | - * Returns true if any user-scope slot of the inspection result equals `value`. |
592 | | - * For window-scoped settings VS Code may populate `globalRemoteValue` and/or |
593 | | - * `globalLocalValue` in addition to `globalValue` depending on context. |
594 | | - */ |
595 | | -function userScopeHasValue(inspect: { globalValue?: string } | undefined, value: string): boolean { |
596 | | - if (!inspect) { |
597 | | - return false; |
598 | | - } |
599 | | - const record = inspect as Record<string, unknown>; |
600 | | - if (record.globalRemoteValue === value) { |
601 | | - return true; |
602 | | - } |
603 | | - if (record.globalLocalValue === value) { |
604 | | - return true; |
605 | | - } |
606 | | - if (inspect.globalValue === value) { |
607 | | - return true; |
608 | | - } |
609 | | - return false; |
610 | | -} |
611 | | - |
612 | | -/** |
613 | | - * One-time migration: removes `defaultEnvManager` from User (global) settings if it was |
614 | | - * set to `system` by the extension. This was an unintentional side effect of a bug where |
615 | | - * the extension wrote to User scope when no workspace was open. Having `system` at the |
616 | | - * User level causes all workspaces to ignore local .venv environments. |
617 | | - * |
618 | | - * Because `python-envs.defaultEnvManager` is a window-scoped setting, the stale value can |
619 | | - * land in any of `globalValue`, `globalLocalValue`, or `globalRemoteValue` depending on |
620 | | - * which context (local vs remote) hit the bug. We check all three, attempt removal via |
621 | | - * `ConfigurationTarget.Global` (which clears the slot for the current context), then |
622 | | - * re-inspect. If any user-scope slot still holds the stale value we do NOT mark the |
623 | | - * migration complete, so a future activation in the other context can finish the job. |
624 | | - * |
625 | | - * See: https://github.com/microsoft/vscode-python-environments/issues/1468 |
626 | | - */ |
627 | | -export async function migrateGlobalDefaultEnvManagerSetting(): Promise<void> { |
628 | | - const state = await getGlobalPersistentState(); |
629 | | - const alreadyMigrated = await state.get<boolean>(MIGRATION_KEY); |
630 | | - if (alreadyMigrated) { |
631 | | - return; |
632 | | - } |
633 | | - |
634 | | - const config = workspaceApis.getConfiguration('python-envs', undefined); |
635 | | - const inspect = config.inspect<string>('defaultEnvManager'); |
636 | | - |
637 | | - if (!userScopeHasValue(inspect, SYSTEM_MANAGER_ID)) { |
638 | | - sendTelemetryEvent(EventNames.MIGRATION_SYSTEM_ENV_MANAGER, undefined, { outcome: 'not_set' }); |
639 | | - await state.set(MIGRATION_KEY, true); |
640 | | - return; |
641 | | - } |
642 | | - |
643 | | - try { |
644 | | - await config.update('defaultEnvManager', undefined, ConfigurationTarget.Global); |
645 | | - } catch (err) { |
646 | | - // Don't mark migration done; we'll retry on a future activation. |
647 | | - traceWarn( |
648 | | - `[migration] Failed to remove 'python-envs.defaultEnvManager: ${SYSTEM_MANAGER_ID}' from User settings: ${err}`, |
649 | | - ); |
650 | | - sendTelemetryEvent(EventNames.MIGRATION_SYSTEM_ENV_MANAGER, undefined, { |
651 | | - outcome: 'failed', |
652 | | - errorType: err instanceof Error ? err.name : typeof err, |
653 | | - }); |
654 | | - return; |
655 | | - } |
656 | | - |
657 | | - // Re-inspect: `update(Global)` only clears the current context's slot. If another |
658 | | - // context's slot (local vs remote) still holds the stale value, leave the flag unset |
659 | | - // so the next activation in that context can clear it. |
660 | | - const after = config.inspect<string>('defaultEnvManager'); |
661 | | - if (userScopeHasValue(after, SYSTEM_MANAGER_ID)) { |
662 | | - traceInfo( |
663 | | - `[migration] Partially removed 'python-envs.defaultEnvManager: ${SYSTEM_MANAGER_ID}' from User settings; ` + |
664 | | - `another context still has it set. Will retry on next activation.`, |
665 | | - ); |
666 | | - sendTelemetryEvent(EventNames.MIGRATION_SYSTEM_ENV_MANAGER, undefined, { outcome: 'partial' }); |
667 | | - return; |
668 | | - } |
669 | | - |
670 | | - traceInfo( |
671 | | - `[migration] Removed 'python-envs.defaultEnvManager: ${SYSTEM_MANAGER_ID}' from User settings ` + |
672 | | - `(was set unintentionally by a previous version). See https://github.com/microsoft/vscode-python-environments/issues/1468`, |
673 | | - ); |
674 | | - sendTelemetryEvent(EventNames.MIGRATION_SYSTEM_ENV_MANAGER, undefined, { outcome: 'removed' }); |
675 | | - await state.set(MIGRATION_KEY, true); |
676 | | -} |
0 commit comments