This repository has been archived by the owner on Jun 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextension.js
56 lines (49 loc) · 2.44 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
const vscode = require('vscode');
const { exec } = require('child_process');
function activate(context) {
console.log('"kombustion-vscode" has loaded');
["plaintext","yaml","json"].forEach(lang => {
vscode.languages.registerCompletionItemProvider(lang, {
provideCompletionItems(document, position, token, context) {
if (document.lineAt(position.line).text.trim().startsWith("Type:")) {
return new Promise((resolve, reject) => {
exec('kombustion-vs-helper', (err, stdout, stderr) => {
if (err) {
deactivate();
reject(err);
return;
}
let returnedCompletionItems = [];
let doc = JSON.parse(stdout);
doc.forEach(typ => {
let item = new vscode.CompletionItem(typ.Name, vscode.CompletionItemKind.Snippet);
let insertStr = typ.Name + "\nProperties:\n";
let i = 1;
typ.Fields.forEach(field => {
if (isNaN(parseInt(field.ExampleValue))) {
insertStr += "\t" + field.Name + ": \"${" + i + ":" + field.ExampleValue + "}\"\n";
} else {
insertStr += "\t" + field.Name + ": ${" + i + ":" + field.ExampleValue + "}\n";
}
// TODO: Children
i++;
});
item.insertText = new vscode.SnippetString(insertStr);
item.documentation = new vscode.MarkdownString(typ.Description);
returnedCompletionItems.push(item);
});
resolve(returnedCompletionItems);
});
exec();
});
}
return [];
}
});
});
}
exports.activate = activate;
function deactivate() {
console.log('"kombustion-vscode" has been deactivated');
}
exports.deactivate = deactivate;