author | wenzelm |
Sun, 05 Mar 2017 22:32:33 +0100 | |
changeset 65122 | 1edb570f5b17 |
parent 65106 | a57794dbe0af |
child 65134 | 511bf19348d3 |
permissions | -rw-r--r-- |
65094 | 1 |
'use strict'; |
2 |
||
3 |
import * as vscode from 'vscode' |
|
4 |
import { Range, MarkedString, DecorationOptions, DecorationRenderOptions, |
|
5 |
TextEditorDecorationType, ExtensionContext, Uri } from 'vscode' |
|
6 |
||
7 |
||
8 |
/* known decoration types */ |
|
9 |
||
65104
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
10 |
export const types = new Map<string, TextEditorDecorationType>() |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
11 |
|
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
12 |
const background_colors = [ |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
13 |
"unprocessed1", |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
14 |
"running1", |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
15 |
"bad", |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
16 |
"intensify", |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
17 |
"entity", |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
18 |
"quoted", |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
19 |
"antiquoted", |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
20 |
"active", |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
21 |
"active_result", |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
22 |
"markdown_item1", |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
23 |
"markdown_item2", |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
24 |
"markdown_item3", |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
25 |
"markdown_item4" |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
26 |
] |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
27 |
|
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
28 |
const foreground_colors = [ |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
29 |
"quoted", |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
30 |
"antiquoted" |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
31 |
] |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
32 |
|
65122
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65106
diff
changeset
|
33 |
const dotted_colors = [ |
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65106
diff
changeset
|
34 |
"writeln", |
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65106
diff
changeset
|
35 |
"information" |
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65106
diff
changeset
|
36 |
] |
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65106
diff
changeset
|
37 |
|
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65106
diff
changeset
|
38 |
function get_color(color: string, light: boolean): string |
65094 | 39 |
{ |
65122
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65106
diff
changeset
|
40 |
const config = color.concat(light ? "_light" : "_dark").concat("_color") |
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65106
diff
changeset
|
41 |
return vscode.workspace.getConfiguration("isabelle").get<string>(config) |
65094 | 42 |
} |
43 |
||
44 |
export function init(context: ExtensionContext) |
|
45 |
{ |
|
46 |
function decoration(options: DecorationRenderOptions): TextEditorDecorationType |
|
47 |
{ |
|
48 |
const typ = vscode.window.createTextEditorDecorationType(options) |
|
49 |
context.subscriptions.push(typ) |
|
50 |
return typ |
|
51 |
} |
|
52 |
||
65104
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
53 |
function background(color: string): TextEditorDecorationType |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
54 |
{ |
65122
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65106
diff
changeset
|
55 |
return decoration( |
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65106
diff
changeset
|
56 |
{ light: { backgroundColor: get_color(color, true) }, |
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65106
diff
changeset
|
57 |
dark: { backgroundColor: get_color(color, false) } }) |
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65106
diff
changeset
|
58 |
} |
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65106
diff
changeset
|
59 |
|
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65106
diff
changeset
|
60 |
function dotted(color: string): TextEditorDecorationType |
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65106
diff
changeset
|
61 |
{ |
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65106
diff
changeset
|
62 |
const border = "2px none; border-bottom-style: dotted; border-color: " |
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65106
diff
changeset
|
63 |
return decoration( |
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65106
diff
changeset
|
64 |
{ light: { border: border.concat(get_color(color, true)) }, |
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65106
diff
changeset
|
65 |
dark: { border: border.concat(get_color(color, false)) } }) |
65104
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
66 |
} |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
67 |
|
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
68 |
types.clear |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
69 |
for (let color of background_colors) { |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
70 |
types["background_".concat(color)] = background(color) |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
71 |
} |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
72 |
for (let color of foreground_colors) { |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
73 |
types["foreground_".concat(color)] = background(color) // approximation |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
74 |
} |
65122
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65106
diff
changeset
|
75 |
for (let color of dotted_colors) { |
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65106
diff
changeset
|
76 |
types["dotted_".concat(color)] = dotted(color) |
1edb570f5b17
decorations for dotted underline: less intrusive;
wenzelm
parents:
65106
diff
changeset
|
77 |
} |
65106
a57794dbe0af
more general hover_message (see also JEdit_Rendering.tooltip_message);
wenzelm
parents:
65104
diff
changeset
|
78 |
types["hover_message"] = decoration({}) |
65094 | 79 |
} |
80 |
||
81 |
||
82 |
/* decoration for document node */ |
|
83 |
||
84 |
export interface Decoration |
|
85 |
{ |
|
86 |
uri: string, |
|
87 |
"type": string, |
|
88 |
content: DecorationOptions[] |
|
89 |
} |
|
90 |
||
91 |
export function apply(decoration: Decoration) |
|
92 |
{ |
|
93 |
let typ = types[decoration.type] |
|
94 |
if (typ) { |
|
65097 | 95 |
let uri = Uri.parse(decoration.uri).toString() |
65094 | 96 |
let editor = |
97 |
vscode.window.visibleTextEditors.find( |
|
65097 | 98 |
function (editor) { return uri == editor.document.uri.toString() }) |
65094 | 99 |
if (editor) editor.setDecorations(typ, decoration.content) |
100 |
} |
|
101 |
} |