From d27bcf9152af2fdec8fa971ebafb975cc5258bf7 Mon Sep 17 00:00:00 2001 From: krassowski Date: Sun, 10 Oct 2021 17:17:31 +0100 Subject: [PATCH 1/4] Fix kernel completions filtering for R --- CHANGELOG.md | 4 ++++ .../src/features/completion/completion_handler.ts | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0684eaf0..7aabfe0c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,8 +10,12 @@ lines will be collapsed into an expandable details section. - the signature box is now displayed above the current line - the signature box takes up less space +- bug fixes: + - fix missing translation strings ([#675]) + - fix kernel completions not showing up for R () [#671]: https://github.com/krassowski/jupyterlab-lsp/pull/671 +[#675]: https://github.com/krassowski/jupyterlab-lsp/pull/675 ### `@krassowski/jupyterlab-lsp 3.8.1` (2021-08-02) diff --git a/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts b/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts index ec03d23cb..58aaaa7f1 100644 --- a/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts +++ b/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts @@ -260,7 +260,9 @@ export class LSPConnector // TODO: should it be cashed? const kernelLanguage = await this._kernel_language(); - if (document.language === kernelLanguage) { + if ( + document.language.toLocaleLowerCase() === kernelLanguage.toLowerCase() + ) { let default_kernel_promise = this._kernel_connector.fetch(request); let kernel_promise: Promise; From db732994c211dda315d573d2676ece3745a7627b Mon Sep 17 00:00:00 2001 From: krassowski Date: Sun, 10 Oct 2021 17:40:40 +0100 Subject: [PATCH 2/4] Fix tab completions not showing up in strings due to incomplete trigger kind invalidation --- CHANGELOG.md | 1 + .../src/features/completion/completion_handler.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7aabfe0c4..a7d88d28a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - bug fixes: - fix missing translation strings ([#675]) - fix kernel completions not showing up for R () + - fix tab completions not showing up in strings due to incomplete trigger kind invalidation () [#671]: https://github.com/krassowski/jupyterlab-lsp/pull/671 [#675]: https://github.com/krassowski/jupyterlab-lsp/pull/675 diff --git a/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts b/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts index 58aaaa7f1..493f8cf8f 100644 --- a/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts +++ b/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts @@ -194,11 +194,13 @@ export class LSPConnector if (this.trigger_kind == AdditionalCompletionTriggerKinds.AutoInvoked) { if (this.suppress_continuous_hinting_in.indexOf(token.type) !== -1) { this.console.debug('Suppressing completer auto-invoke in', token.type); + this.trigger_kind = CompletionTriggerKind.Invoked; return; } } else if (this.trigger_kind == CompletionTriggerKind.TriggerCharacter) { if (this.suppress_trigger_character_in.indexOf(token.type) !== -1) { this.console.debug('Suppressing completer auto-invoke in', token.type); + this.trigger_kind = CompletionTriggerKind.Invoked; return; } } From 6210fc872372c6ad98414064ae045209754216a3 Mon Sep 17 00:00:00 2001 From: krassowski Date: Sun, 10 Oct 2021 18:53:51 +0100 Subject: [PATCH 3/4] Fix path completion in strings --- CHANGELOG.md | 1 + atest/05_Features/Completion.robot | 7 ++++ atest/examples/Completion.ipynb | 25 ++++++++++++- .../features/completion/completion_handler.ts | 37 +++++++++++++++---- 4 files changed, 62 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7d88d28a..7cb658049 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - fix missing translation strings ([#675]) - fix kernel completions not showing up for R () - fix tab completions not showing up in strings due to incomplete trigger kind invalidation () + - fix path completions reconciliation for `pyls`/`pylsp` with `IPython` () [#671]: https://github.com/krassowski/jupyterlab-lsp/pull/671 [#675]: https://github.com/krassowski/jupyterlab-lsp/pull/675 diff --git a/atest/05_Features/Completion.robot b/atest/05_Features/Completion.robot index ae723048e..93f268fa1 100644 --- a/atest/05_Features/Completion.robot +++ b/atest/05_Features/Completion.robot @@ -320,6 +320,13 @@ Completes In R Magics Trigger Completer Completer Should Suggest library +Completes Paths In Strings + Enter Cell Editor 26 line=1 + Trigger Completer + Completer Should Suggest Completion.ipynb' + Press Keys None ENTER + Wait Until Keyword Succeeds 40x 0.5s Cell Editor Should Equal 26 'Completion.ipynb' + *** Keywords *** Setup Completion Test Setup Notebook Python Completion.ipynb diff --git a/atest/examples/Completion.ipynb b/atest/examples/Completion.ipynb index f83d27c96..47813a03a 100644 --- a/atest/examples/Completion.ipynb +++ b/atest/examples/Completion.ipynb @@ -200,11 +200,27 @@ "source": [ "%R li" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Path completion should work" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "'./Com" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -219,6 +235,13 @@ "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.9" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } } }, "nbformat": 4, diff --git a/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts b/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts index 493f8cf8f..785da029f 100644 --- a/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts +++ b/packages/jupyterlab-lsp/src/features/completion/completion_handler.ts @@ -372,16 +372,11 @@ export class LSPConnector let items: IExtendedCompletionItem[] = []; lspCompletionItems.forEach(match => { let kind = match.kind ? CompletionItemKind[match.kind] : ''; - let completionItem = new LazyCompletionItem( - kind, - this.icon_for(kind), - match, - this, - document.uri - ); // Update prefix values let text = match.insertText ? match.insertText : match.label; + + // declare prefix presence if needed and update it if (text.toLowerCase().startsWith(prefix.toLowerCase())) { all_non_prefixed = false; if (prefix !== token.value) { @@ -395,6 +390,34 @@ export class LSPConnector } } } + // add prefix if needed + else if (token.type === 'string' && prefix.includes('/')) { + // special case for path completion in strings, ensuring that: + // '/Com → '/Completion.ipynb + // when the returned insert text is `Completion.ipynb` (the token here is `'/Com`) + // developed against pyls and pylsp server, may not work well in other cases + const parts = prefix.split('/'); + if ( + text.toLowerCase().startsWith(parts[parts.length - 1].toLowerCase()) + ) { + let pathPrefix = parts.slice(0, -1).join('/') + '/'; + match.insertText = pathPrefix + match.insertText; + // for label removing the prefix quote if present + if (pathPrefix.startsWith("'") || pathPrefix.startsWith('"')) { + pathPrefix = pathPrefix.substr(1); + } + match.label = pathPrefix + match.label; + all_non_prefixed = false; + } + } + + let completionItem = new LazyCompletionItem( + kind, + this.icon_for(kind), + match, + this, + document.uri + ); items.push(completionItem); }); From fc92b7b353e4ec3e6d9c590165571826c9aba967 Mon Sep 17 00:00:00 2001 From: krassowski Date: Sun, 10 Oct 2021 21:34:01 +0100 Subject: [PATCH 4/4] Improve the completion test --- CHANGELOG.md | 7 ++++--- atest/05_Features/Completion.robot | 6 +++--- atest/Keywords.robot | 2 +- atest/examples/Completion.ipynb | 2 +- .../jupyterlab-lsp/src/features/completion/completion.ts | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cb658049..ff099679f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,12 +12,13 @@ - the signature box takes up less space - bug fixes: - fix missing translation strings ([#675]) - - fix kernel completions not showing up for R () - - fix tab completions not showing up in strings due to incomplete trigger kind invalidation () - - fix path completions reconciliation for `pyls`/`pylsp` with `IPython` () + - fix kernel completions not showing up for R ([#686]) + - fix tab completions not showing up in strings due to incomplete trigger kind invalidation ([#686]) + - fix path completions reconciliation for `pyls`/`pylsp` with `IPython` ([#686]) [#671]: https://github.com/krassowski/jupyterlab-lsp/pull/671 [#675]: https://github.com/krassowski/jupyterlab-lsp/pull/675 +[#686]: https://github.com/krassowski/jupyterlab-lsp/pull/686 ### `@krassowski/jupyterlab-lsp 3.8.1` (2021-08-02) diff --git a/atest/05_Features/Completion.robot b/atest/05_Features/Completion.robot index 93f268fa1..02ab3dece 100644 --- a/atest/05_Features/Completion.robot +++ b/atest/05_Features/Completion.robot @@ -321,11 +321,11 @@ Completes In R Magics Completer Should Suggest library Completes Paths In Strings - Enter Cell Editor 26 line=1 + Enter Cell Editor 26 + Press Keys None LEFT Trigger Completer - Completer Should Suggest Completion.ipynb' Press Keys None ENTER - Wait Until Keyword Succeeds 40x 0.5s Cell Editor Should Equal 26 'Completion.ipynb' + Wait Until Keyword Succeeds 40x 0.5s Cell Editor Should Equal 26 '../Completion.ipynb' *** Keywords *** Setup Completion Test diff --git a/atest/Keywords.robot b/atest/Keywords.robot index 01ad5e1e6..e1b207bd7 100644 --- a/atest/Keywords.robot +++ b/atest/Keywords.robot @@ -221,7 +221,7 @@ Open Context Menu for File Click Element ${JLAB CSS REFRESH FILES} ${selector} = Set Variable xpath://span[@class='jp-DirListing-itemText']/span\[text() = '${file}'] Wait Until Page Contains Element ${selector} timeout=10s - Open Context Menu ${selector} + Wait Until Keyword Succeeds 10 x 0.1 s Open Context Menu ${selector} Rename Jupyter File [Arguments] ${old} ${new} diff --git a/atest/examples/Completion.ipynb b/atest/examples/Completion.ipynb index 47813a03a..90e8aeb45 100644 --- a/atest/examples/Completion.ipynb +++ b/atest/examples/Completion.ipynb @@ -214,7 +214,7 @@ "metadata": {}, "outputs": [], "source": [ - "'./Com" + "'../Com'" ] } ], diff --git a/packages/jupyterlab-lsp/src/features/completion/completion.ts b/packages/jupyterlab-lsp/src/features/completion/completion.ts index 293ffa11a..9d779b71a 100644 --- a/packages/jupyterlab-lsp/src/features/completion/completion.ts +++ b/packages/jupyterlab-lsp/src/features/completion/completion.ts @@ -324,7 +324,7 @@ export class CompletionLabIntegration implements IFeatureLabIntegration { this.current_index ]; - if (!item || active.insertText != item.insertText) { + if (!item || !active || active.insertText != item.insertText) { return; }