11import { INotebookShell } from '@jupyter-notebook/application' ;
22import {
3+ ILayoutRestorer ,
34 JupyterFrontEnd ,
45 JupyterFrontEndPlugin ,
56 ILabShell
67} from '@jupyterlab/application' ;
7- import { ICommandPalette , IThemeManager } from '@jupyterlab/apputils' ;
8+ import {
9+ ICommandPalette ,
10+ IThemeManager ,
11+ MainAreaWidget ,
12+ WidgetTracker
13+ } from '@jupyterlab/apputils' ;
814import { IEditorExtensionRegistry } from '@jupyterlab/codemirror' ;
915import {
1016 ILSPFeatureManager ,
@@ -19,6 +25,7 @@ import { FeatureSettings } from '../../feature';
1925
2026import { diagnosticsIcon , diagnosticsPanel } from './diagnostics' ;
2127import { DiagnosticsFeature } from './feature' ;
28+ import { DiagnosticsListing } from './listing' ;
2229import { IDiagnosticsFeature } from './tokens' ;
2330
2431export namespace CommandIDs {
@@ -33,14 +40,15 @@ export const DIAGNOSTICS_PLUGIN: JupyterFrontEndPlugin<IDiagnosticsFeature> = {
3340 ILSPDocumentConnectionManager ,
3441 IEditorExtensionRegistry
3542 ] ,
36- optional : [ IThemeManager , ICommandPalette , ITranslator ] ,
43+ optional : [ ILayoutRestorer , IThemeManager , ICommandPalette , ITranslator ] ,
3744 autoStart : true ,
3845 activate : async (
3946 app : JupyterFrontEnd ,
4047 featureManager : ILSPFeatureManager ,
4148 settingRegistry : ISettingRegistry ,
4249 connectionManager : ILSPDocumentConnectionManager ,
4350 editorExtensionRegistry : IEditorExtensionRegistry ,
51+ restorer : ILayoutRestorer | null ,
4452 themeManager : IThemeManager | null ,
4553 palette : ICommandPalette | null ,
4654 translator : ITranslator | null
@@ -67,14 +75,21 @@ export const DIAGNOSTICS_PLUGIN: JupyterFrontEndPlugin<IDiagnosticsFeature> = {
6775 connectionManager
6876 } ) ;
6977
78+ const namespace = 'lsp-diagnostics' ;
79+ const tracker = new WidgetTracker < MainAreaWidget < DiagnosticsListing > > ( {
80+ namespace : namespace
81+ } ) ;
82+
7083 app . commands . addCommand ( CommandIDs . showPanel , {
7184 execute : async ( ) => {
7285 const context = assembler . getContext ( ) ;
73- if ( ! context ) {
86+ let ref = null ;
87+ if ( context ) {
88+ feature . switchDiagnosticsPanelSource ( context . adapter ) ;
89+ ref = context . adapter . widgetId ;
90+ } else {
7491 console . warn ( 'Could not get context' ) ;
75- return ;
7692 }
77- feature . switchDiagnosticsPanelSource ( context . adapter ) ;
7893
7994 if ( ! diagnosticsPanel . isRegistered ) {
8095 diagnosticsPanel . trans = trans ;
@@ -83,12 +98,14 @@ export const DIAGNOSTICS_PLUGIN: JupyterFrontEndPlugin<IDiagnosticsFeature> = {
8398
8499 const panelWidget = diagnosticsPanel . widget ;
85100 if ( ! panelWidget . isAttached ) {
101+ void tracker . add ( panelWidget ) ;
86102 app . shell . add ( panelWidget , 'main' , {
87- ref : context . adapter . widgetId ,
103+ ref : ref ,
88104 mode : 'split-bottom'
89105 } ) ;
90106 }
91107 app . shell . activateById ( panelWidget . id ) ;
108+ void tracker . save ( panelWidget ) ;
92109 } ,
93110 label : trans . __ ( 'Show diagnostics panel' ) ,
94111 icon : diagnosticsIcon ,
@@ -117,6 +134,13 @@ export const DIAGNOSTICS_PLUGIN: JupyterFrontEndPlugin<IDiagnosticsFeature> = {
117134 category : trans . __ ( 'Language Server Protocol' )
118135 } ) ;
119136 }
137+
138+ if ( restorer ) {
139+ void restorer . restore ( tracker , {
140+ command : CommandIDs . showPanel ,
141+ name : _ => 'listing'
142+ } ) ;
143+ }
120144 }
121145 return feature ;
122146 }
0 commit comments