-
-
Notifications
You must be signed in to change notification settings - Fork 213
/
annotations.ts
74 lines (67 loc) · 2.26 KB
/
annotations.ts
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import * as vscode from 'vscode';
const evalResultsDecorationType = vscode.window.createTextEditorDecorationType({
before: {
textDecoration: 'none',
fontWeight: 'normal',
fontStyle: 'normal',
},
rangeBehavior: vscode.DecorationRangeBehavior.ClosedOpen
});
function evaluated(contentText, hasError) {
return {
renderOptions: {
before: {
contentText: contentText,
},
light: {
before: {
color: hasError ? 'rgb(255, 127, 127)' : 'black',
backgroundColor: 'white',
},
},
dark: {
before: {
color: hasError ? 'rgb(255, 175, 175)' : 'white',
backgroundColor: 'black',
}
},
},
}
}
const evalSelectionDecorationType = vscode.window.createTextEditorDecorationType({
overviewRulerColor: 'blue',
backgroundColor: 'rgba(255, 255, 20, 0.1)',
overviewRulerLane: vscode.OverviewRulerLane.Right,
});
function clearEvaluationDecorations(editor) {
editor.setDecorations(evalResultsDecorationType, []);
editor.setDecorations(evalSelectionDecorationType, []);
}
function decorateResults(resultString, hasError, codeSelection, editor) {
let decoration = evaluated(resultString, hasError)
decoration["range"] = new vscode.Selection(codeSelection.end, codeSelection.end);
editor.setDecorations(evalResultsDecorationType, [decoration]);
setTimeout(() => {
let subscription = vscode.window.onDidChangeTextEditorSelection(() => {
subscription.dispose();
editor.setDecorations(evalResultsDecorationType, []);
});
}, 350);
}
function decorateSelection(codeSelection, editor) {
editor.setDecorations(evalSelectionDecorationType, [{ range: codeSelection }]);
setTimeout(() => {
let subscription = vscode.window.onDidChangeTextEditorSelection(() => {
subscription.dispose();
editor.setDecorations(evalSelectionDecorationType, []);
});
}, 350);
}
export default {
evalResultsDecorationType,
evaluated,
evalSelectionDecorationType,
clearEvaluationDecorations,
decorateResults,
decorateSelection
};