@@ -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 { convertNotebookCellUriToNotebookUri } from '../common/utils/pathUtils' ;
5051
5152class PythonEnvironmentApiImpl implements PythonEnvironmentApi {
5253 private readonly _onDidChangeEnvironments = new EventEmitter < DidChangeEnvironmentsEventArgs > ( ) ;
@@ -209,44 +210,24 @@ class PythonEnvironmentApiImpl implements PythonEnvironmentApi {
209210 }
210211 onDidChangeEnvironments : Event < DidChangeEnvironmentsEventArgs > = this . _onDidChangeEnvironments . event ;
211212 setEnvironment ( scope : SetEnvironmentScope , environment ?: PythonEnvironment ) : Promise < void > {
212- let currentScope : SetEnvironmentScope = scope ;
213+ let currentScope = scope ;
214+
213215 if ( scope instanceof Uri && scope . scheme === 'vscode-notebook-cell' ) {
214- currentScope = Uri . from ( {
215- scheme : 'vscode-notebook' ,
216- path : scope . path ,
217- authority : scope . authority ,
218- } ) ;
216+ currentScope = convertNotebookCellUriToNotebookUri ( scope ) ;
219217 }
220218
221219 if ( Array . isArray ( scope ) && scope . length > 0 ) {
222- // if scope is an array of Uri, go through each item and check if it is a notebook cell Uri
223- // if it is, convert it to notebook Uri and push all items to the currentScope
224- currentScope = [ ] ;
225- for ( const s of scope ) {
226- if ( s instanceof Uri && s . scheme === 'vscode-notebook-cell' ) {
227- currentScope . push (
228- Uri . from ( {
229- scheme : 'vscode-notebook' ,
230- path : s . path ,
231- authority : s . authority ,
232- } ) ,
233- ) ;
234- } else {
235- currentScope . push ( s ) ;
236- }
237- }
220+ currentScope = scope . map ( ( s ) =>
221+ s instanceof Uri && s . scheme === 'vscode-notebook-cell' ? convertNotebookCellUriToNotebookUri ( s ) : s ,
222+ ) ;
238223 }
239224
240225 return this . envManagers . setEnvironment ( currentScope , environment ) ;
241226 }
242227 async getEnvironment ( scope : GetEnvironmentScope ) : Promise < PythonEnvironment | undefined > {
243228 let currentScope : GetEnvironmentScope = scope ;
244229 if ( scope instanceof Uri && scope . scheme === 'vscode-notebook-cell' ) {
245- currentScope = Uri . from ( {
246- scheme : 'vscode-notebook' ,
247- path : scope . path ,
248- authority : scope . authority ,
249- } ) ;
230+ currentScope = convertNotebookCellUriToNotebookUri ( scope ) ;
250231 }
251232 return this . envManagers . getEnvironment ( currentScope ) ;
252233 }
@@ -321,11 +302,7 @@ class PythonEnvironmentApiImpl implements PythonEnvironmentApi {
321302 getPythonProject ( uri : Uri ) : PythonProject | undefined {
322303 let currentUri : GetEnvironmentScope = uri ;
323304 if ( uri . scheme === 'vscode-notebook-cell' ) {
324- currentUri = Uri . from ( {
325- scheme : 'vscode-notebook' ,
326- path : uri . path ,
327- authority : uri . authority ,
328- } ) ;
305+ currentUri = convertNotebookCellUriToNotebookUri ( uri ) ;
329306 }
330307 return this . projectManager . get ( currentUri ) ;
331308 }
@@ -372,11 +349,7 @@ class PythonEnvironmentApiImpl implements PythonEnvironmentApi {
372349 ) : Promise < { [ key : string ] : string | undefined } > {
373350 let currentUri : GetEnvironmentScope = uri ;
374351 if ( uri . scheme === 'vscode-notebook-cell' ) {
375- currentUri = Uri . from ( {
376- scheme : 'vscode-notebook' ,
377- path : uri . path ,
378- authority : uri . authority ,
379- } ) ;
352+ currentUri = convertNotebookCellUriToNotebookUri ( uri ) ;
380353 }
381354 return this . envVarManager . getEnvironmentVariables ( currentUri , overrides , baseEnvVar ) ;
382355 }
0 commit comments