Skip to content

Commit 49dbdaa

Browse files
committed
Allow to disable LSP or Kernel completions independently.
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 #440
1 parent f9462ee commit 49dbdaa

File tree

2 files changed

+43
-15
lines changed

2 files changed

+43
-15
lines changed

packages/jupyterlab-lsp/schema/completion.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@
4141
"type": "number",
4242
"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)."
4343
},
44+
"useKernelCompletions": {
45+
"title": "Request Kernel Completion",
46+
"type": "boolean",
47+
"default": true,
48+
"description": "Whether to send completions request to the kernel."
49+
},
50+
"useLspCompletions": {
51+
"title": "Request LSP Completion",
52+
"type": "boolean",
53+
"default": true,
54+
"description": "Whether to send completions request to the lsp server."
55+
},
4456
"waitForBusyKernel": {
4557
"title": "Wait for kernel if busy",
4658
"default": true,

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

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ export class LSPConnector
7878
return this.options.settings.composite.kernelCompletionsFirst;
7979
}
8080

81+
protected get use_lsp_completions(): boolean {
82+
return this.options.settings.composite.useLspCompletions;
83+
}
84+
85+
protected get use_kernel_completions(): boolean {
86+
return this.options.settings.composite.useKernelCompletions;
87+
}
88+
8189
protected get suppress_continuous_hinting_in(): string[] {
8290
return this.options.settings.composite.suppressContinuousHintingIn;
8391
}
@@ -213,15 +221,19 @@ export class LSPConnector
213221
cursor_in_root
214222
);
215223

216-
const lsp_promise = this.fetch_lsp(
217-
token,
218-
typed_character,
219-
virtual_start,
220-
virtual_end,
221-
virtual_cursor,
222-
document,
223-
position_in_token
224-
);
224+
const lsp_promise: Promise<CompletionHandler.ICompletionItemsReply> = this
225+
.use_lsp_completions
226+
? this.fetch_lsp(
227+
token,
228+
typed_character,
229+
virtual_start,
230+
virtual_end,
231+
virtual_cursor,
232+
document,
233+
position_in_token
234+
)
235+
: Promise.resolve(null);
236+
225237
let promise: Promise<CompletionHandler.ICompletionItemsReply> = null;
226238

227239
try {
@@ -271,12 +283,16 @@ export class LSPConnector
271283
promise = Promise.all([
272284
kernel_promise.catch(p => p),
273285
lsp_promise.catch(p => p)
274-
]).then(([kernel, lsp]) =>
275-
this.merge_replies(
276-
[this.transform_reply(kernel), lsp],
277-
this._editor
278-
)
279-
);
286+
]).then(([kernel, lsp]) => {
287+
let replies = [];
288+
if (this.use_kernel_completions) {
289+
replies.push(this.transform_reply(kernel));
290+
}
291+
if (this.use_lsp_completions) {
292+
replies.push(lsp);
293+
}
294+
return this.merge_replies(replies, this._editor);
295+
});
280296
}
281297
}
282298
if (!promise) {

0 commit comments

Comments
 (0)