From 64be2198468b370902b3690a83d7601cd0f19acb Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Sun, 27 Aug 2023 19:19:44 +0100 Subject: [PATCH] Restore diagnostics panel on refreshing --- .../src/features/diagnostics/index.ts | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/packages/jupyterlab-lsp/src/features/diagnostics/index.ts b/packages/jupyterlab-lsp/src/features/diagnostics/index.ts index 1b9428859..55555dd92 100644 --- a/packages/jupyterlab-lsp/src/features/diagnostics/index.ts +++ b/packages/jupyterlab-lsp/src/features/diagnostics/index.ts @@ -1,10 +1,16 @@ import { INotebookShell } from '@jupyter-notebook/application'; import { + ILayoutRestorer, JupyterFrontEnd, JupyterFrontEndPlugin, ILabShell } from '@jupyterlab/application'; -import { ICommandPalette, IThemeManager } from '@jupyterlab/apputils'; +import { + ICommandPalette, + IThemeManager, + MainAreaWidget, + WidgetTracker +} from '@jupyterlab/apputils'; import { IEditorExtensionRegistry } from '@jupyterlab/codemirror'; import { ILSPFeatureManager, @@ -19,6 +25,7 @@ import { FeatureSettings } from '../../feature'; import { diagnosticsIcon, diagnosticsPanel } from './diagnostics'; import { DiagnosticsFeature } from './feature'; +import { DiagnosticsListing } from './listing'; import { IDiagnosticsFeature } from './tokens'; export namespace CommandIDs { @@ -33,7 +40,7 @@ export const DIAGNOSTICS_PLUGIN: JupyterFrontEndPlugin = { ILSPDocumentConnectionManager, IEditorExtensionRegistry ], - optional: [IThemeManager, ICommandPalette, ITranslator], + optional: [ILayoutRestorer, IThemeManager, ICommandPalette, ITranslator], autoStart: true, activate: async ( app: JupyterFrontEnd, @@ -41,6 +48,7 @@ export const DIAGNOSTICS_PLUGIN: JupyterFrontEndPlugin = { settingRegistry: ISettingRegistry, connectionManager: ILSPDocumentConnectionManager, editorExtensionRegistry: IEditorExtensionRegistry, + restorer: ILayoutRestorer | null, themeManager: IThemeManager | null, palette: ICommandPalette | null, translator: ITranslator | null @@ -67,14 +75,21 @@ export const DIAGNOSTICS_PLUGIN: JupyterFrontEndPlugin = { connectionManager }); + const namespace = 'lsp-diagnostics'; + const tracker = new WidgetTracker>({ + namespace: namespace + }); + app.commands.addCommand(CommandIDs.showPanel, { execute: async () => { const context = assembler.getContext(); - if (!context) { + let ref = null; + if (context) { + feature.switchDiagnosticsPanelSource(context.adapter); + ref = context.adapter.widgetId; + } else { console.warn('Could not get context'); - return; } - feature.switchDiagnosticsPanelSource(context.adapter); if (!diagnosticsPanel.isRegistered) { diagnosticsPanel.trans = trans; @@ -83,12 +98,14 @@ export const DIAGNOSTICS_PLUGIN: JupyterFrontEndPlugin = { const panelWidget = diagnosticsPanel.widget; if (!panelWidget.isAttached) { + void tracker.add(panelWidget); app.shell.add(panelWidget, 'main', { - ref: context.adapter.widgetId, + ref: ref, mode: 'split-bottom' }); } app.shell.activateById(panelWidget.id); + void tracker.save(panelWidget); }, label: trans.__('Show diagnostics panel'), icon: diagnosticsIcon, @@ -117,6 +134,13 @@ export const DIAGNOSTICS_PLUGIN: JupyterFrontEndPlugin = { category: trans.__('Language Server Protocol') }); } + + if (restorer) { + void restorer.restore(tracker, { + command: CommandIDs.showPanel, + name: _ => 'listing' + }); + } } return feature; }