-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextension.js
57 lines (48 loc) · 1.61 KB
/
extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const vscode = require('vscode');
const BASE_PATH = `${vscode.extensions.getExtension('IgorSbitnev.error-gutters').extensionPath}/img/`;
const MIN_SEVERITY = 3;
const ICON_SIZE = '80%';
const ICON_PATHS = [
'error-inverse.svg',
'warning-inverse.svg',
'info-inverse.svg',
'info-inverse.svg',
];
const createIcon = iconPath => vscode
.window
.createTextEditorDecorationType({
gutterIconPath: `${BASE_PATH}${iconPath}`,
gutterIconSize: ICON_SIZE,
});
const icons = ICON_PATHS.map(createIcon);
const withDefault = (fallback, value = fallback) => value;
const withPath = path => ([file]) => file.path === path;
const withSeverity = severity => ([, target]) => target === severity;
const toRange = ([line]) => ({ range: new vscode.Range(line, 0, line, 0) });
const getIssues = diagnostics => diagnostics
.reduce((map, { severity, range: { start: { line } } }) => map
.set(
line, Math.min(severity, withDefault(MIN_SEVERITY, map.get(line))),
), new Map());
const checkFile = () => {
const editor = vscode.window.activeTextEditor;
if (!editor) return;
const [, diagnostics] = vscode
.languages
.getDiagnostics()
.find(withPath(editor.document.uri.path)) || [];
if (!diagnostics) return;
const issues = [...getIssues(diagnostics)];
icons.map((icon, iconSeverity) => editor
.setDecorations(icon, issues
.filter(withSeverity(iconSeverity))
.map(toRange)));
};
const activate = context => context
.subscriptions
.push(vscode
.languages
.onDidChangeDiagnostics(checkFile));
const deactivate = () => {};
exports.activate = activate;
exports.deactivate = deactivate;