forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogressDisplay.ts
More file actions
77 lines (67 loc) · 2.83 KB
/
Copy pathprogressDisplay.ts
File metadata and controls
77 lines (67 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { inject, injectable } from 'inversify';
import { Disposable, ProgressLocation, ProgressOptions } from 'vscode';
import { IExtensionSingleActivationService } from '../../activation/types';
import { IApplicationShell } from '../../common/application/types';
import { Commands } from '../../common/constants';
import { IDisposableRegistry } from '../../common/types';
import { createDeferred, Deferred } from '../../common/utils/async';
import { Interpreters } from '../../common/utils/localize';
import { traceDecoratorVerbose } from '../../logging';
import { ProgressReportStage } from '../../pythonEnvironments/base/locator';
import { IComponentAdapter } from '../contracts';
// The parts of IComponentAdapter used here.
@injectable()
export class InterpreterLocatorProgressStatubarHandler implements IExtensionSingleActivationService {
public readonly supportedWorkspaceTypes = { untrustedWorkspace: false, virtualWorkspace: true };
private deferred: Deferred<void> | undefined;
private isFirstTimeLoadingInterpreters = true;
constructor(
@inject(IApplicationShell) private readonly shell: IApplicationShell,
@inject(IDisposableRegistry) private readonly disposables: Disposable[],
@inject(IComponentAdapter) private readonly pyenvs: IComponentAdapter,
) {}
public async activate(): Promise<void> {
this.pyenvs.onProgress(
(event) => {
if (event.stage === ProgressReportStage.discoveryStarted) {
this.showProgress();
const refreshPromise = this.pyenvs.getRefreshPromise();
if (refreshPromise) {
refreshPromise.then(() => this.hideProgress());
}
}
},
this,
this.disposables,
);
}
@traceDecoratorVerbose('Display locator refreshing progress')
private showProgress(): void {
if (!this.deferred) {
this.createProgress();
}
}
@traceDecoratorVerbose('Hide locator refreshing progress')
private hideProgress(): void {
if (this.deferred) {
this.deferred.resolve();
this.deferred = undefined;
}
}
private createProgress() {
const progressOptions: ProgressOptions = {
location: ProgressLocation.Window,
title: `[${
this.isFirstTimeLoadingInterpreters ? Interpreters.discovering : Interpreters.refreshing
}](command:${Commands.Set_Interpreter})`,
};
this.isFirstTimeLoadingInterpreters = false;
this.shell.withProgress(progressOptions, () => {
this.deferred = createDeferred();
return this.deferred.promise;
});
}
}