@@ -291,15 +291,15 @@ export class VenvManager implements EnvironmentManager {
291291 }
292292
293293 private updateCollection ( environment : PythonEnvironment ) : void {
294- this . collection = this . collection . filter (
295- ( e ) => e . environmentPath . fsPath !== environment . environmentPath . fsPath ,
296- ) ;
294+ const envPath = normalizePath ( environment . environmentPath . fsPath ) ;
295+ this . collection = this . collection . filter ( ( e ) => normalizePath ( e . environmentPath . fsPath ) !== envPath ) ;
297296 }
298297
299298 private updateFsPathToEnv ( environment : PythonEnvironment ) : Uri [ ] {
299+ const envPath = normalizePath ( environment . environmentPath . fsPath ) ;
300300 const changed : Uri [ ] = [ ] ;
301301 this . fsPathToEnv . forEach ( ( env , uri ) => {
302- if ( env . environmentPath . fsPath === environment . environmentPath . fsPath ) {
302+ if ( normalizePath ( env . environmentPath . fsPath ) === envPath ) {
303303 this . fsPathToEnv . delete ( uri ) ;
304304 changed . push ( Uri . file ( uri ) ) ;
305305 }
@@ -361,7 +361,7 @@ export class VenvManager implements EnvironmentManager {
361361 return [ ] ;
362362 }
363363
364- const env = this . fsPathToEnv . get ( scope . fsPath ) ;
364+ const env = this . fsPathToEnv . get ( normalizePath ( scope . fsPath ) ) ;
365365 return env ? [ env ] : [ ] ;
366366 }
367367
@@ -378,7 +378,7 @@ export class VenvManager implements EnvironmentManager {
378378 return this . globalEnv ;
379379 }
380380
381- let env = this . fsPathToEnv . get ( project . uri . fsPath ) ;
381+ let env = this . fsPathToEnv . get ( normalizePath ( project . uri . fsPath ) ) ;
382382 if ( ! env ) {
383383 env = this . findEnvironmentByPath ( project . uri . fsPath ) ;
384384 }
@@ -414,11 +414,12 @@ export class VenvManager implements EnvironmentManager {
414414 }
415415 }
416416
417- const before = this . fsPathToEnv . get ( pw . uri . fsPath ) ;
417+ const normalizedPwPath = normalizePath ( pw . uri . fsPath ) ;
418+ const before = this . fsPathToEnv . get ( normalizedPwPath ) ;
418419 if ( environment ) {
419- this . fsPathToEnv . set ( pw . uri . fsPath , environment ) ;
420+ this . fsPathToEnv . set ( normalizedPwPath , environment ) ;
420421 } else {
421- this . fsPathToEnv . delete ( pw . uri . fsPath ) ;
422+ this . fsPathToEnv . delete ( normalizedPwPath ) ;
422423 }
423424 await setVenvForWorkspace ( pw . uri . fsPath , environment ?. environmentPath . fsPath ) ;
424425
@@ -439,11 +440,12 @@ export class VenvManager implements EnvironmentManager {
439440
440441 const before : Map < string , PythonEnvironment | undefined > = new Map ( ) ;
441442 projects . forEach ( ( p ) => {
442- before . set ( p . uri . fsPath , this . fsPathToEnv . get ( p . uri . fsPath ) ) ;
443+ const normalizedPath = normalizePath ( p . uri . fsPath ) ;
444+ before . set ( p . uri . fsPath , this . fsPathToEnv . get ( normalizedPath ) ) ;
443445 if ( environment ) {
444- this . fsPathToEnv . set ( p . uri . fsPath , environment ) ;
446+ this . fsPathToEnv . set ( normalizedPath , environment ) ;
445447 } else {
446- this . fsPathToEnv . delete ( p . uri . fsPath ) ;
448+ this . fsPathToEnv . delete ( normalizedPath ) ;
447449 }
448450 } ) ;
449451
@@ -572,16 +574,17 @@ export class VenvManager implements EnvironmentManager {
572574 this . fsPathToEnv . clear ( ) ;
573575
574576 const sorted = sortEnvironments ( this . collection ) ;
575- const projectPaths = this . api . getPythonProjects ( ) . map ( ( p ) => normalizePath ( p . uri . fsPath ) ) ;
577+ const projects = this . api . getPythonProjects ( ) ;
576578 const events : ( ( ) => void ) [ ] = [ ] ;
577579 // Iterates through all workspace projects
578- for ( const p of projectPaths ) {
579- const env = await getVenvForWorkspace ( p ) ;
580+ for ( const project of projects ) {
581+ const originalPath = project . uri . fsPath ;
582+ const normalizedPath = normalizePath ( originalPath ) ;
583+ const env = await getVenvForWorkspace ( originalPath ) ;
580584 if ( env ) {
581585 // from env path find PythonEnvironment object in the collection.
582586 let foundEnv = this . findEnvironmentByPath ( env , sorted ) ?? this . findEnvironmentByPath ( env , globals ) ;
583- const previousEnv = this . fsPathToEnv . get ( p ) ;
584- const pw = this . api . getPythonProject ( Uri . file ( p ) ) ;
587+ const previousEnv = this . fsPathToEnv . get ( normalizedPath ) ;
585588 if ( ! foundEnv ) {
586589 // attempt to resolve
587590 const resolved = await resolveVenvPythonEnvironmentPath (
@@ -601,20 +604,20 @@ export class VenvManager implements EnvironmentManager {
601604 }
602605 }
603606 // Given found env, add it to the map and fire the event if needed.
604- this . fsPathToEnv . set ( p , foundEnv ) ;
605- if ( pw && previousEnv ?. envId . id !== foundEnv . envId . id ) {
607+ this . fsPathToEnv . set ( normalizedPath , foundEnv ) ;
608+ if ( previousEnv ?. envId . id !== foundEnv . envId . id ) {
606609 events . push ( ( ) =>
607- this . _onDidChangeEnvironment . fire ( { uri : pw . uri , old : undefined , new : foundEnv } ) ,
610+ this . _onDidChangeEnvironment . fire ( { uri : project . uri , old : undefined , new : foundEnv } ) ,
608611 ) ;
609612 }
610613 } else {
611614 // 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.
612615 const found = sorted . find ( ( e ) => {
613616 const t = this . api . getPythonProject ( e . environmentPath ) ?. uri . fsPath ;
614- return t && normalizePath ( t ) === p ;
617+ return t && normalizePath ( t ) === normalizedPath ;
615618 } ) ;
616619 if ( found ) {
617- this . fsPathToEnv . set ( p , found ) ;
620+ this . fsPathToEnv . set ( normalizedPath , found ) ;
618621 }
619622 }
620623 }
0 commit comments