1- import { commands , extensions , ExtensionContext , LogOutputChannel , Terminal , Uri , window , workspace } from 'vscode' ;
1+ import { commands , ExtensionContext , extensions , LogOutputChannel , Terminal , Uri , window , workspace } from 'vscode' ;
22import { PythonEnvironment , PythonEnvironmentApi , PythonProjectCreator } from './api' ;
33import { ensureCorrectVersion } from './common/extVersion' ;
44import { registerLogger , traceError , traceInfo } from './common/logging' ;
@@ -8,6 +8,7 @@ import { StopWatch } from './common/stopWatch';
88import { EventNames } from './common/telemetry/constants' ;
99import { sendManagerSelectionTelemetry } from './common/telemetry/helpers' ;
1010import { sendTelemetryEvent } from './common/telemetry/sender' ;
11+ import { createSimpleDebounce } from './common/utils/debounce' ;
1112import { createDeferred } from './common/utils/deferred' ;
1213import {
1314 activeTerminal ,
@@ -75,27 +76,27 @@ import { registerPyenvFeatures } from './managers/pyenv/main';
7576async function collectEnvironmentInfo (
7677 context : ExtensionContext ,
7778 envManagers : EnvironmentManagers ,
78- projectManager : PythonProjectManager
79+ projectManager : PythonProjectManager ,
7980) : Promise < string > {
8081 const info : string [ ] = [ ] ;
81-
82+
8283 try {
8384 // Extension version
8485 const extensionVersion = context . extension ?. packageJSON ?. version || 'unknown' ;
8586 info . push ( `Extension Version: ${ extensionVersion } ` ) ;
86-
87+
8788 // Python extension version
8889 const pythonExtension = extensions . getExtension ( 'ms-python.python' ) ;
8990 const pythonVersion = pythonExtension ?. packageJSON ?. version || 'not installed' ;
9091 info . push ( `Python Extension Version: ${ pythonVersion } ` ) ;
91-
92+
9293 // Environment managers
9394 const managers = envManagers . managers ;
9495 info . push ( `\nRegistered Environment Managers (${ managers . length } ):` ) ;
95- managers . forEach ( manager => {
96+ managers . forEach ( ( manager ) => {
9697 info . push ( ` - ${ manager . id } (${ manager . displayName } )` ) ;
9798 } ) ;
98-
99+
99100 // Available environments
100101 const allEnvironments : PythonEnvironment [ ] = [ ] ;
101102 for ( const manager of managers ) {
@@ -106,7 +107,7 @@ async function collectEnvironmentInfo(
106107 info . push ( ` Error getting environments from ${ manager . id } : ${ err } ` ) ;
107108 }
108109 }
109-
110+
110111 info . push ( `\nTotal Available Environments: ${ allEnvironments . length } ` ) ;
111112 if ( allEnvironments . length > 0 ) {
112113 info . push ( 'Environment Details:' ) ;
@@ -117,8 +118,9 @@ async function collectEnvironmentInfo(
117118 info . push ( ` ... and ${ allEnvironments . length - 10 } more environments` ) ;
118119 }
119120 }
120-
121+
121122 // Python projects
123+ console . log ( 'getProjects called from extension.ts activate' ) ;
122124 const projects = projectManager . getProjects ( ) ;
123125 info . push ( `\nPython Projects (${ projects . length } ):` ) ;
124126 for ( let index = 0 ; index < projects . length ; index ++ ) {
@@ -133,22 +135,25 @@ async function collectEnvironmentInfo(
133135 info . push ( ` Error getting environment: ${ err } ` ) ;
134136 }
135137 }
136-
138+
137139 // Current settings (non-sensitive)
138140 const config = workspace . getConfiguration ( 'python-envs' ) ;
139141 info . push ( '\nExtension Settings:' ) ;
140142 info . push ( ` Default Environment Manager: ${ config . get ( 'defaultEnvManager' ) } ` ) ;
141143 info . push ( ` Default Package Manager: ${ config . get ( 'defaultPackageManager' ) } ` ) ;
142144 info . push ( ` Terminal Auto Activation: ${ config . get ( 'terminal.autoActivationType' ) } ` ) ;
143-
144145 } catch ( err ) {
145146 info . push ( `\nError collecting environment information: ${ err } ` ) ;
146147 }
147-
148+
148149 return info . join ( '\n' ) ;
149150}
150151
151152export async function activate ( context : ExtensionContext ) : Promise < PythonEnvironmentApi > {
153+ // Debounced version of updateViewsAndStatus to avoid excessive UI updates
154+ const debouncedUpdateViewsAndStatus = createSimpleDebounce ( 200 , ( ) => {
155+ updateViewsAndStatus ( statusBar , workspaceView , managerView , api ) ;
156+ } ) ;
152157 const start = new StopWatch ( ) ;
153158
154159 // Logging should be set up before anything else.
@@ -366,11 +371,11 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
366371 commands . registerCommand ( 'python-envs.reportIssue' , async ( ) => {
367372 try {
368373 const issueData = await collectEnvironmentInfo ( context , envManagers , projectManager ) ;
369-
374+
370375 await commands . executeCommand ( 'workbench.action.openIssueReporter' , {
371376 extensionId : 'ms-python.vscode-python-envs' ,
372377 issueTitle : '[Python Environments] ' ,
373- issueBody : `<!-- Please describe the issue you're experiencing -->\n\n<!-- The following information was automatically generated -->\n\n<details>\n<summary>Environment Information</summary>\n\n\`\`\`\n${ issueData } \n\`\`\`\n\n</details>`
378+ issueBody : `<!-- Please describe the issue you're experiencing -->\n\n<!-- The following information was automatically generated -->\n\n<details>\n<summary>Environment Information</summary>\n\n\`\`\`\n${ issueData } \n\`\`\`\n\n</details>` ,
374379 } ) ;
375380 } catch ( error ) {
376381 window . showErrorMessage ( `Failed to open issue reporter: ${ error } ` ) ;
@@ -387,22 +392,16 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
387392 }
388393 }
389394 } ) ,
390- window . onDidChangeActiveTextEditor ( async ( ) => {
391- updateViewsAndStatus ( statusBar , workspaceView , managerView , api ) ;
392- } ) ,
393- envManagers . onDidChangeEnvironment ( async ( ) => {
394- updateViewsAndStatus ( statusBar , workspaceView , managerView , api ) ;
395+ window . onDidChangeActiveTextEditor ( ( ) => {
396+ debouncedUpdateViewsAndStatus . trigger ( ) ;
395397 } ) ,
396- envManagers . onDidChangeEnvironments ( async ( ) => {
397- updateViewsAndStatus ( statusBar , workspaceView , managerView , api ) ;
398- } ) ,
399- envManagers . onDidChangeEnvironmentFiltered ( async ( e ) => {
398+ envManagers . onDidChangeEnvironmentFiltered ( ( e ) => {
400399 managerView . environmentChanged ( e ) ;
401400 const location = e . uri ?. fsPath ?? 'global' ;
402401 traceInfo (
403402 `Internal: Changed environment from ${ e . old ?. displayName } to ${ e . new ?. displayName } for: ${ location } ` ,
404403 ) ;
405- updateViewsAndStatus ( statusBar , workspaceView , managerView , api ) ;
404+ debouncedUpdateViewsAndStatus . trigger ( ) ;
406405 } ) ,
407406 onDidChangeTerminalShellIntegration ( async ( e ) => {
408407 const shellEnv = e . shellIntegration ?. env ;
@@ -428,6 +427,16 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
428427 } ) ,
429428 ) ;
430429
430+ // Register these listeners last to avoid triggering them during activation/setup
431+ context . subscriptions . push (
432+ envManagers . onDidChangeEnvironment ( ( ) => {
433+ debouncedUpdateViewsAndStatus . trigger ( ) ;
434+ } ) ,
435+ envManagers . onDidChangeEnvironments ( ( ) => {
436+ debouncedUpdateViewsAndStatus . trigger ( ) ;
437+ } ) ,
438+ ) ;
439+
431440 /**
432441 * Below are all the contributed features using the APIs.
433442 */
0 commit comments