11import * as CodeMirror from 'codemirror' ;
22import * as lsProtocol from 'vscode-languageserver-protocol' ;
3+ import { Menu } from '@phosphor/widgets' ;
34import { PositionConverter } from '../../../converter' ;
45import { IVirtualPosition } from '../../../positioning' ;
56import { diagnosticSeverityNames } from '../../../lsp' ;
67import { DefaultMap } from '../../../utils' ;
78import { CodeMirrorLSPFeature , IFeatureCommand } from '../feature' ;
89import { MainAreaWidget } from '@jupyterlab/apputils' ;
910import {
11+ DIAGNOSTICS_LISTING_CLASS ,
1012 DiagnosticsDatabase ,
1113 DiagnosticsListing ,
1214 IEditorDiagnostic
@@ -21,6 +23,7 @@ const default_severity = 2;
2123class DiagnosticsPanel {
2224 content : DiagnosticsListing ;
2325 widget : MainAreaWidget < DiagnosticsListing > ;
26+ is_registered = false ;
2427
2528 constructor ( ) {
2629 this . widget = this . init_widget ( ) ;
@@ -57,6 +60,8 @@ export const diagnostics_databases = new Map<
5760 DiagnosticsDatabase
5861> ( ) ;
5962
63+ const CMD_COLUMN_VISIBILITY = 'lsp-set-column-visibility' ;
64+
6065export class Diagnostics extends CodeMirrorLSPFeature {
6166 name = 'Diagnostics' ;
6267
@@ -69,6 +74,44 @@ export class Diagnostics extends CodeMirrorLSPFeature {
6974
7075 let panel_widget = diagnostics_panel . widget ;
7176
77+ let get_column = ( name : string ) => {
78+ // TODO: a hashmap in the panel itself?
79+ for ( let column of panel_widget . content . columns ) {
80+ if ( column . name === name ) {
81+ return column ;
82+ }
83+ }
84+ } ;
85+
86+ if ( ! diagnostics_panel . is_registered ) {
87+ let columns_menu = new Menu ( { commands : app . commands } ) ;
88+ app . commands . addCommand ( CMD_COLUMN_VISIBILITY , {
89+ execute : args => {
90+ let column = get_column ( args [ 'name' ] as string ) ;
91+ column . is_visible = ! column . is_visible ;
92+ panel_widget . update ( ) ;
93+ } ,
94+ label : args => args [ 'name' ] as string ,
95+ isToggled : args => {
96+ let column = get_column ( args [ 'name' ] as string ) ;
97+ return column . is_visible ;
98+ }
99+ } ) ;
100+ columns_menu . title . label = 'Panel columns' ;
101+ for ( let column of panel_widget . content . columns ) {
102+ columns_menu . addItem ( {
103+ command : CMD_COLUMN_VISIBILITY ,
104+ args : { name : column . name }
105+ } ) ;
106+ }
107+ app . contextMenu . addItem ( {
108+ selector : '.' + DIAGNOSTICS_LISTING_CLASS + ' th' ,
109+ submenu : columns_menu ,
110+ type : 'submenu'
111+ } ) ;
112+ diagnostics_panel . is_registered = true ;
113+ }
114+
72115 if ( ! panel_widget . isAttached ) {
73116 app . shell . add ( panel_widget , 'main' ) ;
74117 }
0 commit comments