forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogress.ts
More file actions
66 lines (56 loc) · 2.08 KB
/
progress.ts
File metadata and controls
66 lines (56 loc) · 2.08 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { Progress, ProgressLocation, window } from 'vscode';
import { Disposable, LanguageClient } from 'vscode-languageclient';
import { createDeferred, Deferred } from '../common/utils/async';
export class ProgressReporting implements Disposable {
private statusBarMessage: Disposable | undefined;
private progress: Progress<{ message?: string; increment?: number }> | undefined;
private progressDeferred: Deferred<void> | undefined;
constructor(private readonly languageClient: LanguageClient) {
this.languageClient.onNotification('python/setStatusBarMessage', (m: string) => {
if (this.statusBarMessage) {
this.statusBarMessage.dispose();
}
this.statusBarMessage = window.setStatusBarMessage(m);
});
this.languageClient.onNotification('python/beginProgress', _ => {
if (this.progressDeferred) {
return;
}
this.beginProgress();
});
this.languageClient.onNotification('python/reportProgress', (m: string) => {
if (!this.progress) {
this.beginProgress();
}
this.progress!.report({ message: m });
});
this.languageClient.onNotification('python/endProgress', _ => {
if (this.progressDeferred) {
this.progressDeferred.resolve();
this.progressDeferred = undefined;
this.progress = undefined;
}
});
}
public dispose() {
if (this.statusBarMessage) {
this.statusBarMessage.dispose();
}
}
private beginProgress(): void {
this.progressDeferred = createDeferred<void>();
window.withProgress(
{
location: ProgressLocation.Window,
title: ''
},
progress => {
this.progress = progress;
return this.progressDeferred!.promise;
}
);
}
}