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

Commit

Permalink
Merge pull request #40 from Xanewok/consistent-timer
Browse files Browse the repository at this point in the history
Make spinner consistent despite multiple running diagnostics
  • Loading branch information
Jonathan Turner committed Mar 26, 2017
2 parents 0522358 + ac23fcb commit 40044e9
Showing 1 changed file with 14 additions and 25 deletions.
39 changes: 14 additions & 25 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { LanguageClient, LanguageClientOptions, SettingMonitor, ServerOptions, T

let DEV_MODE = false;

let spinnerTimers = [];
let spinnerTimer = null;
let spinner = ['|', '/', '-', '\\'];
let nextBuildTask = 0;

class Counter {
Expand Down Expand Up @@ -79,33 +80,21 @@ export function activate(context: ExtensionContext) {
let runningDiagnostics = new Counter();
lc.onNotification({method: "rustDocument/diagnosticsBegin"}, function(f) {
runningDiagnostics.increment();
let state = 0;
spinnerTimers.push(setInterval(function() {
if (state == 0) {
window.setStatusBarMessage("RLS analysis: working |");
state = 1;
}
else if (state == 1) {
window.setStatusBarMessage("RLS analysis: working /");
state = 2;
}
else if (state == 2) {
window.setStatusBarMessage("RLS analysis: working -");
state = 3;
}
else if (state == 3) {
window.setStatusBarMessage("RLS analysis: working \\");
state = 0;
}
}, 100));

if (spinnerTimer == null) {
let state = 0;
spinnerTimer = setInterval(function() {
window.setStatusBarMessage("RLS analysis: working " + spinner[state]);
state = (state + 1) % spinner.length;
}, 100);
}
})
lc.onNotification({method: "rustDocument/diagnosticsEnd"}, function(f) {
while (spinnerTimers.length > 0) {
let spinnerTimer = spinnerTimers.pop();
clearInterval(spinnerTimer);
}
let count = runningDiagnostics.decrementAndGet()
let count = runningDiagnostics.decrementAndGet();
if (count == 0) {
clearInterval(spinnerTimer);
spinnerTimer = null;

window.setStatusBarMessage("RLS analysis: done");
}
})
Expand Down

0 comments on commit 40044e9

Please sign in to comment.