Skip to content

Commit

Permalink
Merge pull request #967 from krassowski/restore-panel
Browse files Browse the repository at this point in the history
Restore diagnostics panel on refreshing
  • Loading branch information
krassowski authored Aug 29, 2023
2 parents 64efa34 + 64be219 commit 3bf1c07
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions packages/jupyterlab-lsp/src/features/diagnostics/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 {
Expand All @@ -33,14 +40,15 @@ export const DIAGNOSTICS_PLUGIN: JupyterFrontEndPlugin<IDiagnosticsFeature> = {
ILSPDocumentConnectionManager,
IEditorExtensionRegistry
],
optional: [IThemeManager, ICommandPalette, ITranslator],
optional: [ILayoutRestorer, IThemeManager, ICommandPalette, ITranslator],
autoStart: true,
activate: async (
app: JupyterFrontEnd,
featureManager: ILSPFeatureManager,
settingRegistry: ISettingRegistry,
connectionManager: ILSPDocumentConnectionManager,
editorExtensionRegistry: IEditorExtensionRegistry,
restorer: ILayoutRestorer | null,
themeManager: IThemeManager | null,
palette: ICommandPalette | null,
translator: ITranslator | null
Expand All @@ -67,14 +75,21 @@ export const DIAGNOSTICS_PLUGIN: JupyterFrontEndPlugin<IDiagnosticsFeature> = {
connectionManager
});

const namespace = 'lsp-diagnostics';
const tracker = new WidgetTracker<MainAreaWidget<DiagnosticsListing>>({
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;
Expand All @@ -83,12 +98,14 @@ export const DIAGNOSTICS_PLUGIN: JupyterFrontEndPlugin<IDiagnosticsFeature> = {

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,
Expand Down Expand Up @@ -117,6 +134,13 @@ export const DIAGNOSTICS_PLUGIN: JupyterFrontEndPlugin<IDiagnosticsFeature> = {
category: trans.__('Language Server Protocol')
});
}

if (restorer) {
void restorer.restore(tracker, {
command: CommandIDs.showPanel,
name: _ => 'listing'
});
}
}
return feature;
}
Expand Down

0 comments on commit 3bf1c07

Please sign in to comment.