-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathextension.ts
74 lines (57 loc) · 1.6 KB
/
extension.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';
import * as data from './properties.json';
interface Property {
syntax: string;
media: string | string[];
inherited: boolean;
animationType: string | string[];
percentages: string | string[];
groups: string[];
initial: string | string[];
appliesto: string;
computed: string | string[];
order: string;
status: string;
mdn_url?: string;
}
const properties: { [key: string]: Property } = data;
export function activate(context: vscode.ExtensionContext) {
const hoverProvider: vscode.HoverProvider = {
provideHover(doc, pos, token): vscode.ProviderResult<vscode.Hover> {
const range = doc.getWordRangeAtPosition(pos, /[a-z\-]+\s*:/ig);
if (range === undefined) {
return;
}
const initialValue = getInitialValue(doc.getText(range));
if (initialValue === undefined) {
return;
}
return new vscode.Hover(getText(initialValue));
}
};
let disposable = vscode.languages.registerHoverProvider(
['css', 'less', 'sass', 'scss'],
hoverProvider
);
context.subscriptions.push(disposable);
}
function getInitialValue(word: string): string | string[] {
return properties[word.slice(0, -1).trim()].initial;
}
function getText(initialValue: string | string[]): vscode.MarkdownString {
let value = '';
if (Array.isArray(initialValue)) {
const props = initialValue.map(item => {
return `* ${item}: \`${properties[item].initial}\``;
});
value = `
Initial value
As each of the properties:
${props.join('\n')}
`;
} else {
value = `Initial value: \`${initialValue}\``;
}
return new vscode.MarkdownString(value);
}
export function deactivate() {}