Skip to content

Commit 7e21481

Browse files
author
Kartik Raj
committed
Add progress notification for activating terminals
1 parent 78e52ad commit 7e21481

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/client/common/utils/localize.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ export namespace Interpreters {
193193
export const condaInheritEnvMessage = l10n.t(
194194
'We noticed you\'re using a conda environment. If you are experiencing issues with this environment in the integrated terminal, we recommend that you let the Python extension change "terminal.integrated.inheritEnv" to false in your user settings. [Learn more](https://aka.ms/AA66i8f).',
195195
);
196+
export const activatingTerminals = l10n.t('Reactivating terminals...');
196197
export const activatedCondaEnvLaunch = l10n.t(
197198
'We noticed VS Code was launched from an activated conda environment, would you like to select it?',
198199
);

src/client/interpreter/activation/service.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import '../../common/extensions';
55

66
import { inject, injectable } from 'inversify';
77

8-
import { IWorkspaceService } from '../../common/application/types';
8+
import { IApplicationShell, IWorkspaceService } from '../../common/application/types';
99
import { PYTHON_WARNINGS } from '../../common/constants';
1010
import { IPlatformService } from '../../common/platform/types';
1111
import * as internalScripts from '../../common/process/internal/scripts';
1212
import { ExecutionResult, IProcessServiceFactory } from '../../common/process/types';
1313
import { ITerminalHelper, TerminalShellType } from '../../common/terminal/types';
1414
import { ICurrentProcess, IDisposable, IExtensionContext, Resource } from '../../common/types';
15-
import { sleep } from '../../common/utils/async';
15+
import { createDeferred, Deferred, sleep } from '../../common/utils/async';
1616
import { InMemoryCache } from '../../common/utils/cacheUtils';
1717
import { OSType } from '../../common/utils/platform';
1818
import { IEnvironmentVariablesProvider } from '../../common/variables/types';
@@ -32,6 +32,8 @@ import {
3232
} from '../../logging';
3333
import { Conda } from '../../pythonEnvironments/common/environmentManagers/conda';
3434
import { StopWatch } from '../../common/utils/stopWatch';
35+
import { Interpreters } from '../../common/utils/localize';
36+
import { ProgressLocation, ProgressOptions } from 'vscode';
3537

3638
const ENVIRONMENT_PREFIX = 'e8b39361-0157-4923-80e1-22d70d46dee6';
3739
const CACHE_DURATION = 10 * 60 * 1000;
@@ -102,6 +104,7 @@ export class EnvironmentActivationServiceCache {
102104
@injectable()
103105
export class EnvironmentActivationService implements IEnvironmentActivationService, IDisposable {
104106
private readonly disposables: IDisposable[] = [];
107+
private deferred: Deferred<void> | undefined;
105108
private previousEnvVars = process.env;
106109
private readonly activatedEnvVariablesCache = new EnvironmentActivationServiceCache();
107110
constructor(
@@ -113,6 +116,7 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
113116
@inject(IInterpreterService) private interpreterService: IInterpreterService,
114117
@inject(IEnvironmentVariablesProvider) private readonly envVarsService: IEnvironmentVariablesProvider,
115118
@inject(IExtensionContext) private context: IExtensionContext,
119+
@inject(IApplicationShell) private shell: IApplicationShell,
116120
) {
117121
this.envVarsService.onDidEnvironmentVariablesChange(
118122
() => this.activatedEnvVariablesCache.clear(),
@@ -122,8 +126,10 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
122126

123127
this.interpreterService.onDidChangeInterpreter(
124128
async (resource) => {
129+
this.showProgress();
125130
this.activatedEnvVariablesCache.clear();
126131
await this.initializeEnvironmentCollection(resource);
132+
this.hideProgress();
127133
},
128134
this,
129135
this.disposables,
@@ -353,4 +359,30 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
353359
}
354360
}
355361
}
362+
363+
@traceDecoratorVerbose('Display activating terminals')
364+
private showProgress(): void {
365+
if (!this.deferred) {
366+
this.createProgress();
367+
}
368+
}
369+
370+
@traceDecoratorVerbose('Hide activating terminals')
371+
private hideProgress(): void {
372+
if (this.deferred) {
373+
this.deferred.resolve();
374+
this.deferred = undefined;
375+
}
376+
}
377+
378+
private createProgress() {
379+
const progressOptions: ProgressOptions = {
380+
location: ProgressLocation.Window,
381+
title: Interpreters.activatingTerminals,
382+
};
383+
this.shell.withProgress(progressOptions, () => {
384+
this.deferred = createDeferred();
385+
return this.deferred.promise;
386+
});
387+
}
356388
}

0 commit comments

Comments
 (0)