@@ -66,6 +66,7 @@ import { EnvironmentManagers, ProjectCreators, PythonProjectManager } from './in
6666import { registerSystemPythonFeatures } from './managers/builtin/main' ;
6767import { SysPythonManager } from './managers/builtin/sysPythonManager' ;
6868import { createNativePythonFinder , NativePythonFinder } from './managers/common/nativePythonFinder' ;
69+ import { IDisposable } from './managers/common/types' ;
6970import { registerCondaFeatures } from './managers/conda/main' ;
7071import { registerPoetryFeatures } from './managers/poetry/main' ;
7172import { registerPyenvFeatures } from './managers/pyenv/main' ;
@@ -149,17 +150,13 @@ async function collectEnvironmentInfo(
149150}
150151
151152export async function activate ( context : ExtensionContext ) : Promise < PythonEnvironmentApi | undefined > {
152- // Add a 5 second delay before continuing activation
153- await new Promise ( ( resolve ) => setTimeout ( resolve , 5000 ) ) ;
154153 const useEnvironmentsExtension = getConfiguration ( 'python' ) . get < boolean > ( 'useEnvironmentsExtension' , true ) ;
155154 if ( ! useEnvironmentsExtension ) {
156155 traceWarn (
157156 'The Python environments extension has been disabled via a setting. If you would like to opt into using the extension, please add the following to your user settings (note that updating this setting requires a window reload afterwards):\n\n"python.useEnvironmentsExtension": true' ,
158157 ) ;
158+ deactivate ( context ) ;
159159 return ;
160- // const extension = extensions.getExtension(context.extension.id);
161- // if (extension) {
162- // await extension.deactivate();
163160 } else {
164161 const start = new StopWatch ( ) ;
165162
@@ -468,4 +465,24 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
468465 }
469466}
470467
471- export function deactivate ( ) { }
468+ /**
469+ * Safely dispose each of the disposables.
470+ */
471+ export async function disposeAll ( disposables : IDisposable [ ] ) : Promise < void > {
472+ await Promise . all (
473+ disposables . map ( async ( d ) => {
474+ try {
475+ return Promise . resolve ( d . dispose ( ) ) ;
476+ } catch ( _err ) {
477+ // do nothing
478+ }
479+ return Promise . resolve ( ) ;
480+ } ) ,
481+ ) ;
482+ }
483+
484+ export async function deactivate ( context : ExtensionContext ) {
485+ await disposeAll ( context . subscriptions ) ;
486+ context . subscriptions . length = 0 ; // Clear subscriptions to prevent memory leaks
487+ traceInfo ( 'Python Environments extension deactivated.' ) ;
488+ }
0 commit comments