-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
99 lines (80 loc) · 3.32 KB
/
extension.js
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const vscode = require('vscode');
const ComponentNameCompletionProvider = require('./Providers/ComponentNameCompletionProvider');
const GlobalVarsCompletionProvider = require('./Providers/GlobalVarsCompletionProvider');
const DataConvertersCompletionProvider = require('./Providers/DataConvertersCompletionProvider');
const StyleNameCompletionProvider = require('./Providers/StyleNameCompletionProvider');
const { showSnippets } = require('./Providers/SnippetCommandProvider');
const { provideHover } = require('./Providers/hoverColorProvider');
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
const providers = [
new GlobalVarsCompletionProvider(),
new ComponentNameCompletionProvider(),
new DataConvertersCompletionProvider(),
new StyleNameCompletionProvider()
]
for (const provider of providers){
context.subscriptions.push(vscode.languages.registerCompletionItemProvider({ scheme: 'file', language: 'json'}, provider, '"'));
}
let disposable = vscode.commands.registerCommand('rlt-theme-helper.showSnippets', showSnippets);
context.subscriptions.push(disposable);
const myCustomIcon = "$(rlt-iconbar-A)";
const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);
statusBarItem.text = myCustomIcon;
statusBarItem.tooltip = "RLT Theme Helper is active!"
statusBarItem.show();
context.subscriptions.push(statusBarItem);
refreshStatusBarIcon(vscode.window.activeTextEditor);
vscode.window.onDidChangeActiveTextEditor((editor) => {
refreshStatusBarIcon(editor);
});
function refreshStatusBarIcon(editor){
const filePath = editor.document.uri.fsPath;
const extensionId = 'kaaac.rlt-theme-helper';
const extensionConfig = vscode.extensions.getExtension(extensionId).packageJSON.contributes;
if (extensionConfig && extensionConfig.jsonValidation) {
const jsonValidation = extensionConfig.jsonValidation;
const matchedSchema = getMatchedSchema(filePath, jsonValidation);
if (matchedSchema) {
statusBarItem.tooltip = 'This file is supported by extension!';
statusBarItem.text = '$(rlt-iconbar-G) RLT'
} else {
statusBarItem.tooltip = 'Sorry! This file is not supported by extension.\nAre you sure you sure it is correct file?';
statusBarItem.text = '$(rlt-iconbar-G)! RLT'
}
}
}
context.subscriptions.push(
vscode.languages.registerHoverProvider(
{ language: 'json', scheme: 'file'},
{ provideHover }
)
);
console.log('Congratulations, your extension "rlt-theme-helper" is now active!');
}
function getMatchedSchema(filePath, jsonValidation) {
for (const schema of jsonValidation) {
if (schema.fileMatch) {
if (Array.isArray(schema.fileMatch)) {
for (const fileMatch of schema.fileMatch) {
const regex = new RegExp(fileMatch.replace(/\//g, '[\\/\\\\]').replace(/\*{2}/g, '.*').replace(/\*{1}/g, '[^\\/\\\\]*'));
if(regex.test(filePath) == true) {return schema;}
}
} else {
const regex = new RegExp(schema.fileMatch.replace(/\//g, '[\\/\\\\]').replace(/\*{2}/g, '.*').replace(/\*{1}/g, '[^\\/\\\\]*'));
if(regex.test(filePath) == true){
return schema;
}
}
}
}
return null; // If no match found
}
// This method is called when your extension is deactivated
function deactivate() {}
module.exports = {
activate,
deactivate
}