Skip to content

Commit 373f887

Browse files
authored
Merge pull request #940 from krassowski/ignoreseverities
Add `ignoreSeverities` setting
2 parents fee5ce6 + 57bed7d commit 373f887

File tree

3 files changed

+65
-15
lines changed

3 files changed

+65
-15
lines changed

packages/jupyterlab-lsp/schema/diagnostics.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@
3030
"default": [],
3131
"description": "Regular expressions matching messages of diagnostics which should not be shown in the panel nor highlighted in the editor."
3232
},
33+
"ignoreSeverities": {
34+
"title": "Diagnostic severity levels to ignore",
35+
"type": "array",
36+
"items": {
37+
"type": "string",
38+
"enum": ["Error", "Warning", "Information", "Hint"]
39+
},
40+
"default": [],
41+
"uniqueItems": true,
42+
"description": "Severities of diagnostics which should not be shown in the panel nor highlighted in the editor."
43+
},
3344
"disable": {
3445
"title": "Disable",
3546
"type": "boolean",

packages/jupyterlab-lsp/src/features/diagnostics/diagnostics.spec.ts

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,24 @@ import {
1212
set_notebook_content,
1313
showAllCells
1414
} from '../../editor_integration/testutils';
15+
import { DiagnosticSeverity } from '../../lsp';
1516
import { is_equal } from '../../positioning';
1617
import { foreign_code_extractors } from '../../transclusions/ipython/extractors';
1718

1819
import { DiagnosticsCM, diagnostics_panel } from './diagnostics';
1920
import { message_without_code } from './listing';
2021

22+
const SETTING_DEFAULTS: LSPDiagnosticsSettings = {
23+
ignoreCodes: [],
24+
ignoreMessagesPatterns: [],
25+
ignoreSeverities: [],
26+
defaultSeverity: 'Warning'
27+
};
28+
2129
describe('Diagnostics', () => {
2230
let feature: DiagnosticsCM;
23-
let default_settings = new MockSettings<LSPDiagnosticsSettings>({
24-
defaultSeverity: 'Warning',
25-
ignoreCodes: [],
26-
ignoreMessagesPatterns: []
31+
let defaultSettings = new MockSettings<LSPDiagnosticsSettings>({
32+
...SETTING_DEFAULTS
2733
});
2834

2935
describe('FileEditor integration', () => {
@@ -34,7 +40,7 @@ describe('Diagnostics', () => {
3440
feature = env.init_integration({
3541
constructor: DiagnosticsCM,
3642
id: 'Diagnostics',
37-
settings: default_settings
43+
settings: defaultSettings
3844
});
3945
});
4046
afterEach(() => {
@@ -47,22 +53,24 @@ describe('Diagnostics', () => {
4753
expect(feature.is_registered).to.equal(true);
4854
});
4955

50-
const diagnostics = [
56+
const diagnostics: lsProtocol.Diagnostic[] = [
5157
{
5258
range: {
5359
start: { line: 0, character: 7 },
5460
end: { line: 0, character: 9 }
5561
},
5662
message: 'Undefined symbol "aa"',
57-
code: 'E001'
63+
code: 'E001',
64+
severity: DiagnosticSeverity['Error']
5865
},
5966
{
6067
range: {
6168
start: { line: 1, character: 3 },
6269
end: { line: 1, character: 4 }
6370
},
6471
message: 'Trimming whitespace',
65-
code: 'W001'
72+
code: 'W001',
73+
severity: DiagnosticSeverity['Warning']
6674
}
6775
];
6876

@@ -91,9 +99,32 @@ describe('Diagnostics', () => {
9199
constructor: DiagnosticsCM,
92100
id: 'Diagnostics',
93101
settings: new MockSettings({
94-
defaultSeverity: 'Warning',
95-
ignoreCodes: ['W001'],
96-
ignoreMessagesPatterns: []
102+
...SETTING_DEFAULTS,
103+
ignoreCodes: ['W001']
104+
})
105+
});
106+
env.ce_editor.model.value.text = text;
107+
await env.adapter.update_documents();
108+
109+
feature.handleDiagnostic(null as any, {
110+
uri: env.document_options.path,
111+
diagnostics: diagnostics
112+
});
113+
114+
let markers = env.ce_editor.editor.getDoc().getAllMarks();
115+
expect(markers.length).to.equal(1);
116+
expect((markers[0] as TextMarkerOptions).title).to.equal(
117+
'Undefined symbol "aa"'
118+
);
119+
});
120+
121+
it('filters out inspections by severity', async () => {
122+
feature = env.init_integration({
123+
constructor: DiagnosticsCM,
124+
id: 'Diagnostics',
125+
settings: new MockSettings({
126+
...SETTING_DEFAULTS,
127+
ignoreSeverities: ['Warning']
97128
})
98129
});
99130
env.ce_editor.model.value.text = text;
@@ -116,8 +147,7 @@ describe('Diagnostics', () => {
116147
constructor: DiagnosticsCM,
117148
id: 'Diagnostics',
118149
settings: new MockSettings({
119-
defaultSeverity: 'Warning',
120-
ignoreCodes: [],
150+
...SETTING_DEFAULTS,
121151
ignoreMessagesPatterns: ['Undefined symbol "\\w+"']
122152
})
123153
});
@@ -148,7 +178,7 @@ describe('Diagnostics', () => {
148178
feature = env.init_integration({
149179
constructor: DiagnosticsCM,
150180
id: 'Diagnostics',
151-
settings: default_settings
181+
settings: defaultSettings
152182
});
153183
});
154184
afterEach(() => {
@@ -266,7 +296,7 @@ describe('Diagnostics', () => {
266296
constructor: DiagnosticsCM,
267297
id: 'Diagnostics',
268298
document: foreign_document,
269-
settings: default_settings
299+
settings: defaultSettings
270300
});
271301

272302
let response = {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,11 @@ export class DiagnosticsCM extends CodeMirrorIntegration {
445445
const ignoredDiagnosticsCodes = new Set(
446446
this.settings.composite.ignoreCodes
447447
);
448+
const ignoredSeverities = new Set<number>(
449+
this.settings.composite.ignoreSeverities.map(
450+
severityName => DiagnosticSeverity[severityName]
451+
)
452+
);
448453
const ignoredMessagesRegExp =
449454
this.settings.composite.ignoreMessagesPatterns.map(
450455
pattern => new RegExp(pattern)
@@ -464,6 +469,10 @@ export class DiagnosticsCM extends CodeMirrorIntegration {
464469
) {
465470
return false;
466471
}
472+
let severity = diagnostic.severity;
473+
if (severity && ignoredSeverities.has(severity)) {
474+
return false;
475+
}
467476
let message = diagnostic.message;
468477
if (
469478
message &&

0 commit comments

Comments
 (0)