Skip to content

Commit ce963da

Browse files
authored
Merge pull request #140 from yunair/fix_ws_signature
fix ws signature failed
2 parents 5a21fe6 + 8266290 commit ce963da

File tree

16 files changed

+238
-22
lines changed

16 files changed

+238
-22
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
## `lsp-ws-connection 0.3.1`
44

5-
- added sendSaved() method (textDocument/didSave) (
5+
- added `sendSaved()` method (textDocument/didSave) (
66
[#147](https://github.com/krassowski/jupyterlab-lsp/pull/147)
77
)
8+
- fixed `getSignatureHelp()` off-by-one error (
9+
[#140](https://github.com/krassowski/jupyterlab-lsp/pull/140)
10+
)
811

912
## `@krassowski/jupyterlab-lsp 0.7.0-rc.0`
1013

@@ -38,6 +41,8 @@
3841
exctracted R documents (improved foreign code extractor) (
3942
[#148](https://github.com/krassowski/jupyterlab-lsp/pull/148)
4043
)
44+
- console logs can now easily be redirected to a floating console
45+
windows for debugging of the browser tests (see CONTRIBUTING.md)
4146

4247
- bugfixes
4348
- diagnostics in foreign documents are now correctly updated (
@@ -62,6 +67,9 @@
6267
[#95](https://github.com/krassowski/jupyterlab-lsp/pull/95),
6368
[#147](https://github.com/krassowski/jupyterlab-lsp/pull/147),
6469
)
70+
- signature feature is now correctly working in notebooks (
71+
[#140](https://github.com/krassowski/jupyterlab-lsp/pull/140)
72+
)
6573

6674
## `lsp-ws-connection 0.3.0`
6775

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ atest/
185185

186186
and re-run the tests.
187187

188+
- To display logs on the screenshots, write logs with `virtual_editor.console.log` method,
189+
and change `create_console('browser')` to `create_console('floating')` in `VirtualEditor`
190+
constructor (please feel free to add a config option for this).
191+
188192
### Formatting
189193

190194
Minimal code style is enforced with `pytest-flake8` during unit testing. If installed,

atest/05_Features/Completion.robot

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ Suite Setup Setup Suite For Screenshots completion
33
Resource ../Keywords.robot
44

55
*** Variables ***
6-
${STATUSBAR} css:div.lsp-statusbar-item
76
${COMPLETER_BOX} css:.jp-Completer.jp-HoverBox
87

98
*** Test Cases ***
109
Works With Kernel Running
1110
[Documentation] The suggestions from kernel and LSP should get integrated.
1211
Setup Notebook Python Completion.ipynb
13-
Wait Until Element Contains ${STATUSBAR} Fully initialized timeout=20s
12+
Wait Until Fully Initialized
1413
Enter Cell Editor 1 line=2
1514
Capture Page Screenshot 01-entered-cell.png
1615
Trigger Completer
@@ -29,6 +28,7 @@ Works With Kernel Running
2928

3029
Works When Kernel Is Shut Down
3130
Setup Notebook Python Completion.ipynb
31+
Wait Until Fully Initialized
3232
Lab Command Shut Down All Kernels…
3333
Capture Page Screenshot 01-shutting-kernels.png
3434
Accept Default Dialog Option
@@ -46,6 +46,7 @@ Autocompletes If Only One Option
4646
Setup Notebook Python Completion.ipynb
4747
Enter Cell Editor 3 line=1
4848
Press Keys None cle
49+
Wait Until Fully Initialized
4950
Press Keys None TAB
5051
Wait Until Keyword Succeeds 40x 0.5s Cell Editor Should Equal 3 list.clear
5152
[Teardown] Clean Up After Working With File Completion.ipynb
@@ -54,17 +55,22 @@ User Can Select Lowercase After Starting Uppercase
5455
Setup Notebook Python Completion.ipynb
5556
Enter Cell Editor 4 line=1
5657
Trigger Completer
57-
Completer Should Suggest time
58+
Completer Should Suggest time
5859
Press Keys None ENTER
5960
Wait Until Keyword Succeeds 40x 0.5s Cell Editor Should Equal 4 from time import time
6061
[Teardown] Clean Up After Working With File Completion.ipynb
6162

62-
*** Keywords ***
63-
Enter Cell Editor
64-
[Arguments] ${cell_nr} ${line}=1
65-
Click Element css:.jp-CodeCell:nth-child(${cell_nr}) .CodeMirror-line:nth-child(${line})
66-
Wait Until Page Contains Element css:.jp-CodeCell:nth-child(${cell_nr}) .CodeMirror-focused
63+
Triggers Completer On Dot
64+
Setup Notebook Python Completion.ipynb
65+
Enter Cell Editor 2 line=1
66+
Wait Until Fully Initialized
67+
Press Keys None .
68+
Wait Until Keyword Succeeds 10x 0.5s Cell Editor Should Equal 2 list.
69+
Wait Until Page Contains Element ${COMPLETER_BOX} timeout=35s
70+
Completer Should Suggest append
71+
[Teardown] Clean Up After Working With File Completion.ipynb
6772

73+
*** Keywords ***
6874
Get Cell Editor Content
6975
[Arguments] ${cell_nr}
7076
${content} Execute JavaScript return document.querySelector('.jp-CodeCell:nth-child(${cell_nr}) .CodeMirror').CodeMirror.getValue()
@@ -85,4 +91,4 @@ Completer Should Not Suggest
8591

8692
Trigger Completer
8793
Press Keys None TAB
88-
Wait Until Page Contains Element ${COMPLETER_BOX} timeout=15s
94+
Wait Until Page Contains Element ${COMPLETER_BOX} timeout=35s

atest/05_Features/Signature.robot

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
*** Settings ***
2+
Suite Setup Setup Suite For Screenshots completion
3+
Resource ../Keywords.robot
4+
5+
*** Variables ***
6+
${SIGNATURE_BOX} css:.lsp-signature-help
7+
8+
*** Test Cases ***
9+
Triggers Signature Help After A Keystroke
10+
Setup Notebook Python Signature.ipynb
11+
Wait Until Fully Initialized
12+
Enter Cell Editor 1 line=6
13+
Capture Page Screenshot 01-entered-cell.png
14+
Press Keys None (
15+
Capture Page Screenshot 02-signature-shown.png
16+
Wait Until Keyword Succeeds 20x 0.5s Page Should Contain Element ${SIGNATURE_BOX}
17+
Element Should Contain ${SIGNATURE_BOX} Important docstring of abc()
18+
[Teardown] Clean Up After Working With File Signature.ipynb

atest/Keywords.robot

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ Ensure All Kernels Are Shut Down
7878
Enter Command Name Shut Down All Kernels
7979
${els} = Get WebElements ${CMD PALETTE ITEM ACTIVE}
8080
Run Keyword If ${els.__len__()} Click Element ${CMD PALETTE ITEM ACTIVE}
81-
Run Keyword If ${els.__len__()} Click Element css:.jp-mod-accept.jp-mod-warn
81+
${accept} = Set Variable css:.jp-mod-accept.jp-mod-warn
82+
Run Keyword If ${els.__len__()} Wait Until Page Contains Element ${accept}
83+
Run Keyword If ${els.__len__()} Click Element ${accept}
8284

8385
Open Command Palette
8486
Press Keys id:main ${ACCEL}+SHIFT+c
@@ -189,3 +191,11 @@ Wait For Dialog
189191

190192
Gently Reset Workspace
191193
Lab Command Close All Tabs
194+
195+
Enter Cell Editor
196+
[Arguments] ${cell_nr} ${line}=1
197+
Click Element css:.jp-CodeCell:nth-child(${cell_nr}) .CodeMirror-line:nth-child(${line})
198+
Wait Until Page Contains Element css:.jp-CodeCell:nth-child(${cell_nr}) .CodeMirror-focused
199+
200+
Wait Until Fully Initialized
201+
Wait Until Element Contains ${STATUSBAR} Fully initialized timeout=35s

atest/Variables.robot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ ${DIAGNOSTIC PANEL CLOSE} css:.p-DockPanel-tabBar .p-TabBar-tab[data-id="lsp-
2121
${DIALOG WINDOW} css:.jp-Dialog
2222
${DIALOG INPUT} css:.jp-Input-Dialog input
2323
${DIALOG ACCEPT} css:button.jp-Dialog-button.jp-mod-accept
24+
${STATUSBAR} css:div.lsp-statusbar-item

atest/examples/Signature.ipynb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": false,
8+
"jupyter": {
9+
"outputs_hidden": false
10+
}
11+
},
12+
"outputs": [],
13+
"source": [
14+
"def abc(x=1):\n",
15+
" \"\"\"Important docstring of abc()\"\"\"\n",
16+
" pass\n",
17+
"\n",
18+
"\n",
19+
"abc"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": null,
25+
"metadata": {},
26+
"outputs": [],
27+
"source": [
28+
"list"
29+
]
30+
}
31+
],
32+
"metadata": {
33+
"kernelspec": {
34+
"display_name": "Python 3",
35+
"language": "python",
36+
"name": "python3"
37+
},
38+
"language_info": {
39+
"codemirror_mode": {
40+
"name": "ipython",
41+
"version": 3
42+
},
43+
"file_extension": ".py",
44+
"mimetype": "text/x-python",
45+
"name": "python",
46+
"nbconvert_exporter": "python",
47+
"pygments_lexer": "ipython3",
48+
"version": "3.8.0"
49+
}
50+
},
51+
"nbformat": 4,
52+
"nbformat_minor": 4
53+
}

packages/jupyterlab-lsp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
},
4040
"dependencies": {
4141
"@krassowski/jupyterlab_go_to_definition": "^0.7.1",
42-
"lsp-ws-connection": "*"
42+
"lsp-ws-connection": "0.3.1"
4343
},
4444
"devDependencies": {
4545
"@babel/preset-env": "^7.4.3",

packages/jupyterlab-lsp/src/adapters/codemirror/cm_adapter.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ export class CodeMirrorAdapter {
2626
for (let feature of features) {
2727
feature.register();
2828
if (!feature.is_registered) {
29-
console.warn('The feature ', feature, 'was not registered properly');
29+
this.editor.console.warn(
30+
'The feature ',
31+
feature,
32+
'was not registered properly'
33+
);
3034
}
3135
this.features.set(feature.name, feature);
3236
}
@@ -63,8 +67,8 @@ export class CodeMirrorAdapter {
6367
}
6468
return true;
6569
} catch (e) {
66-
console.log('updateAfterChange failure');
67-
console.error(e);
70+
this.editor.console.log('updateAfterChange failure');
71+
this.editor.console.error(e);
6872
}
6973
this.invalidateLastChange();
7074
}

packages/jupyterlab-lsp/src/adapters/codemirror/features/completion.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export class Completion extends CodeMirrorLSPFeature {
2525
// requires an up-to-date virtual document on the LSP side, so we need to wait for sync.
2626
let last_character = this.extract_last_character(change);
2727
if (this.completionCharacters.indexOf(last_character) > -1) {
28+
this.virtual_editor.console.log(
29+
'Will invoke completer after',
30+
last_character
31+
);
2832
this.jupyterlab_components.invoke_completer(
2933
CompletionTriggerKind.TriggerCharacter
3034
);

0 commit comments

Comments
 (0)