-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhifi-vscode.js
104 lines (84 loc) · 2.68 KB
/
hifi-vscode.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
100
101
102
103
104
const fs = require('fs');
const path = require('path')
var vsCodeArray = [];
// load jsdoc
var hifiDoc = require('./hifiJSDoc.json');
// console.log("hifiDoc \n", hifiDoc);
// create VsCode mapping
function VSCodeMappingObject(name, prefix, body, description){
this.name = name;
this.prefix = prefix;
this.body = body;
this.description = description;
}
// {$1:ray: PickRay}
// iterate hifiDoc
hifiDoc.forEach( item => {
let body = ``;
let bodyParams = [];
item.longname = item.longname.replace(/\(0\)/g,"");
if (item.params){
bodyParams = item.params.map( (param, index) => {
return `\${${index+1}:${param.name}${param.type?`\: ${param.type.names[0]}`:''}}`
})
body = [`${item.longname}(${`${bodyParams.join(',')}`})`];
} else {
body = [item.longname];
}
vsCodeArray.push(
new VSCodeMappingObject(
item.name,
item.longname,
body,
item.description
)
)
});
// console.log("VSCodeMappingObject \n", vsCodeArray);
// Convert to JSON format
function JSONConvert(VSCodeMappingObject){
var ObjectForJSON = {};
ObjectForJSON[VSCodeMappingObject.prefix] = {
prefix: VSCodeMappingObject.prefix,
body: VSCodeMappingObject.body,
description: VSCodeMappingObject.description
}
return JSON.stringify(ObjectForJSON);
}
// convert array
var convertedArray = vsCodeArray.map(vcObject => JSONConvert(vcObject))
// console.log("convertedArray \n", convertedArray);
// write file
var stringToWrite = `
[
\t${convertedArray.join(",\n\t")}
]
`
// console.log(stringToWrite);
fs.writeFileSync(path.join(__dirname, 'out', 'hifiVsCode.json'), stringToWrite);
/*
https://code.visualstudio.com/docs/editor/userdefinedsnippets
How VSCODE snipets are formated:
{
"For_Loop": {
"prefix": "for",
"body": [
"for (const ${2:element} of ${1:array}) {",
"\t$0",
"}"
],
"description": "For Loop"
},
}
For Loop
is the snippet name.
prefix
defines how this snippet is selected from
IntelliSense and tab completion. In this case for.
body
is the content and either a single string or
an array of strings of which each element will be
inserted as separate line.
description
is the description used in the IntelliSense drop down.
*/