Skip to content

Commit

Permalink
Allow to disable LSP or Kernel completions independently.
Browse files Browse the repository at this point in the history
Some use love LSP for many of its features, but prefer to keep
completions via the kernel.

This adds two boolean flags in the configuration to not send completions
request to LSP and not send completions requests to the kernel.

See jupyter-lsp#440
  • Loading branch information
Carreau committed Apr 27, 2021
1 parent f9462ee commit 49dbdaa
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
12 changes: 12 additions & 0 deletions packages/jupyterlab-lsp/schema/completion.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@
"type": "number",
"description": "The time to wait for the kernel completions suggestions in milliseconds. Set to 0 to disable kernel completions, or to -1 to wait indefinitely (not recommended)."
},
"useKernelCompletions": {
"title": "Request Kernel Completion",
"type": "boolean",
"default": true,
"description": "Whether to send completions request to the kernel."
},
"useLspCompletions": {
"title": "Request LSP Completion",
"type": "boolean",
"default": true,
"description": "Whether to send completions request to the lsp server."
},
"waitForBusyKernel": {
"title": "Wait for kernel if busy",
"default": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ export class LSPConnector
return this.options.settings.composite.kernelCompletionsFirst;
}

protected get use_lsp_completions(): boolean {
return this.options.settings.composite.useLspCompletions;
}

protected get use_kernel_completions(): boolean {
return this.options.settings.composite.useKernelCompletions;
}

protected get suppress_continuous_hinting_in(): string[] {
return this.options.settings.composite.suppressContinuousHintingIn;
}
Expand Down Expand Up @@ -213,15 +221,19 @@ export class LSPConnector
cursor_in_root
);

const lsp_promise = this.fetch_lsp(
token,
typed_character,
virtual_start,
virtual_end,
virtual_cursor,
document,
position_in_token
);
const lsp_promise: Promise<CompletionHandler.ICompletionItemsReply> = this
.use_lsp_completions
? this.fetch_lsp(
token,
typed_character,
virtual_start,
virtual_end,
virtual_cursor,
document,
position_in_token
)
: Promise.resolve(null);

let promise: Promise<CompletionHandler.ICompletionItemsReply> = null;

try {
Expand Down Expand Up @@ -271,12 +283,16 @@ export class LSPConnector
promise = Promise.all([
kernel_promise.catch(p => p),
lsp_promise.catch(p => p)
]).then(([kernel, lsp]) =>
this.merge_replies(
[this.transform_reply(kernel), lsp],
this._editor
)
);
]).then(([kernel, lsp]) => {
let replies = [];
if (this.use_kernel_completions) {
replies.push(this.transform_reply(kernel));
}
if (this.use_lsp_completions) {
replies.push(lsp);
}
return this.merge_replies(replies, this._editor);
});
}
}
if (!promise) {
Expand Down

0 comments on commit 49dbdaa

Please sign in to comment.