From 49dbdaaea7c55ed8091305f0c676070dc9e810d5 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Mon, 26 Apr 2021 15:51:46 -0700 Subject: [PATCH 1/6] 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 --- .../jupyterlab-lsp/schema/completion.json | 12 +++++ .../features/completion/completion_handler.ts | 46 +++++++++++++------ 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/packages/jupyterlab-lsp/schema/completion.json b/packages/jupyterlab-lsp/schema/completion.json index 93e9e0801..f614725a3 100644 --- a/packages/jupyterlab-lsp/schema/completion.json +++ b/packages/jupyterlab-lsp/schema/completion.json @@ -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, diff --git a/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts b/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts index 798388c24..29f22a122 100644 --- a/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts +++ b/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts @@ -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; } @@ -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 = 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 = null; try { @@ -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) { From fcb6b4d3ac40cd75337487692525e3806375e8d5 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Mon, 26 Apr 2021 17:31:28 -0700 Subject: [PATCH 2/6] document --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 48c1b36ec..628db15fc 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 setting the `useKernelCompletions` to `false` in the `completion` section +of advanced settings. Alternatively if you _only_ want kernel completions you can set `useLspCompletions` to `false`. +Or both if you like to code in hardcore mode and get no completions. + ### Rename Rename variables, functions and more, in both: notebooks and the file editor. From c7afdc49c88ee0925cb43458cbceaa6d56547a1c Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Mon, 26 Apr 2021 17:33:03 -0700 Subject: [PATCH 3/6] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) 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: From 2dc40896b699fa50cadab45fcf33d1fb392bb0f6 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Tue, 27 Apr 2021 08:58:48 -0700 Subject: [PATCH 4/6] Move to exclusion list for config. Take reviews into accounts --- README.md | 6 +++--- packages/jupyterlab-lsp/schema/completion.json | 16 +++++----------- .../features/completion/completion_handler.ts | 18 +++++++++++++----- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 628db15fc..8e02d6ec1 100644 --- a/README.md +++ b/README.md @@ -66,9 +66,9 @@ 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 setting the `useKernelCompletions` to `false` in the `completion` section -of advanced settings. Alternatively if you _only_ want kernel completions you can set `useLspCompletions` to `false`. -Or both if you like to code in hardcore mode and get no completions. +You can deactivate the kernel suggestions by adding `"kenel"` to the `disableCompletionsFrom` in the `completion` section +of _Advanced Settings_. Alternatively if you _only_ want kernel completions you can add `"languageServer"` 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 diff --git a/packages/jupyterlab-lsp/schema/completion.json b/packages/jupyterlab-lsp/schema/completion.json index f614725a3..808d35b63 100644 --- a/packages/jupyterlab-lsp/schema/completion.json +++ b/packages/jupyterlab-lsp/schema/completion.json @@ -41,17 +41,11 @@ "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." + "disableCompletionsFrom": { + "description": "The sources from which to exclude completion from. Possible values include 'kernel', 'languageServer'.", + "type": "array", + "default": [], + "uniqueItems": true }, "waitForBusyKernel": { "title": "Wait for kernel if busy", diff --git a/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts b/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts index 29f22a122..360af7d59 100644 --- a/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts +++ b/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts @@ -79,11 +79,19 @@ export class LSPConnector } protected get use_lsp_completions(): boolean { - return this.options.settings.composite.useLspCompletions; + return ( + this.options.settings.composite.disableCompletionsFrom.indexOf( + 'languageServer' + ) == -1 + ); } protected get use_kernel_completions(): boolean { - return this.options.settings.composite.useKernelCompletions; + return ( + this.options.settings.composite.disableCompletionsFrom.indexOf( + 'kernel' + ) == -1 + ); } protected get suppress_continuous_hinting_in(): string[] { @@ -220,7 +228,6 @@ 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( @@ -240,6 +247,7 @@ export class LSPConnector 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) && @@ -285,10 +293,10 @@ export class LSPConnector lsp_promise.catch(p => p) ]).then(([kernel, lsp]) => { let replies = []; - if (this.use_kernel_completions) { + if (kernel != null) { replies.push(this.transform_reply(kernel)); } - if (this.use_lsp_completions) { + if (lsp != null) { replies.push(lsp); } return this.merge_replies(replies, this._editor); From 26fb4639c77cfff769f0a72612d3bdb74230ffd2 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Tue, 27 Apr 2021 13:50:36 -0700 Subject: [PATCH 5/6] Rename options --- README.md | 4 ++-- packages/jupyterlab-lsp/schema/completion.json | 2 +- .../src/features/completion/completion_handler.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8e02d6ec1..2ebb0f05b 100644 --- a/README.md +++ b/README.md @@ -66,8 +66,8 @@ 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 `"kenel"` to the `disableCompletionsFrom` in the `completion` section -of _Advanced Settings_. Alternatively if you _only_ want kernel completions you can add `"languageServer"` to the same +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 diff --git a/packages/jupyterlab-lsp/schema/completion.json b/packages/jupyterlab-lsp/schema/completion.json index 808d35b63..5f057bd56 100644 --- a/packages/jupyterlab-lsp/schema/completion.json +++ b/packages/jupyterlab-lsp/schema/completion.json @@ -42,7 +42,7 @@ "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', 'languageServer'.", + "description": "The sources from which to exclude completion from. Possible values include 'Kernel', 'LSP'.", "type": "array", "default": [], "uniqueItems": true diff --git a/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts b/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts index 360af7d59..0323b0a28 100644 --- a/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts +++ b/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts @@ -81,7 +81,7 @@ export class LSPConnector protected get use_lsp_completions(): boolean { return ( this.options.settings.composite.disableCompletionsFrom.indexOf( - 'languageServer' + 'LSP' ) == -1 ); } @@ -89,7 +89,7 @@ export class LSPConnector protected get use_kernel_completions(): boolean { return ( this.options.settings.composite.disableCompletionsFrom.indexOf( - 'kernel' + 'Kernel' ) == -1 ); } From 2117c3615610d5374f28dfc119188fade3960f22 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Tue, 27 Apr 2021 19:15:07 -0700 Subject: [PATCH 6/6] prettier --- .../src/features/completion/completion_handler.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts b/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts index 0323b0a28..ec03d23cb 100644 --- a/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts +++ b/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts @@ -80,9 +80,8 @@ export class LSPConnector protected get use_lsp_completions(): boolean { return ( - this.options.settings.composite.disableCompletionsFrom.indexOf( - 'LSP' - ) == -1 + this.options.settings.composite.disableCompletionsFrom.indexOf('LSP') == + -1 ); }