Skip to content

Commit 031c4b8

Browse files
author
Kartik Raj
authored
Revert "Only trigger auto environment discovery once in the first session for a particular scope (#19145)" (#19159)
This reverts commit 2de8125.
1 parent 2de8125 commit 031c4b8

File tree

2 files changed

+11
-39
lines changed

2 files changed

+11
-39
lines changed

news/1 Enhancements/19102.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/client/pythonEnvironments/index.ts

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ import { PythonEnvsReducer } from './base/locators/composite/envsReducer';
1212
import { PythonEnvsResolver } from './base/locators/composite/envsResolver';
1313
import { WindowsPathEnvVarLocator } from './base/locators/lowLevel/windowsKnownPathsLocator';
1414
import { WorkspaceVirtualEnvironmentLocator } from './base/locators/lowLevel/workspaceVirtualEnvLocator';
15-
import {
16-
initializeExternalDependencies as initializeLegacyExternalDependencies,
17-
normCasePath,
18-
} from './common/externalDependencies';
15+
import { initializeExternalDependencies as initializeLegacyExternalDependencies } from './common/externalDependencies';
1916
import { ExtensionLocators, WatchRootsArgs, WorkspaceLocators } from './base/locators/wrappers';
2017
import { CustomVirtualEnvironmentLocator } from './base/locators/lowLevel/customVirtualEnvLocator';
2118
import { CondaEnvironmentLocator } from './base/locators/lowLevel/condaLocator';
@@ -55,44 +52,20 @@ export async function initialize(ext: ExtensionState): Promise<IDiscoveryAPI> {
5552
/**
5653
* Make use of the component (e.g. register with VS Code).
5754
*/
58-
export async function activate(api: IDiscoveryAPI, ext: ExtensionState): Promise<ActivationResult> {
55+
export async function activate(api: IDiscoveryAPI, _ext: ExtensionState): Promise<ActivationResult> {
5956
/**
6057
* Force an initial background refresh of the environments.
6158
*
62-
* Note API is ready to be queried only after a refresh has been triggered, and extension activation is
63-
* blocked on API being ready. So if discovery was never triggered for a scope, we need to block
64-
* extension activation on the "refresh trigger".
59+
* Note API is ready to be queried only after a refresh has been triggered, and extension activation is blocked on API. So,
60+
* * If discovery was never triggered, we need to block extension activation on the refresh trigger.
61+
* * If discovery was already triggered, it maybe the case that this is a new workspace for which it hasn't been triggered yet.
62+
* So always trigger discovery as part of extension activation for now.
63+
*
64+
* TODO: https://github.com/microsoft/vscode-python/issues/17498
65+
* Once `onInterpretersChanged` event is exposed via API, we can probably expect extensions to rely on that and
66+
* discovery can be triggered after activation, especially in the second case.
6567
*/
66-
const folders = vscode.workspace.workspaceFolders;
67-
const wasTriggered = getGlobalStorage<boolean>(ext.context, 'PYTHON_WAS_DISCOVERY_TRIGGERED', false);
68-
if (!wasTriggered.get()) {
69-
api.triggerRefresh().ignoreErrors();
70-
wasTriggered.set(true).then(() => {
71-
folders?.forEach(async (folder) => {
72-
const wasTriggeredForFolder = getGlobalStorage<boolean>(
73-
ext.context,
74-
`PYTHON_WAS_DISCOVERY_TRIGGERED_${normCasePath(folder.uri.fsPath)}`,
75-
false,
76-
);
77-
await wasTriggeredForFolder.set(true);
78-
});
79-
});
80-
} else {
81-
// Figure out which workspace folders need to be activated.
82-
folders?.forEach(async (folder) => {
83-
const wasTriggeredForFolder = getGlobalStorage<boolean>(
84-
ext.context,
85-
`PYTHON_WAS_DISCOVERY_TRIGGERED_${normCasePath(folder.uri.fsPath)}`,
86-
false,
87-
);
88-
if (!wasTriggeredForFolder.get()) {
89-
api.triggerRefresh({
90-
searchLocations: { roots: [folder.uri], doNotIncludeNonRooted: true },
91-
}).ignoreErrors();
92-
await wasTriggeredForFolder.set(true);
93-
}
94-
});
95-
}
68+
api.triggerRefresh().ignoreErrors();
9669

9770
return {
9871
fullyReady: Promise.resolve(),

0 commit comments

Comments
 (0)