Skip to content

Commit a73b2d1

Browse files
committed
build config
1 parent e963504 commit a73b2d1

File tree

4 files changed

+121
-0
lines changed

4 files changed

+121
-0
lines changed

.vscode/launch.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,22 @@
8888
"stderr",
8989
],
9090
},
91+
{
92+
"name": "🀄build-doc",
93+
"type": "lua",
94+
"request": "launch",
95+
"stopOnEntry": false,
96+
"luaexe": "${workspaceFolder}/bin/lua-language-server",
97+
"program": "${workspaceRoot}/tools/build-doc.lua",
98+
"cpath": "${workspaceFolder}/bin/?.dll",
99+
"arg": [
100+
],
101+
"luaVersion": "latest",
102+
"sourceCoding": "utf8",
103+
"outputCapture": [
104+
"print",
105+
"stderr",
106+
],
107+
},
91108
]
92109
}

script/config/template.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ end
1414

1515
function mt:__shr(default)
1616
self.default = default
17+
self.hasDefault = true
1718
return self
1819
end
1920

tools/build-doc.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package.path = package.path .. ';script/?.lua;tools/?.lua'
2+
3+
local config = require 'configuration'
4+

tools/configuration.lua

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
local json = require 'json'
2+
local template = require 'config.template'
3+
4+
local function getType(temp)
5+
if temp.name == 'Boolean' then
6+
return 'boolean'
7+
end
8+
if temp.name == 'String' then
9+
return 'string'
10+
end
11+
if temp.name == 'Integer' then
12+
return 'integer'
13+
end
14+
if temp.name == 'Nil' then
15+
return 'null'
16+
end
17+
if temp.name == 'Array' then
18+
return 'array'
19+
end
20+
if temp.name == 'Hash' then
21+
return 'object'
22+
end
23+
if temp.name == 'Or' then
24+
return { getType(temp.subs[1]), getType(temp.subs[2]) }
25+
end
26+
error('Unknown type: ' .. temp.name)
27+
end
28+
29+
local function getDefault(temp)
30+
local default = temp.default
31+
if default == nil and temp.hasDefault then
32+
default = json.null
33+
end
34+
return default
35+
end
36+
37+
local function getEnum(temp)
38+
return temp.enums
39+
end
40+
41+
local function getEnumDesc(name, temp)
42+
if not temp.enums then
43+
return nil
44+
end
45+
local descs = {}
46+
47+
for _, enum in ipairs(temp.enums) do
48+
descs[#descs+1] = name:gsub('^Lua', '%%config') .. '.' .. enum .. '%'
49+
end
50+
51+
return descs
52+
end
53+
54+
local function insertArray(conf, temp)
55+
conf.items = {
56+
type = getType(temp.sub),
57+
}
58+
end
59+
60+
local function insertHash(conf, temp)
61+
conf.additionalProperties = false
62+
if not temp.subkey.enums then
63+
if temp.subvalue.enums then
64+
conf.patternProperties = {
65+
['.*'] = {
66+
type = getType( temp.subvalue),
67+
default = getDefault( temp.subvalue),
68+
enum = getEnum( temp.subvalue),
69+
}
70+
}
71+
end
72+
end
73+
end
74+
75+
local config = {}
76+
77+
for name, temp in pairs(template) do
78+
config[name] = {
79+
scope = 'resource',
80+
type = getType(temp),
81+
default = getDefault(temp),
82+
enum = getEnum(temp),
83+
84+
markdownDescription = name:gsub('^Lua', '%%config') .. '%',
85+
markdownEnumDescriptions = getEnumDesc(name, temp),
86+
}
87+
88+
if temp.name == 'Array' then
89+
insertArray(config[name], temp)
90+
end
91+
92+
if temp.name == 'Hash' then
93+
insertHash(config[name], temp)
94+
end
95+
end
96+
97+
config['Lua.telemetry.enable'].tags = { 'telemetry' }
98+
99+
return config

0 commit comments

Comments
 (0)