@@ -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' ;
@@ -383,6 +384,16 @@ export class VenvManager implements EnvironmentManager {
383384 return ;
384385 }
385386
387+ // Notify user if VIRTUAL_ENV is set and they're trying to select a different environment
388+ if ( process . env . VIRTUAL_ENV && environment ) {
389+ const virtualEnvPath = process . env . VIRTUAL_ENV ;
390+ const selectedPath = environment . sysPrefix ;
391+ // Only show notification if they selected a different environment
392+ if ( virtualEnvPath !== selectedPath ) {
393+ showInformationMessage ( VenvManagerStrings . venvVirtualEnvActive ) ;
394+ }
395+ }
396+
386397 const before = this . fsPathToEnv . get ( pw . uri . fsPath ) ;
387398 if ( environment ) {
388399 this . fsPathToEnv . set ( pw . uri . fsPath , environment ) ;
@@ -541,7 +552,7 @@ export class VenvManager implements EnvironmentManager {
541552 this . fsPathToEnv . clear ( ) ;
542553
543554 const sorted = sortEnvironments ( this . collection ) ;
544- const projectPaths = this . api . getPythonProjects ( ) . map ( ( p ) => path . normalize ( p . uri . fsPath ) ) ;
555+ const projectPaths = this . api . getPythonProjects ( ) . map ( ( p ) => normalizePath ( p . uri . fsPath ) ) ;
545556 const events : ( ( ) => void ) [ ] = [ ] ;
546557 // Iterates through all workspace projects
547558 for ( const p of projectPaths ) {
@@ -580,7 +591,7 @@ export class VenvManager implements EnvironmentManager {
580591 // 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.
581592 const found = sorted . find ( ( e ) => {
582593 const t = this . api . getPythonProject ( e . environmentPath ) ?. uri . fsPath ;
583- return t && path . normalize ( t ) === p ;
594+ return t && normalizePath ( t ) === p ;
584595 } ) ;
585596 if ( found ) {
586597 this . fsPathToEnv . set ( p , found ) ;
@@ -595,11 +606,15 @@ export class VenvManager implements EnvironmentManager {
595606 * Finds a PythonEnvironment in the given collection (or all environments) that matches the provided file system path. O(e) where e = environments.len
596607 */
597608 private findEnvironmentByPath ( fsPath : string , collection ?: PythonEnvironment [ ] ) : PythonEnvironment | undefined {
598- const normalized = path . normalize ( fsPath ) ;
609+ const normalized = normalizePath ( fsPath ) ;
599610 const envs = collection ?? this . collection ;
600611 return envs . find ( ( e ) => {
601- const n = path . normalize ( e . environmentPath . fsPath ) ;
602- return n === normalized || path . dirname ( n ) === normalized || path . dirname ( path . dirname ( n ) ) === normalized ;
612+ const n = normalizePath ( e . environmentPath . fsPath ) ;
613+ return (
614+ n === normalized ||
615+ normalizePath ( path . dirname ( e . environmentPath . fsPath ) ) === normalized ||
616+ normalizePath ( path . dirname ( path . dirname ( e . environmentPath . fsPath ) ) ) === normalized
617+ ) ;
603618 } ) ;
604619 }
605620
0 commit comments