-
Notifications
You must be signed in to change notification settings - Fork 163
accept window/progress instead of beginBuild/diagnosticEnd #231
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,7 +129,7 @@ function makeRlsProcess(): Promise<child_process.ChildProcess> { | |
}); | ||
|
||
return childProcessPromise.catch(() => { | ||
window.setStatusBarMessage('RLS could not be started'); | ||
stopSpinner('RLS could not be started'); | ||
return Promise.reject(undefined); | ||
}); | ||
} | ||
|
@@ -151,7 +151,7 @@ function startLanguageClient(context: ExtensionContext) | |
} | ||
warnOnMissingCargoToml(); | ||
|
||
window.setStatusBarMessage('RLS: starting up'); | ||
startSpinner('RLS', 'Starting'); | ||
|
||
warnOnRlsToml(); | ||
// Check for deprecated env vars. | ||
|
@@ -172,7 +172,7 @@ function startLanguageClient(context: ExtensionContext) | |
// Create the language client and start the client. | ||
lc = new LanguageClient('Rust Language Server', serverOptions, clientOptions); | ||
|
||
diagnosticCounter(); | ||
progressCounter(); | ||
|
||
const disposable = lc.start(); | ||
context.subscriptions.push(disposable); | ||
|
@@ -207,17 +207,45 @@ async function autoUpdate() { | |
} | ||
} | ||
|
||
function diagnosticCounter() { | ||
function progressCounter() { | ||
const runningProgress: { [index: string]: boolean } = {}; | ||
const asPercent = (fraction: number): string => `${Math.round(fraction * 100)}%`; | ||
let runningDiagnostics = 0; | ||
lc.onReady().then(() => { | ||
lc.onNotification(new NotificationType('rustDocument/beginBuild'), function(_f: any) { | ||
|
||
stopSpinner('RLS'); | ||
|
||
lc.onNotification(new NotificationType('window/progress'), function (progress: any) { | ||
if (progress.done) { | ||
delete runningProgress[progress.id]; | ||
} else { | ||
runningProgress[progress.id] = true; | ||
} | ||
if (Object.keys(runningProgress).length) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
let status = ''; | ||
if (typeof progress.percentage === 'number') { | ||
status = asPercent(progress.percentage); | ||
} else if (progress.message) { | ||
status = progress.message; | ||
} else if (progress.title) { | ||
status = `[${progress.title.toLowerCase()}]`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I know it's up to clients to display this on the UI side, but shouldn't we just display it how servers send it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ultimately I don't really want to end up in this part of the logic. This is a last resort fallback. We should try to send percentages or messages instead. It looked really bad to me with the caps, but this just taste and style, so I'm only going to argue my case once :) If you think it's an important point, I'll change it. |
||
} | ||
startSpinner('RLS', status); | ||
} else { | ||
stopSpinner('RLS'); | ||
} | ||
}); | ||
|
||
// FIXME these are legacy notifications used by RLS ca jan 2018. | ||
// remove once we're certain we've progress on. | ||
lc.onNotification(new NotificationType('rustDocument/beginBuild'), function (_f: any) { | ||
runningDiagnostics++; | ||
startSpinner('RLS: working'); | ||
startSpinner('RLS', 'working'); | ||
}); | ||
lc.onNotification(new NotificationType('rustDocument/diagnosticsEnd'), function(_f: any) { | ||
lc.onNotification(new NotificationType('rustDocument/diagnosticsEnd'), function (_f: any) { | ||
runningDiagnostics--; | ||
if (runningDiagnostics <= 0) { | ||
stopSpinner('RLS: done'); | ||
stopSpinner('RLS'); | ||
} | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really wonky with JS, but would it be possible to replace that with
Set
for clarity?Also not really sure why/how it's allowed to be
const
, since it's clearly modified in the callbacks, but I guess that's TypeScript shenanigans that I'm missing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.
Set
is better.const
is not typescript shenanigans but javascript. It's not actually immutable (sadly), it's just the actual variable itself that is impossible to change. I.e.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, makes sense. Thanks for the changes!