@@ -12,7 +12,10 @@ import { PythonEnvsReducer } from './base/locators/composite/envsReducer';
12
12
import { PythonEnvsResolver } from './base/locators/composite/envsResolver' ;
13
13
import { WindowsPathEnvVarLocator } from './base/locators/lowLevel/windowsKnownPathsLocator' ;
14
14
import { WorkspaceVirtualEnvironmentLocator } from './base/locators/lowLevel/workspaceVirtualEnvLocator' ;
15
- import { initializeExternalDependencies as initializeLegacyExternalDependencies } from './common/externalDependencies' ;
15
+ import {
16
+ initializeExternalDependencies as initializeLegacyExternalDependencies ,
17
+ normCasePath ,
18
+ } from './common/externalDependencies' ;
16
19
import { ExtensionLocators , WatchRootsArgs , WorkspaceLocators } from './base/locators/wrappers' ;
17
20
import { CustomVirtualEnvironmentLocator } from './base/locators/lowLevel/customVirtualEnvLocator' ;
18
21
import { CondaEnvironmentLocator } from './base/locators/lowLevel/condaLocator' ;
@@ -52,20 +55,44 @@ export async function initialize(ext: ExtensionState): Promise<IDiscoveryAPI> {
52
55
/**
53
56
* Make use of the component (e.g. register with VS Code).
54
57
*/
55
- export async function activate ( api : IDiscoveryAPI , _ext : ExtensionState ) : Promise < ActivationResult > {
58
+ export async function activate ( api : IDiscoveryAPI , ext : ExtensionState ) : Promise < ActivationResult > {
56
59
/**
57
60
* Force an initial background refresh of the environments.
58
61
*
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.
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".
67
65
*/
68
- api . triggerRefresh ( ) . ignoreErrors ( ) ;
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
+ }
69
96
70
97
return {
71
98
fullyReady : Promise . resolve ( ) ,
0 commit comments