Skip to content

Commit 4677917

Browse files
committed
Implement allSettled replacement to show _something_ when one of
the completion sources fails
1 parent 6284337 commit 4677917

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
- delayed completion suggestions will no longer show up if cursor moved to another line ([#496])
1313
- changes in notebooks after kernel restart or file rename will now be recorded by the language server again ([#496])
14+
- when either of kernel providers: kernel or LSP server fails, the completion from the other will still be shown ([#496])
1415

1516
[#496]: https://github.com/krassowski/jupyterlab-lsp/pull/496
1617

packages/jupyterlab-lsp/src/features/completion/completion_handler.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,9 @@ export class LSPConnector
374374
]);
375375
}
376376

377-
// TODO: use allSettled if available; requires ES2020 or a polyfill
378-
// allSettled ensures that the result is not lost if one of the promises rejects
379377
promise = Promise.all([
380-
kernel_promise,
381-
lsp_promise
378+
kernel_promise.catch(p => p),
379+
lsp_promise.catch(p => p)
382380
]).then(([kernel, lsp]) =>
383381
this.merge_replies(this.transform_reply(kernel), lsp, this._editor)
384382
);
@@ -544,10 +542,17 @@ export class LSPConnector
544542
): CompletionHandler.ICompletionItemsReply {
545543
this.console.debug('Merging completions:', lsp, kernel);
546544

547-
if (!kernel.items.length) {
545+
if (kernel instanceof Error) {
546+
this.console.warn('Caught kernel completions error', kernel);
547+
}
548+
if (lsp instanceof Error) {
549+
this.console.warn('Caught LSP completions error', lsp);
550+
}
551+
552+
if (kernel instanceof Error || !kernel.items.length) {
548553
return lsp;
549554
}
550-
if (!lsp.items.length) {
555+
if (lsp instanceof Error || !lsp.items.length) {
551556
return kernel;
552557
}
553558

0 commit comments

Comments
 (0)