Skip to content

Commit 1c70b3b

Browse files
authored
Merge pull request #159 from krassowski/diagnostics/hide_columns
Allow to hide chosen columns in diagnostics panel
2 parents 211716b + 9620a3e commit 1c70b3b

File tree

8 files changed

+239
-96
lines changed

8 files changed

+239
-96
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# CHANGELOG
22

3+
## `@krassowski/jupyterlab-lsp 0.7.1` (unreleased)
4+
5+
- features
6+
7+
- users can now choose which columns to display/hide
8+
in the diagnostic panel, using a context menu action (
9+
[#159](https://github.com/krassowski/jupyterlab-lsp/pull/159)
10+
)
11+
312
## `lsp-ws-connection 0.3.1`
413

514
- added `sendSaved()` method (textDocument/didSave) (

atest/01_Editor.robot

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,6 @@ Measure Cursor Position
112112
${position} = Wait Until Keyword Succeeds 20 x 0.05s Get Vertical Position ${CM CURSOR}
113113
[Return] ${position}
114114

115-
Open Context Menu Over
116-
[Arguments] ${sel}
117-
Wait Until Keyword Succeeds 10 x 0.1 s Mouse Over ${sel}
118-
Wait Until Keyword Succeeds 10 x 0.1 s Click Element ${sel}
119-
Wait Until Keyword Succeeds 10 x 0.1 s Open Context Menu ${sel}
120-
121115
Get Editor Content
122116
${content} Execute JavaScript return document.querySelector('.CodeMirror').CodeMirror.getValue()
123117
[Return] ${content}

atest/04_Interface/DiagnosticsPanel.robot

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ Resource ../Keywords.robot
55
*** Variables ***
66
${EXPECTED_COUNT} 1
77
${DIAGNOSTIC} W291 trailing whitespace (pycodestyle)
8+
${DIAGNOSTIC MESSAGE} trailing whitespace
9+
${MENU COLUMNS} xpath://div[contains(@class, 'p-Menu-itemLabel')][contains(text(), "columns")]
10+
${MENU COLUMN MESSAGE} xpath://div[contains(@class, 'p-Menu-itemLabel')][contains(text(), "Message")]
811

912
*** Test Cases ***
1013
Diagnostics Panel Opens
@@ -36,6 +39,21 @@ Diagnostics Panel Can Be Restored
3639
Wait Until Keyword Succeeds 10 x 1s Should Have Expected Rows Count
3740
[Teardown] Clean Up After Working With File Panel.ipynb
3841

42+
Columns Can Be Hidden
43+
[Setup] Gently Reset Workspace
44+
Open Notebook And Panel Panel.ipynb
45+
Wait Until Keyword Succeeds 10 x 1s Element Should Contain ${DIAGNOSTICS PANEL} ${DIAGNOSTIC MESSAGE}
46+
Open Context Menu Over css:.lsp-diagnostics-listing th
47+
Capture Page Screenshot 01-menu-visible.png
48+
Mouse Over ${MENU COLUMNS}
49+
Wait Until Page Contains Element ${MENU COLUMN MESSAGE} timeout=10s
50+
Mouse Over ${MENU COLUMN MESSAGE}
51+
Capture Page Screenshot 02-message-column-visible.png
52+
Click Element ${MENU COLUMN MESSAGE}
53+
Capture Page Screenshot 03-message-column-toggled.png
54+
Wait Until Keyword Succeeds 10 x 1s Element Should Not Contain ${DIAGNOSTICS PANEL} ${DIAGNOSTIC MESSAGE}
55+
[Teardown] Clean Up After Working With File Panel.ipynb
56+
3957
*** Keywords ***
4058
Open Notebook And Panel
4159
[Arguments] ${notebook}

atest/Keywords.robot

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,9 @@ Enter Cell Editor
203203

204204
Wait Until Fully Initialized
205205
Wait Until Element Contains ${STATUSBAR} Fully initialized timeout=35s
206+
207+
Open Context Menu Over
208+
[Arguments] ${sel}
209+
Wait Until Keyword Succeeds 10 x 0.1 s Mouse Over ${sel}
210+
Wait Until Keyword Succeeds 10 x 0.1 s Click Element ${sel}
211+
Wait Until Keyword Succeeds 10 x 0.1 s Open Context Menu ${sel}

packages/jupyterlab-lsp/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"@jupyterlab/testutils": "^1.2.2",
6161
"@jupyterlab/tooltip": "^1.1",
6262
"@phosphor/algorithm": "*",
63+
"@phosphor/widgets": "*",
6364
"@types/chai": "^4.1.7",
6465
"@types/codemirror": "^0.0.74",
6566
"@types/events": "^3.0.0",
@@ -93,6 +94,7 @@
9394
"@jupyterlab/testutils": "^1.2.2",
9495
"@jupyterlab/tooltip": "^1.1",
9596
"@phosphor/algorithm": "*",
97+
"@phosphor/widgets": "*",
9698
"codemirror": "*",
9799
"react": "*"
98100
},

packages/jupyterlab-lsp/src/adapters/codemirror/features/diagnostics.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import * as CodeMirror from 'codemirror';
22
import * as lsProtocol from 'vscode-languageserver-protocol';
3+
import { Menu } from '@phosphor/widgets';
34
import { PositionConverter } from '../../../converter';
45
import { IVirtualPosition } from '../../../positioning';
56
import { diagnosticSeverityNames } from '../../../lsp';
67
import { DefaultMap } from '../../../utils';
78
import { CodeMirrorLSPFeature, IFeatureCommand } from '../feature';
89
import { MainAreaWidget } from '@jupyterlab/apputils';
910
import {
11+
DIAGNOSTICS_LISTING_CLASS,
1012
DiagnosticsDatabase,
1113
DiagnosticsListing,
1214
IEditorDiagnostic
@@ -21,6 +23,7 @@ const default_severity = 2;
2123
class 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+
6065
export 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

Comments
 (0)