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

Commit fffe938

Browse files
committed
accept window/progress for progress
1 parent 5afe3bb commit fffe938

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

src/extension.ts

+31-8
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ function makeRlsProcess(): Promise<child_process.ChildProcess> {
129129
});
130130

131131
return childProcessPromise.catch(() => {
132-
window.setStatusBarMessage('RLS could not be started');
132+
stopSpinner('RLS could not be started');
133133
return Promise.reject(undefined);
134134
});
135135
}
@@ -151,7 +151,7 @@ function startLanguageClient(context: ExtensionContext)
151151
}
152152
warnOnMissingCargoToml();
153153

154-
window.setStatusBarMessage('RLS: starting up');
154+
startSpinner('RLS starting');
155155

156156
warnOnRlsToml();
157157
// Check for deprecated env vars.
@@ -172,7 +172,7 @@ function startLanguageClient(context: ExtensionContext)
172172
// Create the language client and start the client.
173173
lc = new LanguageClient('Rust Language Server', serverOptions, clientOptions);
174174

175-
diagnosticCounter();
175+
progressCounter();
176176

177177
const disposable = lc.start();
178178
context.subscriptions.push(disposable);
@@ -207,17 +207,40 @@ async function autoUpdate() {
207207
}
208208
}
209209

210-
function diagnosticCounter() {
210+
function progressCounter() {
211+
const runningProgress: { [index: string]: boolean } = {};
212+
const asPercent = (fraction: number): string => `${Math.round(fraction * 100)}%`;
211213
let runningDiagnostics = 0;
212214
lc.onReady().then(() => {
213-
lc.onNotification(new NotificationType('rustDocument/beginBuild'), function(_f: any) {
215+
216+
stopSpinner('RLS');
217+
218+
lc.onNotification(new NotificationType('window/progress'), function (progress: any) {
219+
if (progress.done) {
220+
delete runningProgress[progress.id];
221+
} else {
222+
runningProgress[progress.id] = true;
223+
}
224+
if (Object.keys(runningProgress).length) {
225+
const msg =
226+
typeof progress.percentage === 'number' ? asPercent(progress.percentage) :
227+
progress.message ? progress.message : '';
228+
startSpinner(`RLS ${msg}`);
229+
} else {
230+
stopSpinner('RLS');
231+
}
232+
});
233+
234+
// FIXME these are legacy notifications used by RLS ca jan 2018.
235+
// remove once we're certain we've progress on.
236+
lc.onNotification(new NotificationType('rustDocument/beginBuild'), function (_f: any) {
214237
runningDiagnostics++;
215-
startSpinner('RLS: working');
238+
startSpinner('RLS', 'working');
216239
});
217-
lc.onNotification(new NotificationType('rustDocument/diagnosticsEnd'), function(_f: any) {
240+
lc.onNotification(new NotificationType('rustDocument/diagnosticsEnd'), function (_f: any) {
218241
runningDiagnostics--;
219242
if (runningDiagnostics <= 0) {
220-
stopSpinner('RLS: done');
243+
stopSpinner('RLS');
221244
}
222245
});
223246
});

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)