Skip to content

Commit 6bf1b2b

Browse files
authored
Merge pull request #261 from krassowski/interface/diagnostics_panel/fix-caret-icons
Fix caret icon in diagnostics panel (port to JupyterLab 2.0) #258
2 parents 38521c4 + bd90578 commit 6bf1b2b

File tree

9 files changed

+181
-43
lines changed

9 files changed

+181
-43
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
- fixes currently-highlighted token in dark editor themes against light lab theme
88
(and vice versa) ([#195][])
9+
- restores sorting order-indicating caret icons in diagnostics panel table ([#261][])
910

1011
[#195]: https://github.com/krassowski/jupyterlab-lsp/issues/195
12+
[#261]: https://github.com/krassowski/jupyterlab-lsp/issues/261
1113

1214
### `@krassowski/jupyterlab-lsp 1.0.0` (2020-03-14)
1315

packages/jupyterlab-lsp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"license": "BSD-3-Clause",
2020
"author": "Michał Krassowski",
2121
"files": [
22-
"{lib,style,schema,src}/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf,css,json,ts,tsx}"
22+
"{lib,style,schema,src}/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf,css,json,ts,tsx,txt,md}"
2323
],
2424
"main": "lib/index.js",
2525
"types": "lib/index.d.ts",

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
DIAGNOSTICS_LISTING_CLASS,
1212
DiagnosticsDatabase,
1313
DiagnosticsListing,
14-
IEditorDiagnostic
14+
IEditorDiagnostic,
15+
diagnosticsIcon
1516
} from './diagnostics_listing';
1617
import { VirtualDocument } from '../../../virtual/document';
1718
import { VirtualEditor } from '../../../virtual/editor';
@@ -46,6 +47,7 @@ class DiagnosticsPanel {
4647
widget.id = 'lsp-diagnostics-panel';
4748
widget.title.label = 'Diagnostics Panel';
4849
widget.title.closable = true;
50+
widget.title.icon = diagnosticsIcon;
4951
return widget;
5052
}
5153

packages/jupyterlab-lsp/src/adapters/codemirror/features/diagnostics_listing.tsx

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { ReactElement } from 'react';
22
import { VDomModel, VDomRenderer } from '@jupyterlab/apputils';
3+
import { caretDownIcon, caretUpIcon, LabIcon } from '@jupyterlab/ui-components';
34
import * as lsProtocol from 'vscode-languageserver-protocol';
45
import * as CodeMirror from 'codemirror';
56
import { IEditorPosition } from '../../../positioning';
@@ -12,6 +13,13 @@ import { Cell } from '@jupyterlab/cells';
1213
import { diagnosticSeverityNames } from '../../../lsp';
1314
import { message_without_code } from './diagnostics';
1415

16+
import diagnosticsSvg from '../../../../style/icons/diagnostics.svg';
17+
18+
export const diagnosticsIcon = new LabIcon({
19+
name: 'lsp:diagnostics',
20+
svgstr: diagnosticsSvg
21+
});
22+
1523
/**
1624
* Diagnostic which is localized at a specific editor (cell) within a notebook
1725
* (if used in the context of a FileEditor, then there is just a single editor)
@@ -161,19 +169,20 @@ class Column {
161169

162170
function SortableTH(props: { name: string; listing: DiagnosticsListing }): any {
163171
const is_sort_key = props.name === props.listing.sort_key;
172+
const sortIcon =
173+
!is_sort_key || props.listing.sort_direction === 1
174+
? caretUpIcon
175+
: caretDownIcon;
164176
return (
165177
<th
166178
key={props.name}
167179
onClick={() => props.listing.sort(props.name)}
168-
className={
169-
is_sort_key
170-
? 'lsp-sorted ' +
171-
(props.listing.sort_direction === 1 ? 'lsp-descending' : '')
172-
: ''
173-
}
180+
className={is_sort_key ? 'lsp-sorted-header' : null}
174181
>
175-
{props.name}
176-
{is_sort_key ? <span className={'lsp-caret'} /> : null}
182+
<div>
183+
<label>{props.name}</label>
184+
<sortIcon.react tag="span" className="lsp-sort-icon" />
185+
</div>
177186
</th>
178187
);
179188
}
@@ -230,19 +239,29 @@ export class DiagnosticsListing extends VDomRenderer<DiagnosticsListing.Model> {
230239
new Column({
231240
name: 'Cell',
232241
render_cell: row => <td key={5}>{row.cell_number}</td>,
233-
sort: (a, b) => (a.cell_number > b.cell_number ? 1 : -1),
242+
sort: (a, b) =>
243+
a.cell_number > b.cell_number
244+
? 1
245+
: a.data.range.start.line > b.data.range.start.line
246+
? 1
247+
: a.data.range.start.ch > b.data.range.start.ch
248+
? 1
249+
: -1,
234250
is_available: context => context.editor.has_cells
235251
}),
236252
new Column({
237-
name: 'Line',
238-
render_cell: row => <td key={6}>{row.data.range.start.line}</td>,
253+
name: 'Line:Ch',
254+
render_cell: row => (
255+
<td key={6}>
256+
{row.data.range.start.line}:{row.data.range.start.ch}
257+
</td>
258+
),
239259
sort: (a, b) =>
240-
a.data.range.start.line > b.data.range.start.line ? 1 : -1
241-
}),
242-
new Column({
243-
name: 'Ch',
244-
render_cell: row => <td key={7}>{row.data.range.start.line}</td>,
245-
sort: (a, b) => (a.data.range.start.ch > b.data.range.start.ch ? 1 : -1)
260+
a.data.range.start.line > b.data.range.start.line
261+
? 1
262+
: a.data.range.start.ch > b.data.range.start.ch
263+
? 1
264+
: -1
246265
})
247266
];
248267

packages/jupyterlab-lsp/src/typings.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
// Distributed under the terms of the Modified BSD License.
33

44
/// <reference path="../typings/codemirror/codemirror.d.ts"/>
5+
6+
declare module '*.svg' {
7+
const script: string;
8+
export default script;
9+
}

packages/jupyterlab-lsp/style/diagnostics_listing.css

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@
1919
overflow-x: hidden;
2020
}
2121

22+
.lsp-diagnostics-listing th,
23+
.lsp-diagnostics-listing td {
24+
padding: 4px 12px 2px 12px;
25+
height: 18px;
26+
}
27+
2228
.lsp-diagnostics-listing th {
23-
padding: 4px 12px;
2429
font-weight: 500;
2530
text-align: left;
2631
border-bottom: var(--jp-border-width) solid var(--jp-border-color1);
@@ -44,37 +49,35 @@
4449
content: ' > ';
4550
}
4651

47-
.lsp-diagnostics-listing td:first-child,
48-
.lsp-diagnostics-listing td:last-child {
49-
padding: 4px 12px;
52+
.lsp-diagnostics-listing tbody tr:hover {
53+
background: var(--jp-layout-color2);
54+
}
55+
56+
.lsp-diagnostics-listing thead th > div {
57+
flex-direction: row;
58+
display: flex;
5059
}
5160

52-
.lsp-diagnostics-listing tbody td:not(:first-child):not(:last-child) {
53-
padding: 4px 2px;
61+
.lsp-diagnostics-listing thead th > div > label {
62+
flex: 1;
63+
text-overflow: ellipsis;
5464
}
5565

56-
.lsp-diagnostics-listing tbody tr:hover {
57-
background: var(--jp-layout-color2);
66+
.lsp-sort-icon {
67+
flex: 0;
68+
height: var(--jp-ui-font-size1);
69+
width: var(--jp-ui-font-size1);
5870
}
5971

60-
.lsp-sort-caret {
61-
height: 16px;
62-
width: 16px;
63-
background-size: 18px;
64-
background-image: 18px;
65-
background-repeat: no-repeat;
66-
background-position: center;
67-
display: inline-block;
68-
position: relative;
69-
top: 3px;
72+
.lsp-sort-icon svg {
73+
display: inline;
74+
height: auto;
7075
}
7176

72-
.lsp-sorted .lsp-caret {
73-
background-image: var(--jp-icon-caretup);
74-
margin-top: -4px;
75-
left: 3px;
77+
.lsp-diagnostics-listing thead th:not(.lsp-sorted-header) .lsp-sort-icon {
78+
opacity: 0;
7679
}
7780

78-
.lsp-sorted.lsp-descending .lsp-caret {
79-
background-image: var(--jp-icon-caretdown);
81+
.lsp-diagnostics-listing thead th:not(.lsp-sorted-header):hover .lsp-sort-icon {
82+
opacity: 0.5;
8083
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
Copyright (c) 2014, Austin Andrews (http://materialdesignicons.com/),
2+
with Reserved Font Name Material Design Icons.
3+
Copyright (c) 2014, Google (http://www.google.com/design/)
4+
uses the license at https://github.com/google/material-design-icons/blob/master/LICENSE
5+
6+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
7+
This license is copied below, and is also available with a FAQ at:
8+
http://scripts.sil.org/OFL
9+
10+
11+
-----------------------------------------------------------
12+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
13+
-----------------------------------------------------------
14+
15+
PREAMBLE
16+
The goals of the Open Font License (OFL) are to stimulate worldwide
17+
development of collaborative font projects, to support the font creation
18+
efforts of academic and linguistic communities, and to provide a free and
19+
open framework in which fonts may be shared and improved in partnership
20+
with others.
21+
22+
The OFL allows the licensed fonts to be used, studied, modified and
23+
redistributed freely as long as they are not sold by themselves. The
24+
fonts, including any derivative works, can be bundled, embedded,
25+
redistributed and/or sold with any software provided that any reserved
26+
names are not used by derivative works. The fonts and derivatives,
27+
however, cannot be released under any other type of license. The
28+
requirement for fonts to remain under this license does not apply
29+
to any document created using the fonts or their derivatives.
30+
31+
DEFINITIONS
32+
"Font Software" refers to the set of files released by the Copyright
33+
Holder(s) under this license and clearly marked as such. This may
34+
include source files, build scripts and documentation.
35+
36+
"Reserved Font Name" refers to any names specified as such after the
37+
copyright statement(s).
38+
39+
"Original Version" refers to the collection of Font Software components as
40+
distributed by the Copyright Holder(s).
41+
42+
"Modified Version" refers to any derivative made by adding to, deleting,
43+
or substituting -- in part or in whole -- any of the components of the
44+
Original Version, by changing formats or by porting the Font Software to a
45+
new environment.
46+
47+
"Author" refers to any designer, engineer, programmer, technical
48+
writer or other person who contributed to the Font Software.
49+
50+
PERMISSION & CONDITIONS
51+
Permission is hereby granted, free of charge, to any person obtaining
52+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
53+
redistribute, and sell modified and unmodified copies of the Font
54+
Software, subject to the following conditions:
55+
56+
1) Neither the Font Software nor any of its individual components,
57+
in Original or Modified Versions, may be sold by itself.
58+
59+
2) Original or Modified Versions of the Font Software may be bundled,
60+
redistributed and/or sold with any software, provided that each copy
61+
contains the above copyright notice and this license. These can be
62+
included either as stand-alone text files, human-readable headers or
63+
in the appropriate machine-readable metadata fields within text or
64+
binary files as long as those fields can be easily viewed by the user.
65+
66+
3) No Modified Version of the Font Software may use the Reserved Font
67+
Name(s) unless explicit written permission is granted by the corresponding
68+
Copyright Holder. This restriction only applies to the primary font name as
69+
presented to the users.
70+
71+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
72+
Software shall not be used to promote, endorse or advertise any
73+
Modified Version, except to acknowledge the contribution(s) of the
74+
Copyright Holder(s) and the Author(s) or with their explicit written
75+
permission.
76+
77+
5) The Font Software, modified or unmodified, in part or in whole,
78+
must be distributed entirely under this license, and must not be
79+
distributed under any other license. The requirement for fonts to
80+
remain under this license does not apply to any document created
81+
using the Font Software.
82+
83+
TERMINATION
84+
This license becomes null and void if any of the above conditions are
85+
not met.
86+
87+
DISCLAIMER
88+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
89+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
90+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
91+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
92+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
93+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
94+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
95+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
96+
OTHER DEALINGS IN THE FONT SOFTWARE.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
The following icons in this directory are open source, and are &copy; their
2+
respective license holders:
3+
4+
## Material Design Icons [OFL 1.1](<(./LICENSE.materialdesignicons.txt)>)
5+
6+
- [diagnostics.svg](./diagnostics.svg)
Lines changed: 5 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)