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

Restore diagnostics panel on refreshing #967

Merged
merged 1 commit into from
Aug 29, 2023
Merged
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
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