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

Commit 77f3227

Browse files
authored
Merge pull request #231 from algesten/progress-params
accept window/progress instead of beginBuild/diagnosticEnd
2 parents 5afe3bb + 36c541b commit 77f3227

File tree

3 files changed

+47
-18
lines changed

3 files changed

+47
-18
lines changed

src/extension.ts

+36-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,45 @@ async function autoUpdate() {
207207
}
208208
}
209209

210-
function diagnosticCounter() {
210+
function progressCounter() {
211+
const runningProgress: Set<string> = new Set();
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+
runningProgress.delete(progress.id);
221+
} else {
222+
runningProgress.add(progress.id);
223+
}
224+
if (runningProgress.size) {
225+
let status = '';
226+
if (typeof progress.percentage === 'number') {
227+
status = asPercent(progress.percentage);
228+
} else if (progress.message) {
229+
status = progress.message;
230+
} else if (progress.title) {
231+
status = `[${progress.title.toLowerCase()}]`;
232+
}
233+
startSpinner('RLS', status);
234+
} else {
235+
stopSpinner('RLS');
236+
}
237+
});
238+
239+
// FIXME these are legacy notifications used by RLS ca jan 2018.
240+
// remove once we're certain we've progress on.
241+
lc.onNotification(new NotificationType('rustDocument/beginBuild'), function (_f: any) {
214242
runningDiagnostics++;
215-
startSpinner('RLS: working');
243+
startSpinner('RLS', 'working');
216244
});
217-
lc.onNotification(new NotificationType('rustDocument/diagnosticsEnd'), function(_f: any) {
245+
lc.onNotification(new NotificationType('rustDocument/diagnosticsEnd'), function (_f: any) {
218246
runningDiagnostics--;
219247
if (runningDiagnostics <= 0) {
220-
stopSpinner('RLS: done');
248+
stopSpinner('RLS');
221249
}
222250
});
223251
});

src/rustup.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function runRlsViaRustup(env: any): Promise<child_process.ChildProcess> {
2525
}
2626

2727
export async function rustupUpdate() {
28-
startSpinner('Updating RLS...');
28+
startSpinner('RLS', 'Updating…');
2929

3030
try {
3131
const { stdout } = await execChildProcess(CONFIGURATION.rustupPath + ' update');
@@ -74,7 +74,7 @@ async function hasToolchain(): Promise<boolean> {
7474
}
7575

7676
async function tryToInstallToolchain(): Promise<void> {
77-
startSpinner('Installing toolchain...');
77+
startSpinner('RLS', 'Installing toolchain');
7878
try {
7979
const { stdout, stderr } = await execChildProcess(CONFIGURATION.rustupPath + ' toolchain install ' + CONFIGURATION.channel);
8080
console.log(stdout);
@@ -129,7 +129,7 @@ async function hasRlsComponents(): Promise<boolean> {
129129
}
130130

131131
async function installRls(): Promise<void> {
132-
startSpinner('Installing RLS components');
132+
startSpinner('RLS', 'Installing components');
133133

134134
const tryFn: (component: string) => Promise<(Error | null)> = async (component: string) => {
135135
try {

src/spinner.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212

1313
import { window } from 'vscode';
1414

15-
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);
15+
export function startSpinner(prefix: string, postfix: string) {
16+
if (spinnerTimer != null) {
17+
clearInterval(spinnerTimer);
2218
}
19+
let state = 0;
20+
spinnerTimer = setInterval(function() {
21+
window.setStatusBarMessage(prefix + ' ' + spinner[state] + ' ' + postfix);
22+
state = (state + 1) % spinner.length;
23+
}, 100);
2324
}
2425

2526
export function stopSpinner(message: string) {

0 commit comments

Comments
 (0)