author | wenzelm |
Sat, 04 Mar 2017 21:04:44 +0100 | |
changeset 65106 | a57794dbe0af |
parent 65104 | 66b19d05dcee |
child 65122 | 1edb570f5b17 |
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 |
|
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
33 |
function property(prop: string, config: string): Object |
65094 | 34 |
{ |
65104
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
35 |
let res = {} |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
36 |
res[prop] = vscode.workspace.getConfiguration("isabelle").get<string>(config) |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
37 |
return res |
65094 | 38 |
} |
39 |
||
40 |
export function init(context: ExtensionContext) |
|
41 |
{ |
|
42 |
function decoration(options: DecorationRenderOptions): TextEditorDecorationType |
|
43 |
{ |
|
44 |
const typ = vscode.window.createTextEditorDecorationType(options) |
|
45 |
context.subscriptions.push(typ) |
|
46 |
return typ |
|
47 |
} |
|
48 |
||
65104
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
49 |
function background(color: string): TextEditorDecorationType |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
50 |
{ |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
51 |
const prop = "backgroundColor" |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
52 |
const light = property(prop, color.concat("_light_color")) |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
53 |
const dark = property(prop, color.concat("_dark_color")) |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
54 |
return decoration({ light: light, dark: dark }) |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
55 |
} |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
56 |
|
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
57 |
types.clear |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
58 |
for (let color of background_colors) { |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
59 |
types["background_".concat(color)] = background(color) |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
60 |
} |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
61 |
for (let color of foreground_colors) { |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
62 |
types["foreground_".concat(color)] = background(color) // approximation |
66b19d05dcee
decorations for background and foreground colors;
wenzelm
parents:
65098
diff
changeset
|
63 |
} |
65106
a57794dbe0af
more general hover_message (see also JEdit_Rendering.tooltip_message);
wenzelm
parents:
65104
diff
changeset
|
64 |
types["hover_message"] = decoration({}) |
65094 | 65 |
} |
66 |
||
67 |
||
68 |
/* decoration for document node */ |
|
69 |
||
70 |
export interface Decoration |
|
71 |
{ |
|
72 |
uri: string, |
|
73 |
"type": string, |
|
74 |
content: DecorationOptions[] |
|
75 |
} |
|
76 |
||
77 |
export function apply(decoration: Decoration) |
|
78 |
{ |
|
79 |
let typ = types[decoration.type] |
|
80 |
if (typ) { |
|
65097 | 81 |
let uri = Uri.parse(decoration.uri).toString() |
65094 | 82 |
let editor = |
83 |
vscode.window.visibleTextEditors.find( |
|
65097 | 84 |
function (editor) { return uri == editor.document.uri.toString() }) |
65094 | 85 |
if (editor) editor.setDecorations(typ, decoration.content) |
86 |
} |
|
87 |
} |