@@ -23,7 +23,7 @@ import { createDeferred, Deferred } from '../common/utils/async';
2323import { Architecture , getUserHomeDir } from '../common/utils/platform' ;
2424import { parseVersion } from './base/info/pythonVersion' ;
2525import { cache } from '../common/utils/decorators' ;
26- import { traceError , traceLog , traceWarn } from '../logging' ;
26+ import { traceError , traceInfo , traceLog , traceWarn } from '../logging' ;
2727import { StopWatch } from '../common/utils/stopWatch' ;
2828import { FileChangeType } from '../common/platform/fileSystemWatcher' ;
2929import { categoryToKind , NativePythonEnvironmentKind } from './base/locators/common/nativePythonUtils' ;
@@ -157,6 +157,15 @@ function getEnvType(kind: PythonEnvKind): PythonEnvType | undefined {
157157 }
158158}
159159
160+ function isSubDir ( pathToCheck : string | undefined , parents : string [ ] ) : boolean {
161+ return parents . some ( ( prefix ) => {
162+ if ( pathToCheck ) {
163+ return path . normalize ( pathToCheck ) . startsWith ( path . normalize ( prefix ) ) ;
164+ }
165+ return false ;
166+ } ) ;
167+ }
168+
160169function getName ( nativeEnv : NativeEnvInfo , kind : PythonEnvKind , condaEnvDirs : string [ ] ) : string {
161170 if ( nativeEnv . name ) {
162171 return nativeEnv . name ;
@@ -168,14 +177,18 @@ function getName(nativeEnv: NativeEnvInfo, kind: PythonEnvKind, condaEnvDirs: st
168177 }
169178
170179 if ( nativeEnv . prefix && envType === PythonEnvType . Conda ) {
171- if (
172- condaEnvDirs . some ( ( dir ) => {
173- if ( nativeEnv . prefix ) {
174- return path . normalize ( nativeEnv . prefix ) . startsWith ( path . normalize ( dir ) ) ;
175- }
176- return false ;
177- } )
178- ) {
180+ if ( nativeEnv . name === 'base' ) {
181+ return 'base' ;
182+ }
183+
184+ const workspaces = ( getWorkspaceFolders ( ) ?? [ ] ) . map ( ( wf ) => wf . uri . fsPath ) ;
185+ if ( isSubDir ( nativeEnv . prefix , workspaces ) ) {
186+ traceInfo ( `Conda env is --prefix environment: ${ nativeEnv . prefix } ` ) ;
187+ return '' ;
188+ }
189+
190+ if ( condaEnvDirs . length > 0 && isSubDir ( nativeEnv . prefix , condaEnvDirs ) ) {
191+ traceInfo ( `Conda env is --named environment: ${ nativeEnv . prefix } ` ) ;
179192 return path . basename ( nativeEnv . prefix ) ;
180193 }
181194 }
0 commit comments