-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathui.js
56 lines (53 loc) · 1.83 KB
/
ui.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
import * as vscode from 'vscode';
export default class CoverageUI {
constructor(context) {
this.tray = vscode.window.createStatusBarItem();
this.tray.command = "ShowCoverage";
this.tray.text = "Coverage $(eye)";
this.highlight = vscode.window.createTextEditorDecorationType({
backgroundColor: 'rgba(128,64,64,0.5)',
isWholeLine: true
});
this.branch = vscode.window.createTextEditorDecorationType({
backgroundColor: 'rgba(128,128,64,0.5)',
isWholeLine: true
});
this.lineCovered = vscode.window.createTextEditorDecorationType({
backgroundColor: 'rgba(64,200,160,0.5)',
isWholeLine: true
});
this.branchCovered = vscode.window.createTextEditorDecorationType({
backgroundColor: 'rgba(64,200,160,0.5)',
isWholeLine: true
});
}
dispose() {
return vscode.Disposable.from(this.tray, this.highlight, this.branch, this.lineCovered, this.branchCovered).dispose();
}
show(editor, {skippedLines=[],coveredLines=[],skippedBranches=[],coveredBranches=[]} = {}) {
this.tray.show();
decorateLines(editor, this.highlight, skippedLines, "Line not covered");
decorateLines(editor, this.lineCovered, coveredLines, "Line covered");
decorateLines(editor, this.branch, skippedBranches, "Branch not covered");
decorateLines(editor, this.branchCovered, coveredBranches, "Branch covered");
this.tray.command = 'HideCoverage';
}
hide(editor) {
editor.setDecorations(this.highlight, []);
editor.setDecorations(this.lineCovered, []);
editor.setDecorations(this.branch, []);
editor.setDecorations(this.branchCovered, []);
this.tray.command = 'ShowCoverage';
}
}
function decorateLines(editor, style, lines, msg) {
const ranges = [];
for (const line of lines) {
const options = {
hoverMessage: msg,
range: new vscode.Range(line, 0, line, 1)
};
ranges.push(options);
}
editor.setDecorations(style, ranges);
}