99 ProgressLocation ,
1010 ProgressOptions ,
1111 Uri ,
12+ WorkspaceFolder ,
1213} from 'vscode' ;
1314import '../common/extensions' ;
1415import { IApplicationShell , IDocumentManager , IWorkspaceService } from '../common/application/types' ;
@@ -96,7 +97,13 @@ export class InterpreterService implements Disposable, IInterpreterService {
9697 public async refresh ( resource ?: Uri ) : Promise < void > {
9798 const interpreterDisplay = this . serviceContainer . get < IInterpreterDisplay > ( IInterpreterDisplay ) ;
9899 await interpreterDisplay . refresh ( resource ) ;
99- this . ensureEnvironmentContainsPython ( this . configService . getSettings ( resource ) . pythonPath ) . ignoreErrors ( ) ;
100+ const workspaceFolder = this . serviceContainer
101+ . get < IWorkspaceService > ( IWorkspaceService )
102+ . getWorkspaceFolder ( resource ) ;
103+ this . ensureEnvironmentContainsPython (
104+ this . configService . getSettings ( resource ) . pythonPath ,
105+ workspaceFolder ,
106+ ) . ignoreErrors ( ) ;
100107 }
101108
102109 public initialize ( ) : void {
@@ -227,18 +234,21 @@ export class InterpreterService implements Disposable, IInterpreterService {
227234 if ( this . _pythonPathSetting === '' || this . _pythonPathSetting !== pySettings . pythonPath ) {
228235 this . _pythonPathSetting = pySettings . pythonPath ;
229236 this . didChangeInterpreterEmitter . fire ( resource ) ;
237+ const workspaceFolder = this . serviceContainer
238+ . get < IWorkspaceService > ( IWorkspaceService )
239+ . getWorkspaceFolder ( resource ) ;
230240 reportActiveInterpreterChanged ( {
231241 path : pySettings . pythonPath ,
232- resource : this . serviceContainer . get < IWorkspaceService > ( IWorkspaceService ) . getWorkspaceFolder ( resource ) ,
242+ resource : workspaceFolder ,
233243 } ) ;
234244 const interpreterDisplay = this . serviceContainer . get < IInterpreterDisplay > ( IInterpreterDisplay ) ;
235245 interpreterDisplay . refresh ( ) . catch ( ( ex ) => traceError ( 'Python Extension: display.refresh' , ex ) ) ;
236- await this . ensureEnvironmentContainsPython ( this . _pythonPathSetting ) ;
246+ await this . ensureEnvironmentContainsPython ( this . _pythonPathSetting , workspaceFolder ) ;
237247 }
238248 }
239249
240250 @cache ( - 1 , true )
241- private async ensureEnvironmentContainsPython ( pythonPath : string ) {
251+ private async ensureEnvironmentContainsPython ( pythonPath : string , workspaceFolder : WorkspaceFolder | undefined ) {
242252 const installer = this . serviceContainer . get < IInstaller > ( IInstaller ) ;
243253 if ( ! ( await installer . isInstalled ( Product . python ) ) ) {
244254 // If Python is not installed into the environment, install it.
@@ -251,7 +261,17 @@ export class InterpreterService implements Disposable, IInterpreterService {
251261 traceLog ( 'Conda envs without Python are known to not work well; fixing conda environment...' ) ;
252262 const promise = installer . install ( Product . python , await this . getInterpreterDetails ( pythonPath ) ) ;
253263 shell . withProgress ( progressOptions , ( ) => promise ) ;
254- promise . then ( ( ) => this . triggerRefresh ( ) . ignoreErrors ( ) ) ;
264+ promise
265+ . then ( async ( ) => {
266+ // Fetch interpreter details so the cache is updated to include the newly installed Python.
267+ await this . getInterpreterDetails ( pythonPath ) ;
268+ this . didChangeInterpreterEmitter . fire ( workspaceFolder ?. uri ) ;
269+ reportActiveInterpreterChanged ( {
270+ path : pythonPath ,
271+ resource : workspaceFolder ,
272+ } ) ;
273+ } )
274+ . ignoreErrors ( ) ;
255275 }
256276 }
257277}
0 commit comments