1- import { commands , ExtensionContext , LogOutputChannel , Terminal , Uri } from 'vscode' ;
1+ import { commands , ExtensionContext , LogOutputChannel , Terminal , Uri , window } from 'vscode' ;
22import { PythonEnvironment , PythonEnvironmentApi } from './api' ;
33import { ensureCorrectVersion } from './common/extVersion' ;
44import { registerTools } from './common/lm.apis' ;
@@ -13,7 +13,6 @@ import {
1313 activeTerminal ,
1414 createLogOutputChannel ,
1515 onDidChangeActiveTerminal ,
16- onDidChangeActiveTextEditor ,
1716 onDidChangeTerminalShellIntegration ,
1817} from './common/window.apis' ;
1918import { createManagerReady } from './features/common/managerReady' ;
@@ -88,6 +87,14 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
8887 const projectManager : PythonProjectManager = new PythonProjectManagerImpl ( ) ;
8988 context . subscriptions . push ( projectManager ) ;
9089
90+ // Helper function to check if a resource is an existing Python project
91+ const isExistingProject = ( uri : Uri | undefined ) : boolean => {
92+ if ( ! uri ) {
93+ return false ;
94+ }
95+ return projectManager . get ( uri ) !== undefined ;
96+ } ;
97+
9198 const envVarManager : EnvVarManager = new PythonEnvVariableManager ( projectManager ) ;
9299 context . subscriptions . push ( envVarManager ) ;
93100
@@ -194,6 +201,10 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
194201 await setPackageManagerCommand ( envManagers , projectManager ) ;
195202 } ) ,
196203 commands . registerCommand ( 'python-envs.addPythonProject' , async ( resource ) => {
204+ // Set context to show/hide menu item depending on whether the resource is already a Python project
205+ if ( resource instanceof Uri ) {
206+ commands . executeCommand ( 'setContext' , 'python-envs:isExistingProject' , isExistingProject ( resource ) ) ;
207+ }
197208 await addPythonProjectCommand ( resource , projectManager , envManagers , projectCreators ) ;
198209 } ) ,
199210 commands . registerCommand ( 'python-envs.removePythonProject' , async ( item ) => {
@@ -254,7 +265,7 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
254265 }
255266 }
256267 } ) ,
257- onDidChangeActiveTextEditor ( async ( ) => {
268+ window . onDidChangeActiveTextEditor ( async ( ) => {
258269 updateViewsAndStatus ( statusBar , workspaceView , managerView , api ) ;
259270 } ) ,
260271 envManagers . onDidChangeEnvironment ( async ( ) => {
0 commit comments