Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More backports to 2.x #499

Merged
merged 6 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion atest/03_Notebook.robot
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,40 @@ Foreign Extractors
Code Overrides
${file} = Set Variable Code overrides.ipynb
Setup Notebook Python ${file}
${virtual_path} = Set Variable ${VIRTUALDOCS DIR}${/}Code overrides.ipynb
${virtual_path} = Set Variable ${VIRTUALDOCS DIR}${/}${file}
Wait Until Created ${virtual_path}
${document} = Get File ${virtual_path}
Should Be Equal ${document} get_ipython().run_line_magic("ls", "")\n\n\nget_ipython().run_line_magic("pip", " freeze")\n
[Teardown] Clean Up After Working With File Code overrides.ipynb

Adding Text To Cells Is Reflected In Virtual Document
${file} = Set Variable Empty.ipynb
Setup Notebook Python ${file}
${virtual_path} = Set Variable ${VIRTUALDOCS DIR}${/}${file}
Wait Until Created ${virtual_path}
Enter Cell Editor 1
Press Keys None cell_1
Lab Command Insert Cell Below
Enter Cell Editor 2
Press Keys None cell_2
Wait Until Keyword Succeeds 3x 1s File Content Should Be Equal ${virtual_path} cell_1\n\n\ncell_2\n
[Teardown] Clean Up After Working With File Empty.ipynb

Adding Text To Cells After Kernel Restart
${file} = Set Variable Empty.ipynb
Setup Notebook Python ${file}
${virtual_path} = Set Variable ${VIRTUALDOCS DIR}${/}${file}
Wait Until Created ${virtual_path}
Enter Cell Editor 1
Lab Command Insert Cell Below
Enter Cell Editor 2 line=1
Press Keys None text
Wait Until Keyword Succeeds 3x 1s File Content Should Be Equal ${virtual_path} \n\n\ntext\n
[Teardown] Clean Up After Working With File Empty.ipynb

*** Keywords ***
File Content Should Be Equal
[Arguments] ${file} ${text}
Wait Until Keyword Succeeds 5x 1s File Should Not Be Empty ${file}
${document} = Get File ${file}
Should Be Equal ${document} ${text}
10 changes: 10 additions & 0 deletions atest/04_Interface/DiagnosticsPanel.robot
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ Diagnostics Panel Works After Rename
Wait Until Keyword Succeeds 10 x 1s Should Have Expected Rows Count ${EXPECTED_COUNT}
Clean Up After Working With File PanelRenamed.ipynb

Diagnostics Panel Works After Kernel Restart
[Documentation] Test for #475 bug
Close Diagnostics Panel
Lab Command Restart Kernel…
Wait For Dialog
Accept Default Dialog Option
Wait Until Page Contains Element css:.cm-lsp-diagnostic[title*="${DIAGNOSTIC}"] timeout=20s
Open Diagnostics Panel
Wait Until Keyword Succeeds 10 x 1s Should Have Expected Rows Count ${EXPECTED_COUNT}

Diagnostics Panel Can Be Restored
Close Diagnostics Panel
Open Diagnostics Panel
Expand Down
5 changes: 1 addition & 4 deletions atest/04_Interface/Statusbar.robot
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ Statusbar Popup Opens
Status Changes Between Notebooks
Setup Notebook Python Python.ipynb
Wait Until Fully Initialized
Lab Command New Notebook
Wait For Dialog
# Kernel selection dialog shows up, accept Python as default kernel
Accept Default Dialog Option
Open New Notebook
Element Should Contain ${STATUSBAR} Waiting...
Wait Until Fully Initialized
Switch To Tab Python.ipynb
Expand Down
16 changes: 16 additions & 0 deletions atest/05_Features/Completion.robot
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Works With Kernel Running

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

Works After Kernel Restart In New Cells
Lab Command Restart Kernel…
Wait For Dialog
Accept Default Dialog Option
Enter Cell Editor 1 line=2
# works in old cells
Trigger Completer
Completer Should Suggest test
Lab Command Insert Cell Below
Enter Cell Editor 2 line=1
# works in new cells
Press Keys None lis
Trigger Completer
Completer Should Suggest list

Works In File Editor
Prepare File for Editing Python completion completion.py
Place Cursor In File Editor At 9 2
Expand Down
11 changes: 11 additions & 0 deletions atest/Keywords.robot
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,14 @@ Measure Cursor Position
Wait Until Page Contains Element ${CM CURSORS}
${position} = Wait Until Keyword Succeeds 20 x 0.05s Get Vertical Position ${CM CURSOR}
[Return] ${position}

Switch To Tab
[Arguments] ${file}
Click Element ${JLAB XP DOCK TAB}\[contains(., '${file}')]

Open New Notebook
Lab Command New Notebook
Wait For Dialog
# Kernel selection dialog shows up, accept Python as default kernel
Accept Default Dialog Option

32 changes: 32 additions & 0 deletions atest/examples/Empty.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.9"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
57 changes: 37 additions & 20 deletions packages/jupyterlab-lsp/src/adapters/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,8 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
this.widget.context.saveState.disconnect(this.on_save_state, this);
this.connection_manager.closed.disconnect(this.on_connection_closed, this);
this.widget.disposed.disconnect(this.dispose, this);
this.widget.context.model.contentChanged.disconnect(
this.onContentChanged,
this
);

for (let adapter of this.adapters.values()) {
adapter.dispose();
}
this.adapters.clear();

this.connection_manager.disconnect_document_signals(
this.virtual_editor.virtual_document
);
this.virtual_editor.dispose();
this.disconnect();

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

abstract get language_file_extension(): string;

disconnect() {
this.connection_manager.unregister_document(
this.virtual_editor.virtual_document
);
this.widget.context.model.contentChanged.disconnect(
this.onContentChanged,
this
);

// pretend that all editors were removed to trigger the disconnection of even handlers
// they will be connected again on new connection
for (let editor of this.editors) {
this.editorRemoved.emit({
editor: editor
});
}

for (let adapter of this.adapters.values()) {
adapter.dispose();
}
this.adapters.clear();

this.virtual_editor.dispose();
}

// equivalent to triggering didClose and didOpen, as per syncing specification,
// but also reloads the connection; used during file rename (or when it was moved)
protected reload_connection() {
Expand All @@ -231,15 +244,18 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
}

// disconnect all existing connections (and dispose adapters)
this.connection_manager.unregister_document(
this.virtual_editor.virtual_document
);
this.disconnect();

// recreate virtual document using current path and language
let virtual_document = this.create_virtual_document();
this.virtual_editor.virtual_document = virtual_document;
// as virtual editor assumes it gets the virtual document at init,
// just dispose virtual editor (which disposes virtual document too)
// and re-initialize both virtual editor and document
this.init_virtual();

// reconnect
this.connect_document(virtual_document, true).catch(console.warn);
this.connect_document(this.virtual_editor.virtual_document, true).catch(
console.warn
);
}

protected on_save_state(context: any, state: DocumentRegistry.SaveState) {
Expand Down Expand Up @@ -361,6 +377,7 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
return;
}
this.virtual_editor = virtual_editor;
this.connect_contentChanged_signal();
}

/**
Expand Down Expand Up @@ -507,7 +524,7 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
* (range) updates this can be still implemented by comparison of before/after states of the
* virtual documents, which is even more resilient and -obviously - editor-independent.
*/
connect_contentChanged_signal() {
private connect_contentChanged_signal() {
this.widget.context.model.contentChanged.connect(
this.onContentChanged,
this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export class FileEditorAdapter extends WidgetAdapter<
this.editor = editor_widget.content;

this.init_virtual();
this.connect_contentChanged_signal();

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

Expand Down
Loading