Skip to content
This repository was archived by the owner on Nov 18, 2022. It is now read-only.

Commit 9160fa4

Browse files
committed
accept window/progress instead of beginBuild/diagnosticEnd
1 parent 0f3994f commit 9160fa4

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

src/extension.ts

+22-13
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function makeRlsProcess(): Promise<child_process.ChildProcess> {
127127
});
128128

129129
return childProcessPromise.catch(() => {
130-
window.setStatusBarMessage('RLS could not be started');
130+
stopSpinner('RLS could not be started');
131131
return Promise.reject(undefined);
132132
});
133133
}
@@ -149,7 +149,7 @@ function startLanguageClient(context: ExtensionContext)
149149
}
150150
warnOnMissingCargoToml();
151151

152-
window.setStatusBarMessage('RLS: starting up');
152+
startSpinner('RLS starting');
153153

154154
warnOnRlsToml();
155155
// Check for deprecated env vars.
@@ -170,7 +170,7 @@ function startLanguageClient(context: ExtensionContext)
170170
// Create the language client and start the client.
171171
lc = new LanguageClient('Rust Language Server', serverOptions, clientOptions);
172172

173-
diagnosticCounter();
173+
progressCounter();
174174

175175
const disposable = lc.start();
176176
context.subscriptions.push(disposable);
@@ -205,17 +205,26 @@ async function autoUpdate() {
205205
}
206206
}
207207

208-
function diagnosticCounter() {
209-
let runningDiagnostics = 0;
208+
function progressCounter() {
209+
const runningProgress: { [index: string]: boolean } = {};
210+
const asPercent = (fraction: number): string => `${Math.round(fraction * 100)}%`;
210211
lc.onReady().then(() => {
211-
lc.onNotification(new NotificationType('rustDocument/beginBuild'), function(_f: any) {
212-
runningDiagnostics++;
213-
startSpinner('RLS: working');
214-
});
215-
lc.onNotification(new NotificationType('rustDocument/diagnosticsEnd'), function(_f: any) {
216-
runningDiagnostics--;
217-
if (runningDiagnostics <= 0) {
218-
stopSpinner('RLS: done');
212+
213+
stopSpinner('RLS');
214+
215+
lc.onNotification(new NotificationType('window/progress'), function (progress: any) {
216+
if (progress.done) {
217+
delete runningProgress[progress.id];
218+
} else {
219+
runningProgress[progress.id] = true;
220+
}
221+
if (Object.keys(runningProgress).length) {
222+
const msg =
223+
typeof progress.percentage === 'number' ? asPercent(progress.percentage) :
224+
progress.message ? progress.message : '';
225+
startSpinner(`RLS ${msg}`);
226+
} else {
227+
stopSpinner('RLS');
219228
}
220229
});
221230
});

src/spinner.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
import { window } from 'vscode';
1414

1515
export function startSpinner(message: string) {
16-
if (spinnerTimer == null) {
17-
let state = 0;
18-
spinnerTimer = setInterval(function() {
19-
window.setStatusBarMessage(message + ' ' + spinner[state]);
20-
state = (state + 1) % spinner.length;
21-
}, 100);
16+
if (spinnerTimer != null) {
17+
clearInterval(spinnerTimer);
2218
}
19+
let state = 0;
20+
spinnerTimer = setInterval(function() {
21+
window.setStatusBarMessage(message + ' ' + spinner[state]);
22+
state = (state + 1) % spinner.length;
23+
}, 100);
2324
}
2425

2526
export function stopSpinner(message: string) {

0 commit comments

Comments
 (0)