diff --git a/CHANGELOG.md b/CHANGELOG.md index a08a3e43c..2f1af6cee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Changelog +### (unreleased) + +- Add ability to deactivate Kernel completions or LSP completion through the settings. + ### `jupyter-lsp 1.2.0` (2021-04-26) - features: diff --git a/README.md b/README.md index 48c1b36ec..2ebb0f05b 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,10 @@ from the Language Server (in notebook). If the kernel is too slow to respond promptly only the Language Server suggestions will be shown (default threshold: 0.6s). You can configure the completer to not attempt to fetch the kernel completions if the kernel is busy (skipping the 0.6s timeout). +You can deactivate the kernel suggestions by adding `"Kernel"` to the `disableCompletionsFrom` in the `completion` section +of _Advanced Settings_. Alternatively if you _only_ want kernel completions you can add `"LSP"` to the same +setting; Or add both if you like to code in hardcore mode and get no completions, or if another provider has been added. + ### Rename Rename variables, functions and more, in both: notebooks and the file editor. diff --git a/packages/jupyterlab-lsp/schema/completion.json b/packages/jupyterlab-lsp/schema/completion.json index 93e9e0801..5f057bd56 100644 --- a/packages/jupyterlab-lsp/schema/completion.json +++ b/packages/jupyterlab-lsp/schema/completion.json @@ -41,6 +41,12 @@ "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)." }, + "disableCompletionsFrom": { + "description": "The sources from which to exclude completion from. Possible values include 'Kernel', 'LSP'.", + "type": "array", + "default": [], + "uniqueItems": true + }, "waitForBusyKernel": { "title": "Wait for kernel if busy", "default": true, diff --git a/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts b/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts index 798388c24..ec03d23cb 100644 --- a/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts +++ b/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts @@ -78,6 +78,21 @@ export class LSPConnector return this.options.settings.composite.kernelCompletionsFirst; } + protected get use_lsp_completions(): boolean { + return ( + this.options.settings.composite.disableCompletionsFrom.indexOf('LSP') == + -1 + ); + } + + protected get use_kernel_completions(): boolean { + return ( + this.options.settings.composite.disableCompletionsFrom.indexOf( + 'Kernel' + ) == -1 + ); + } + protected get suppress_continuous_hinting_in(): string[] { return this.options.settings.composite.suppressContinuousHintingIn; } @@ -212,22 +227,26 @@ export class LSPConnector let virtual_cursor = virtual_editor.root_position_to_virtual_position( cursor_in_root ); + const lsp_promise: Promise = this + .use_lsp_completions + ? this.fetch_lsp( + token, + typed_character, + virtual_start, + virtual_end, + virtual_cursor, + document, + position_in_token + ) + : Promise.resolve(null); - const lsp_promise = this.fetch_lsp( - token, - typed_character, - virtual_start, - virtual_end, - virtual_cursor, - document, - position_in_token - ); let promise: Promise = null; try { const kernelTimeout = this._kernel_timeout; if ( + this.use_kernel_completions && this._kernel_connector && this._has_kernel && (this._is_kernel_idle || this._should_wait_for_busy_kernel) && @@ -271,12 +290,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 (kernel != null) { + replies.push(this.transform_reply(kernel)); + } + if (lsp != null) { + replies.push(lsp); + } + return this.merge_replies(replies, this._editor); + }); } } if (!promise) {