@@ -32,7 +32,8 @@ import { PYTHON_EXTENSION_ID } from '../../common/constants';
3232import { VenvManagerStrings } from '../../common/localize' ;
3333import { traceError , traceWarn } from '../../common/logging' ;
3434import { createDeferred , Deferred } from '../../common/utils/deferred' ;
35- import { showErrorMessage , withProgress } from '../../common/window.apis' ;
35+ import { normalizePath } from '../../common/utils/pathUtils' ;
36+ import { showErrorMessage , showInformationMessage , withProgress } from '../../common/window.apis' ;
3637import { findParentIfFile } from '../../features/envCommands' ;
3738import { NativePythonFinder } from '../common/nativePythonFinder' ;
3839import { getLatest , shortVersion , sortEnvironments } from '../common/utils' ;
@@ -403,6 +404,16 @@ export class VenvManager implements EnvironmentManager {
403404 return ;
404405 }
405406
407+ // Notify user if VIRTUAL_ENV is set and they're trying to select a different environment
408+ if ( process . env . VIRTUAL_ENV && environment ) {
409+ const virtualEnvPath = process . env . VIRTUAL_ENV ;
410+ const selectedPath = environment . sysPrefix ;
411+ // Only show notification if they selected a different environment
412+ if ( virtualEnvPath !== selectedPath ) {
413+ showInformationMessage ( VenvManagerStrings . venvVirtualEnvActive ) ;
414+ }
415+ }
416+
406417 const before = this . fsPathToEnv . get ( pw . uri . fsPath ) ;
407418 if ( environment ) {
408419 this . fsPathToEnv . set ( pw . uri . fsPath , environment ) ;
@@ -561,7 +572,7 @@ export class VenvManager implements EnvironmentManager {
561572 this . fsPathToEnv . clear ( ) ;
562573
563574 const sorted = sortEnvironments ( this . collection ) ;
564- const projectPaths = this . api . getPythonProjects ( ) . map ( ( p ) => path . normalize ( p . uri . fsPath ) ) ;
575+ const projectPaths = this . api . getPythonProjects ( ) . map ( ( p ) => normalizePath ( p . uri . fsPath ) ) ;
565576 const events : ( ( ) => void ) [ ] = [ ] ;
566577 // Iterates through all workspace projects
567578 for ( const p of projectPaths ) {
@@ -600,7 +611,7 @@ export class VenvManager implements EnvironmentManager {
600611 // Search through all known environments (e) and check if any are associated with the current project path. If so, add that environment and path in the map.
601612 const found = sorted . find ( ( e ) => {
602613 const t = this . api . getPythonProject ( e . environmentPath ) ?. uri . fsPath ;
603- return t && path . normalize ( t ) === p ;
614+ return t && normalizePath ( t ) === p ;
604615 } ) ;
605616 if ( found ) {
606617 this . fsPathToEnv . set ( p , found ) ;
@@ -615,11 +626,15 @@ export class VenvManager implements EnvironmentManager {
615626 * Finds a PythonEnvironment in the given collection (or all environments) that matches the provided file system path. O(e) where e = environments.len
616627 */
617628 private findEnvironmentByPath ( fsPath : string , collection ?: PythonEnvironment [ ] ) : PythonEnvironment | undefined {
618- const normalized = path . normalize ( fsPath ) ;
629+ const normalized = normalizePath ( fsPath ) ;
619630 const envs = collection ?? this . collection ;
620631 return envs . find ( ( e ) => {
621- const n = path . normalize ( e . environmentPath . fsPath ) ;
622- return n === normalized || path . dirname ( n ) === normalized || path . dirname ( path . dirname ( n ) ) === normalized ;
632+ const n = normalizePath ( e . environmentPath . fsPath ) ;
633+ return (
634+ n === normalized ||
635+ normalizePath ( path . dirname ( e . environmentPath . fsPath ) ) === normalized ||
636+ normalizePath ( path . dirname ( path . dirname ( e . environmentPath . fsPath ) ) ) === normalized
637+ ) ;
623638 } ) ;
624639 }
625640
0 commit comments