Skip to content

Commit e85d73f

Browse files
authored
Merge pull request #586 from Carreau/select-completer
Allow to disable LSP or Kernel completions independently.
2 parents f9462ee + 2117c36 commit e85d73f

File tree

4 files changed

+52
-15
lines changed

4 files changed

+52
-15
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Changelog
22

3+
### (unreleased)
4+
5+
- Add ability to deactivate Kernel completions or LSP completion through the settings.
6+
37
### `jupyter-lsp 1.2.0` (2021-04-26)
48

59
- features:

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ from the Language Server (in notebook).
6666
If the kernel is too slow to respond promptly only the Language Server suggestions will be shown (default threshold: 0.6s).
6767
You can configure the completer to not attempt to fetch the kernel completions if the kernel is busy (skipping the 0.6s timeout).
6868

69+
You can deactivate the kernel suggestions by adding `"Kernel"` to the `disableCompletionsFrom` in the `completion` section
70+
of _Advanced Settings_. Alternatively if you _only_ want kernel completions you can add `"LSP"` to the same
71+
setting; Or add both if you like to code in hardcore mode and get no completions, or if another provider has been added.
72+
6973
### Rename
7074

7175
Rename variables, functions and more, in both: notebooks and the file editor.

packages/jupyterlab-lsp/schema/completion.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
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+
"disableCompletionsFrom": {
45+
"description": "The sources from which to exclude completion from. Possible values include 'Kernel', 'LSP'.",
46+
"type": "array",
47+
"default": [],
48+
"uniqueItems": true
49+
},
4450
"waitForBusyKernel": {
4551
"title": "Wait for kernel if busy",
4652
"default": true,

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

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

81+
protected get use_lsp_completions(): boolean {
82+
return (
83+
this.options.settings.composite.disableCompletionsFrom.indexOf('LSP') ==
84+
-1
85+
);
86+
}
87+
88+
protected get use_kernel_completions(): boolean {
89+
return (
90+
this.options.settings.composite.disableCompletionsFrom.indexOf(
91+
'Kernel'
92+
) == -1
93+
);
94+
}
95+
8196
protected get suppress_continuous_hinting_in(): string[] {
8297
return this.options.settings.composite.suppressContinuousHintingIn;
8398
}
@@ -212,22 +227,26 @@ export class LSPConnector
212227
let virtual_cursor = virtual_editor.root_position_to_virtual_position(
213228
cursor_in_root
214229
);
230+
const lsp_promise: Promise<CompletionHandler.ICompletionItemsReply> = this
231+
.use_lsp_completions
232+
? this.fetch_lsp(
233+
token,
234+
typed_character,
235+
virtual_start,
236+
virtual_end,
237+
virtual_cursor,
238+
document,
239+
position_in_token
240+
)
241+
: Promise.resolve(null);
215242

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-
);
225243
let promise: Promise<CompletionHandler.ICompletionItemsReply> = null;
226244

227245
try {
228246
const kernelTimeout = this._kernel_timeout;
229247

230248
if (
249+
this.use_kernel_completions &&
231250
this._kernel_connector &&
232251
this._has_kernel &&
233252
(this._is_kernel_idle || this._should_wait_for_busy_kernel) &&
@@ -271,12 +290,16 @@ export class LSPConnector
271290
promise = Promise.all([
272291
kernel_promise.catch(p => p),
273292
lsp_promise.catch(p => p)
274-
]).then(([kernel, lsp]) =>
275-
this.merge_replies(
276-
[this.transform_reply(kernel), lsp],
277-
this._editor
278-
)
279-
);
293+
]).then(([kernel, lsp]) => {
294+
let replies = [];
295+
if (kernel != null) {
296+
replies.push(this.transform_reply(kernel));
297+
}
298+
if (lsp != null) {
299+
replies.push(lsp);
300+
}
301+
return this.merge_replies(replies, this._editor);
302+
});
280303
}
281304
}
282305
if (!promise) {

0 commit comments

Comments
 (0)