Skip to content

Commit 7d4198d

Browse files
committed
Ensure that diagnostics panel works after restart
1 parent cfa0cfd commit 7d4198d

File tree

3 files changed

+37
-20
lines changed

3 files changed

+37
-20
lines changed

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

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

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -167,20 +167,8 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
167167
this.widget.context.saveState.disconnect(this.on_save_state, this);
168168
this.connection_manager.closed.disconnect(this.on_connection_closed, this);
169169
this.widget.disposed.disconnect(this.dispose, this);
170-
this.widget.context.model.contentChanged.disconnect(
171-
this.onContentChanged,
172-
this
173-
);
174170

175-
for (let adapter of this.adapters.values()) {
176-
adapter.dispose();
177-
}
178-
this.adapters.clear();
179-
180-
this.connection_manager.disconnect_document_signals(
181-
this.virtual_editor.virtual_document
182-
);
183-
this.virtual_editor.dispose();
171+
this.disconnect();
184172

185173
// just to be sure
186174
this.virtual_editor = null;
@@ -224,6 +212,23 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
224212

225213
abstract get language_file_extension(): string;
226214

215+
disconnect() {
216+
this.connection_manager.unregister_document(
217+
this.virtual_editor.virtual_document
218+
);
219+
this.widget.context.model.contentChanged.disconnect(
220+
this.onContentChanged,
221+
this
222+
);
223+
224+
for (let adapter of this.adapters.values()) {
225+
adapter.dispose();
226+
}
227+
this.adapters.clear();
228+
229+
this.virtual_editor.dispose();
230+
}
231+
227232
// equivalent to triggering didClose and didOpen, as per syncing specification,
228233
// but also reloads the connection; used during file rename (or when it was moved)
229234
protected reload_connection() {
@@ -233,16 +238,12 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
233238
}
234239

235240
// disconnect all existing connections (and dispose adapters)
236-
this.connection_manager.unregister_document(
237-
this.virtual_editor.virtual_document
238-
);
241+
this.disconnect();
239242

240243
// recreate virtual document using current path and language
241244
// as virtual editor assumes it gets the virtual document at init,
242245
// just dispose virtual editor (which disposes virtual document too)
243246
// and re-initialize both virtual editor and document
244-
this.virtual_editor.dispose();
245-
246247
this.init_virtual();
247248

248249
// reconnect

packages/jupyterlab-lsp/src/features/diagnostics/diagnostics.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ export class DiagnosticsCM extends CodeMirrorIntegration {
276276
this.wrapper_handlers.set('focusin', this.switchDiagnosticsPanelSource);
277277
this.unique_editor_ids = new DefaultMap(() => this.unique_editor_ids.size);
278278
this.settings.changed.connect(this.refreshDiagnostics, this);
279+
this.adapter.adapterConnected.connect(() =>
280+
this.switchDiagnosticsPanelSource()
281+
);
279282
super.register();
280283
}
281284

@@ -300,7 +303,8 @@ export class DiagnosticsCM extends CodeMirrorIntegration {
300303

301304
switchDiagnosticsPanelSource = () => {
302305
if (
303-
diagnostics_panel.content.model.virtual_editor === this.virtual_editor
306+
diagnostics_panel.content.model.virtual_editor === this.virtual_editor &&
307+
diagnostics_panel.content.model.diagnostics == this.diagnostics_db
304308
) {
305309
return;
306310
}
@@ -596,7 +600,9 @@ export class DiagnosticsCM extends CodeMirrorIntegration {
596600
};
597601

598602
public refreshDiagnostics() {
599-
this.setDiagnostics(this.last_response);
603+
if (this.last_response) {
604+
this.setDiagnostics(this.last_response);
605+
}
600606
diagnostics_panel.update();
601607
}
602608

0 commit comments

Comments
 (0)