Skip to content

Commit 2dbab04

Browse files
authored
Merge pull request #499 from jtpio/backports-2-x
More backports to 2.x
2 parents fe2b568 + d14af99 commit 2dbab04

File tree

11 files changed

+296
-127
lines changed

11 files changed

+296
-127
lines changed

atest/03_Notebook.robot

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,40 @@ Foreign Extractors
6666
Code Overrides
6767
${file} = Set Variable Code overrides.ipynb
6868
Setup Notebook Python ${file}
69-
${virtual_path} = Set Variable ${VIRTUALDOCS DIR}${/}Code overrides.ipynb
69+
${virtual_path} = Set Variable ${VIRTUALDOCS DIR}${/}${file}
7070
Wait Until Created ${virtual_path}
7171
${document} = Get File ${virtual_path}
7272
Should Be Equal ${document} get_ipython().run_line_magic("ls", "")\n\n\nget_ipython().run_line_magic("pip", " freeze")\n
73+
[Teardown] Clean Up After Working With File Code overrides.ipynb
74+
75+
Adding Text To Cells Is Reflected In Virtual Document
76+
${file} = Set Variable Empty.ipynb
77+
Setup Notebook Python ${file}
78+
${virtual_path} = Set Variable ${VIRTUALDOCS DIR}${/}${file}
79+
Wait Until Created ${virtual_path}
80+
Enter Cell Editor 1
81+
Press Keys None cell_1
82+
Lab Command Insert Cell Below
83+
Enter Cell Editor 2
84+
Press Keys None cell_2
85+
Wait Until Keyword Succeeds 3x 1s File Content Should Be Equal ${virtual_path} cell_1\n\n\ncell_2\n
86+
[Teardown] Clean Up After Working With File Empty.ipynb
87+
88+
Adding Text To Cells After Kernel Restart
89+
${file} = Set Variable Empty.ipynb
90+
Setup Notebook Python ${file}
91+
${virtual_path} = Set Variable ${VIRTUALDOCS DIR}${/}${file}
92+
Wait Until Created ${virtual_path}
93+
Enter Cell Editor 1
94+
Lab Command Insert Cell Below
95+
Enter Cell Editor 2 line=1
96+
Press Keys None text
97+
Wait Until Keyword Succeeds 3x 1s File Content Should Be Equal ${virtual_path} \n\n\ntext\n
98+
[Teardown] Clean Up After Working With File Empty.ipynb
99+
100+
*** Keywords ***
101+
File Content Should Be Equal
102+
[Arguments] ${file} ${text}
103+
Wait Until Keyword Succeeds 5x 1s File Should Not Be Empty ${file}
104+
${document} = Get File ${file}
105+
Should Be Equal ${document} ${text}

atest/04_Interface/DiagnosticsPanel.robot

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ Diagnostics Panel Works After Rename
2828
Wait Until Keyword Succeeds 10 x 1s Should Have Expected Rows Count ${EXPECTED_COUNT}
2929
Clean Up After Working With File PanelRenamed.ipynb
3030

31+
Diagnostics Panel Works After Kernel Restart
32+
[Documentation] Test for #475 bug
33+
Close Diagnostics Panel
34+
Lab Command Restart Kernel…
35+
Wait For Dialog
36+
Accept Default Dialog Option
37+
Wait Until Page Contains Element css:.cm-lsp-diagnostic[title*="${DIAGNOSTIC}"] timeout=20s
38+
Open Diagnostics Panel
39+
Wait Until Keyword Succeeds 10 x 1s Should Have Expected Rows Count ${EXPECTED_COUNT}
40+
3141
Diagnostics Panel Can Be Restored
3242
Close Diagnostics Panel
3343
Open Diagnostics Panel

atest/04_Interface/Statusbar.robot

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ Statusbar Popup Opens
2222
Status Changes Between Notebooks
2323
Setup Notebook Python Python.ipynb
2424
Wait Until Fully Initialized
25-
Lab Command New Notebook
26-
Wait For Dialog
27-
# Kernel selection dialog shows up, accept Python as default kernel
28-
Accept Default Dialog Option
25+
Open New Notebook
2926
Element Should Contain ${STATUSBAR} Waiting...
3027
Wait Until Fully Initialized
3128
Switch To Tab Python.ipynb

atest/05_Features/Completion.robot

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Works With Kernel Running
2828

2929
Works When Kernel Is Shut Down
3030
Lab Command Shut Down All Kernels…
31+
Wait For Dialog
3132
Capture Page Screenshot 01-shutting-kernels.png
3233
Accept Default Dialog Option
3334
Capture Page Screenshot 02-kernels-shut.png
@@ -39,6 +40,21 @@ Works When Kernel Is Shut Down
3940
# this comes from kernel:
4041
Completer Should Not Suggest %%timeit
4142

43+
Works After Kernel Restart In New Cells
44+
Lab Command Restart Kernel…
45+
Wait For Dialog
46+
Accept Default Dialog Option
47+
Enter Cell Editor 1 line=2
48+
# works in old cells
49+
Trigger Completer
50+
Completer Should Suggest test
51+
Lab Command Insert Cell Below
52+
Enter Cell Editor 2 line=1
53+
# works in new cells
54+
Press Keys None lis
55+
Trigger Completer
56+
Completer Should Suggest list
57+
4258
Works In File Editor
4359
Prepare File for Editing Python completion completion.py
4460
Place Cursor In File Editor At 9 2

atest/Keywords.robot

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,3 +389,14 @@ Measure Cursor Position
389389
Wait Until Page Contains Element ${CM CURSORS}
390390
${position} = Wait Until Keyword Succeeds 20 x 0.05s Get Vertical Position ${CM CURSOR}
391391
[Return] ${position}
392+
393+
Switch To Tab
394+
[Arguments] ${file}
395+
Click Element ${JLAB XP DOCK TAB}\[contains(., '${file}')]
396+
397+
Open New Notebook
398+
Lab Command New Notebook
399+
Wait For Dialog
400+
# Kernel selection dialog shows up, accept Python as default kernel
401+
Accept Default Dialog Option
402+

atest/examples/Empty.ipynb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": []
9+
}
10+
],
11+
"metadata": {
12+
"kernelspec": {
13+
"display_name": "Python 3",
14+
"language": "python",
15+
"name": "python3"
16+
},
17+
"language_info": {
18+
"codemirror_mode": {
19+
"name": "ipython",
20+
"version": 3
21+
},
22+
"file_extension": ".py",
23+
"mimetype": "text/x-python",
24+
"name": "python",
25+
"nbconvert_exporter": "python",
26+
"pygments_lexer": "ipython3",
27+
"version": "3.7.9"
28+
}
29+
},
30+
"nbformat": 4,
31+
"nbformat_minor": 4
32+
}

packages/jupyterlab-lsp/src/adapters/adapter.ts

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,8 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
165165
this.widget.context.saveState.disconnect(this.on_save_state, this);
166166
this.connection_manager.closed.disconnect(this.on_connection_closed, this);
167167
this.widget.disposed.disconnect(this.dispose, this);
168-
this.widget.context.model.contentChanged.disconnect(
169-
this.onContentChanged,
170-
this
171-
);
172168

173-
for (let adapter of this.adapters.values()) {
174-
adapter.dispose();
175-
}
176-
this.adapters.clear();
177-
178-
this.connection_manager.disconnect_document_signals(
179-
this.virtual_editor.virtual_document
180-
);
181-
this.virtual_editor.dispose();
169+
this.disconnect();
182170

183171
// just to be sure
184172
this.virtual_editor = null;
@@ -222,6 +210,31 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
222210

223211
abstract get language_file_extension(): string;
224212

213+
disconnect() {
214+
this.connection_manager.unregister_document(
215+
this.virtual_editor.virtual_document
216+
);
217+
this.widget.context.model.contentChanged.disconnect(
218+
this.onContentChanged,
219+
this
220+
);
221+
222+
// pretend that all editors were removed to trigger the disconnection of even handlers
223+
// they will be connected again on new connection
224+
for (let editor of this.editors) {
225+
this.editorRemoved.emit({
226+
editor: editor
227+
});
228+
}
229+
230+
for (let adapter of this.adapters.values()) {
231+
adapter.dispose();
232+
}
233+
this.adapters.clear();
234+
235+
this.virtual_editor.dispose();
236+
}
237+
225238
// equivalent to triggering didClose and didOpen, as per syncing specification,
226239
// but also reloads the connection; used during file rename (or when it was moved)
227240
protected reload_connection() {
@@ -231,15 +244,18 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
231244
}
232245

233246
// disconnect all existing connections (and dispose adapters)
234-
this.connection_manager.unregister_document(
235-
this.virtual_editor.virtual_document
236-
);
247+
this.disconnect();
237248

238249
// recreate virtual document using current path and language
239-
let virtual_document = this.create_virtual_document();
240-
this.virtual_editor.virtual_document = virtual_document;
250+
// as virtual editor assumes it gets the virtual document at init,
251+
// just dispose virtual editor (which disposes virtual document too)
252+
// and re-initialize both virtual editor and document
253+
this.init_virtual();
254+
241255
// reconnect
242-
this.connect_document(virtual_document, true).catch(console.warn);
256+
this.connect_document(this.virtual_editor.virtual_document, true).catch(
257+
console.warn
258+
);
243259
}
244260

245261
protected on_save_state(context: any, state: DocumentRegistry.SaveState) {
@@ -361,6 +377,7 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
361377
return;
362378
}
363379
this.virtual_editor = virtual_editor;
380+
this.connect_contentChanged_signal();
364381
}
365382

366383
/**
@@ -507,7 +524,7 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
507524
* (range) updates this can be still implemented by comparison of before/after states of the
508525
* virtual documents, which is even more resilient and -obviously - editor-independent.
509526
*/
510-
connect_contentChanged_signal() {
527+
private connect_contentChanged_signal() {
511528
this.widget.context.model.contentChanged.connect(
512529
this.onContentChanged,
513530
this

packages/jupyterlab-lsp/src/adapters/file_editor/file_editor.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export class FileEditorAdapter extends WidgetAdapter<
4646
this.editor = editor_widget.content;
4747

4848
this.init_virtual();
49-
this.connect_contentChanged_signal();
5049

5150
console.log('LSP: file ready for connection:', this.path);
5251

0 commit comments

Comments
 (0)