@@ -47,6 +47,7 @@ import { runAsTask } from './execution/runAsTask';
4747import { runInTerminal } from './terminal/runInTerminal' ;
4848import { runInBackground } from './execution/runInBackground' ;
4949import { EnvVarManager } from './execution/envVariableManager' ;
50+ import { checkUri } from '../common/utils/pathUtils' ;
5051
5152class PythonEnvironmentApiImpl implements PythonEnvironmentApi {
5253 private readonly _onDidChangeEnvironments = new EventEmitter < DidChangeEnvironmentsEventArgs > ( ) ;
@@ -167,36 +168,39 @@ class PythonEnvironmentApiImpl implements PythonEnvironmentApi {
167168 return manager . remove ( environment ) ;
168169 }
169170 async refreshEnvironments ( scope : RefreshEnvironmentsScope ) : Promise < void > {
170- if ( scope === undefined ) {
171- await Promise . all ( this . envManagers . managers . map ( ( manager ) => manager . refresh ( scope ) ) ) ;
171+ const currentScope = checkUri ( scope ) as RefreshEnvironmentsScope ;
172+
173+ if ( currentScope === undefined ) {
174+ await Promise . all ( this . envManagers . managers . map ( ( manager ) => manager . refresh ( currentScope ) ) ) ;
172175 return Promise . resolve ( ) ;
173176 }
174- const manager = this . envManagers . getEnvironmentManager ( scope ) ;
177+ const manager = this . envManagers . getEnvironmentManager ( currentScope ) ;
175178 if ( ! manager ) {
176- return Promise . reject ( new Error ( `No environment manager found for: ${ scope . fsPath } ` ) ) ;
179+ return Promise . reject ( new Error ( `No environment manager found for: ${ currentScope . fsPath } ` ) ) ;
177180 }
178- return manager . refresh ( scope ) ;
181+ return manager . refresh ( currentScope ) ;
179182 }
180183 async getEnvironments ( scope : GetEnvironmentsScope ) : Promise < PythonEnvironment [ ] > {
181- if ( scope === 'all' || scope === 'global' ) {
182- const promises = this . envManagers . managers . map ( ( manager ) => manager . getEnvironments ( scope ) ) ;
184+ const currentScope = checkUri ( scope ) as GetEnvironmentsScope ;
185+ if ( currentScope === 'all' || currentScope === 'global' ) {
186+ const promises = this . envManagers . managers . map ( ( manager ) => manager . getEnvironments ( currentScope ) ) ;
183187 const items = await Promise . all ( promises ) ;
184188 return items . flat ( ) ;
185189 }
186- const manager = this . envManagers . getEnvironmentManager ( scope ) ;
190+ const manager = this . envManagers . getEnvironmentManager ( currentScope ) ;
187191 if ( ! manager ) {
188192 return [ ] ;
189193 }
190194
191- const items = await manager . getEnvironments ( scope ) ;
195+ const items = await manager . getEnvironments ( currentScope ) ;
192196 return items ;
193197 }
194198 onDidChangeEnvironments : Event < DidChangeEnvironmentsEventArgs > = this . _onDidChangeEnvironments . event ;
195199 setEnvironment ( scope : SetEnvironmentScope , environment ?: PythonEnvironment ) : Promise < void > {
196- return this . envManagers . setEnvironment ( scope , environment ) ;
200+ return this . envManagers . setEnvironment ( checkUri ( scope ) as SetEnvironmentScope , environment ) ;
197201 }
198202 async getEnvironment ( scope : GetEnvironmentScope ) : Promise < PythonEnvironment | undefined > {
199- return this . envManagers . getEnvironment ( scope ) ;
203+ return this . envManagers . getEnvironment ( checkUri ( scope ) as GetEnvironmentScope ) ;
200204 }
201205 onDidChangeEnvironment : Event < DidChangeEnvironmentEventArgs > = this . _onDidChangeEnvironment . event ;
202206 async resolveEnvironment ( context : ResolveEnvironmentContext ) : Promise < PythonEnvironment | undefined > {
@@ -267,7 +271,7 @@ class PythonEnvironmentApiImpl implements PythonEnvironmentApi {
267271 }
268272 onDidChangePythonProjects : Event < DidChangePythonProjectsEventArgs > = this . _onDidChangePythonProjects . event ;
269273 getPythonProject ( uri : Uri ) : PythonProject | undefined {
270- return this . projectManager . get ( uri ) ;
274+ return this . projectManager . get ( checkUri ( uri ) as Uri ) ;
271275 }
272276 registerPythonProjectCreator ( creator : PythonProjectCreator ) : Disposable {
273277 return this . projectCreators . registerPythonProjectCreator ( creator ) ;
@@ -310,7 +314,7 @@ class PythonEnvironmentApiImpl implements PythonEnvironmentApi {
310314 overrides ?: ( { [ key : string ] : string | undefined } | Uri ) [ ] ,
311315 baseEnvVar ?: { [ key : string ] : string | undefined } ,
312316 ) : Promise < { [ key : string ] : string | undefined } > {
313- return this . envVarManager . getEnvironmentVariables ( uri , overrides , baseEnvVar ) ;
317+ return this . envVarManager . getEnvironmentVariables ( checkUri ( uri ) as Uri , overrides , baseEnvVar ) ;
314318 }
315319}
316320
0 commit comments