author | wenzelm |
Fri, 03 Mar 2017 23:21:24 +0100 | |
changeset 65098 | b47ba1778e44 |
parent 65097 | ed2e33653438 |
child 65104 | 66b19d05dcee |
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 |
||
10 |
export interface Decorations |
|
11 |
{ |
|
65095 | 12 |
bad: TextEditorDecorationType |
65094 | 13 |
} |
14 |
||
65098
b47ba1778e44
evade odd version conflicts for batch build (e.g. "vsce package");
wenzelm
parents:
65097
diff
changeset
|
15 |
export let types: Decorations |
65094 | 16 |
|
17 |
export function init(context: ExtensionContext) |
|
18 |
{ |
|
19 |
function decoration(options: DecorationRenderOptions): TextEditorDecorationType |
|
20 |
{ |
|
21 |
const typ = vscode.window.createTextEditorDecorationType(options) |
|
22 |
context.subscriptions.push(typ) |
|
23 |
return typ |
|
24 |
} |
|
25 |
||
26 |
if (!types) |
|
27 |
types = |
|
28 |
{ |
|
65095 | 29 |
bad: decoration({ backgroundColor: 'rgba(255, 106, 106, 0.4)' }) |
65094 | 30 |
} |
31 |
} |
|
32 |
||
33 |
||
34 |
/* decoration for document node */ |
|
35 |
||
36 |
export interface Decoration |
|
37 |
{ |
|
38 |
uri: string, |
|
39 |
"type": string, |
|
40 |
content: DecorationOptions[] |
|
41 |
} |
|
42 |
||
43 |
export function apply(decoration: Decoration) |
|
44 |
{ |
|
45 |
let typ = types[decoration.type] |
|
46 |
if (typ) { |
|
65097 | 47 |
let uri = Uri.parse(decoration.uri).toString() |
65094 | 48 |
let editor = |
49 |
vscode.window.visibleTextEditors.find( |
|
65097 | 50 |
function (editor) { return uri == editor.document.uri.toString() }) |
65094 | 51 |
if (editor) editor.setDecorations(typ, decoration.content) |
52 |
} |
|
53 |
} |