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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
|
local util = require 'utility'
local define = require 'proto.define'
local diag = require 'proto.diagnostic'
---@class config.unit
---@field caller function
---@field _checker fun(self: config.unit, value: any): boolean
---@field name string
---@field [string] config.unit
---@operator shl: config.unit
---@operator shr: config.unit
---@operator call: config.unit
local mt = {}
mt.__index = mt
function mt:__call(...)
self:caller(...)
return self
end
function mt:__shr(default)
self.default = default
self.hasDefault = true
return self
end
function mt:__shl(enums)
self.enums = enums
return self
end
function mt:checker(v)
if self.enums then
local ok
for _, enum in ipairs(self.enums) do
if util.equal(enum, v) then
ok = true
break
end
end
if not ok then
return false
end
end
return self:_checker(v)
end
local units = {}
local function register(name, default, checker, loader, caller)
units[name] = {
name = name,
default = default,
_checker = checker,
loader = loader,
caller = caller,
}
end
---@type config.unit
local Type = setmetatable({}, { __index = function (_, name)
local unit = {}
for k, v in pairs(units[name]) do
unit[k] = v
end
return setmetatable(unit, mt)
end })
register('Boolean', false, function (self, v)
return type(v) == 'boolean'
end, function (self, v)
return v
end)
register('Integer', 0, function (self, v)
return type(v) == 'number'
end, function (self, v)
return math.floor(v)
end)
register('String', '', function (self, v)
return type(v) == 'string'
end, function (self, v)
return tostring(v)
end)
register('Nil', nil, function (self, v)
return type(v) == 'nil'
end, function (self, v)
return nil
end)
register('Array', {}, function (self, value)
return type(value) == 'table'
end, function (self, value)
local t = {}
if #value == 0 then
for k in pairs(value) do
if self.sub:checker(k) then
t[#t+1] = self.sub:loader(k)
end
end
else
for _, v in ipairs(value) do
if self.sub:checker(v) then
t[#t+1] = self.sub:loader(v)
end
end
end
return t
end, function (self, sub)
self.sub = sub
end)
register('Hash', {}, function (self, value)
if type(value) == 'table' then
if #value == 0 then
for k, v in pairs(value) do
if not self.subkey:checker(k)
or not self.subvalue:checker(v) then
return false
end
end
else
if not self.subvalue:checker(true) then
return false
end
for _, v in ipairs(value) do
if not self.subkey:checker(v) then
return false
end
end
end
return true
end
if type(value) == 'string' then
return self.subkey:checker('')
and self.subvalue:checker(true)
end
end, function (self, value)
if type(value) == 'table' then
local t = {}
if #value == 0 then
for k, v in pairs(value) do
t[k] = v
end
else
for _, k in pairs(value) do
t[k] = true
end
end
return t
end
if type(value) == 'string' then
local t = {}
for s in value:gmatch('[^' .. self.sep .. ']+') do
t[s] = true
end
return t
end
end, function (self, subkey, subvalue, sep)
self.subkey = subkey
self.subvalue = subvalue
self.sep = sep
end)
register('Or', nil, function (self, value)
for _, sub in ipairs(self.subs) do
if sub:checker(value) then
return true
end
end
return false
end, function (self, value)
for _, sub in ipairs(self.subs) do
if sub:checker(value) then
return sub:loader(value)
end
end
end, function (self, ...)
self.subs = { ... }
end)
---@format disable-next
local template = {
['Lua.runtime.version'] = Type.String >> 'Lua 5.4' << {
'Lua 5.1',
'Lua 5.2',
'Lua 5.3',
'Lua 5.4',
'LuaJIT',
},
['Lua.runtime.path'] = Type.Array(Type.String) >> {
"?.lua",
"?/init.lua",
},
['Lua.runtime.pathStrict'] = Type.Boolean >> false,
['Lua.runtime.special'] = Type.Hash(
Type.String,
Type.String >> 'require' << {
'_G',
'rawset',
'rawget',
'setmetatable',
'require',
'dofile',
'loadfile',
'pcall',
'xpcall',
'assert',
'error',
'type',
'os.exit',
}
),
['Lua.runtime.meta'] = Type.String >> '${version} ${language} ${encoding}',
['Lua.runtime.unicodeName'] = Type.Boolean,
['Lua.runtime.nonstandardSymbol'] = Type.Array(Type.String << {
'//', '/**/',
'`',
'+=', '-=', '*=', '/=', '%=', '^=', '//=',
'|=', '&=', '<<=', '>>=',
'||', '&&', '!', '!=',
'continue',
}),
['Lua.runtime.plugin'] = Type.String,
['Lua.runtime.pluginArgs'] = Type.Array(Type.String),
['Lua.runtime.fileEncoding'] = Type.String >> 'utf8' << {
'utf8',
'ansi',
'utf16le',
'utf16be',
},
['Lua.runtime.builtin'] = Type.Hash(
Type.String << util.getTableKeys(define.BuiltIn, true),
Type.String >> 'default' << {
'default',
'enable',
'disable',
}
)
>> util.deepCopy(define.BuiltIn),
['Lua.diagnostics.enable'] = Type.Boolean >> true,
['Lua.diagnostics.globals'] = Type.Array(Type.String),
['Lua.diagnostics.disable'] = Type.Array(Type.String << util.getTableKeys(diag.getDiagAndErrNameMap(), true)),
['Lua.diagnostics.severity'] = Type.Hash(
Type.String << util.getTableKeys(define.DiagnosticDefaultNeededFileStatus, true),
Type.String << {
'Error',
'Warning',
'Information',
'Hint',
'Error!',
'Warning!',
'Information!',
'Hint!',
}
)
>> util.deepCopy(define.DiagnosticDefaultSeverity),
['Lua.diagnostics.neededFileStatus'] = Type.Hash(
Type.String << util.getTableKeys(define.DiagnosticDefaultNeededFileStatus, true),
Type.String << {
'Any',
'Opened',
'None',
'Any!',
'Opened!',
'None!',
}
)
>> util.deepCopy(define.DiagnosticDefaultNeededFileStatus),
['Lua.diagnostics.groupSeverity'] = Type.Hash(
Type.String << util.getTableKeys(define.DiagnosticDefaultGroupSeverity, true),
Type.String << {
'Error',
'Warning',
'Information',
'Hint',
'Fallback',
}
)
>> util.deepCopy(define.DiagnosticDefaultGroupSeverity),
['Lua.diagnostics.groupFileStatus'] = Type.Hash(
Type.String << util.getTableKeys(define.DiagnosticDefaultGroupFileStatus, true),
Type.String << {
'Any',
'Opened',
'None',
'Fallback',
}
)
>> util.deepCopy(define.DiagnosticDefaultGroupFileStatus),
['Lua.diagnostics.disableScheme'] = Type.Array(Type.String) >> { 'git' },
['Lua.diagnostics.workspaceEvent'] = Type.String >> 'OnSave' << {
'OnChange',
'OnSave',
'None',
},
['Lua.diagnostics.workspaceDelay'] = Type.Integer >> 3000,
['Lua.diagnostics.workspaceRate'] = Type.Integer >> 100,
['Lua.diagnostics.libraryFiles'] = Type.String >> 'Opened' << {
'Enable',
'Opened',
'Disable',
},
['Lua.diagnostics.ignoredFiles'] = Type.String >> 'Opened' << {
'Enable',
'Opened',
'Disable',
},
['Lua.diagnostics.unusedLocalExclude'] = Type.Array(Type.String),
['Lua.workspace.ignoreDir'] = Type.Array(Type.String) >> {
'.vscode',
},
['Lua.workspace.ignoreSubmodules'] = Type.Boolean >> true,
['Lua.workspace.useGitIgnore'] = Type.Boolean >> true,
['Lua.workspace.maxPreload'] = Type.Integer >> 5000,
['Lua.workspace.preloadFileSize'] = Type.Integer >> 500,
['Lua.workspace.library'] = Type.Array(Type.String),
['Lua.workspace.checkThirdParty'] = Type.Boolean >> true,
['Lua.workspace.userThirdParty'] = Type.Array(Type.String),
['Lua.completion.enable'] = Type.Boolean >> true,
['Lua.completion.callSnippet'] = Type.String >> 'Disable' << {
'Disable',
'Both',
'Replace',
},
['Lua.completion.keywordSnippet'] = Type.String >> 'Replace' << {
'Disable',
'Both',
'Replace',
},
['Lua.completion.displayContext'] = Type.Integer >> 0,
['Lua.completion.workspaceWord'] = Type.Boolean >> true,
['Lua.completion.showWord'] = Type.String >> 'Fallback' << {
'Enable',
'Fallback',
'Disable',
},
['Lua.completion.autoRequire'] = Type.Boolean >> true,
['Lua.completion.showParams'] = Type.Boolean >> true,
['Lua.completion.requireSeparator'] = Type.String >> '.',
['Lua.completion.postfix'] = Type.String >> '@',
['Lua.signatureHelp.enable'] = Type.Boolean >> true,
['Lua.hover.enable'] = Type.Boolean >> true,
['Lua.hover.viewString'] = Type.Boolean >> true,
['Lua.hover.viewStringMax'] = Type.Integer >> 1000,
['Lua.hover.viewNumber'] = Type.Boolean >> true,
['Lua.hover.previewFields'] = Type.Integer >> 50,
['Lua.hover.enumsLimit'] = Type.Integer >> 5,
['Lua.hover.expandAlias'] = Type.Boolean >> true,
['Lua.semantic.enable'] = Type.Boolean >> true,
['Lua.semantic.variable'] = Type.Boolean >> true,
['Lua.semantic.annotation'] = Type.Boolean >> true,
['Lua.semantic.keyword'] = Type.Boolean >> false,
['Lua.hint.enable'] = Type.Boolean >> false,
['Lua.hint.paramType'] = Type.Boolean >> true,
['Lua.hint.setType'] = Type.Boolean >> false,
['Lua.hint.paramName'] = Type.String >> 'All' << {
'All',
'Literal',
'Disable',
},
['Lua.hint.await'] = Type.Boolean >> true,
['Lua.hint.arrayIndex'] = Type.String >> 'Auto' << {
'Enable',
'Auto',
'Disable',
},
['Lua.hint.semicolon'] = Type.String >> 'SameLine' << {
'All',
'SameLine',
'Disable',
},
['Lua.window.statusBar'] = Type.Boolean >> true,
['Lua.window.progressBar'] = Type.Boolean >> true,
['Lua.codeLens.enable'] = Type.Boolean >> false,
['Lua.format.enable'] = Type.Boolean >> true,
['Lua.format.defaultConfig'] = Type.Hash(Type.String, Type.String)
>> {},
['Lua.typeFormat.config'] = Type.Hash(Type.String, Type.String)
>> {
format_line = "true",
auto_complete_end = "true",
auto_complete_table_sep = "true"
},
['Lua.spell.dict'] = Type.Array(Type.String),
['Lua.nameStyle.config'] = Type.Hash(Type.String, Type.Or(Type.String, Type.Array(Type.Hash(Type.String, Type.String))))
>> {},
['Lua.misc.parameters'] = Type.Array(Type.String),
['Lua.misc.executablePath'] = Type.String,
['Lua.type.castNumberToInteger'] = Type.Boolean >> true,
['Lua.type.weakUnionCheck'] = Type.Boolean >> false,
['Lua.type.weakNilCheck'] = Type.Boolean >> false,
['Lua.doc.privateName'] = Type.Array(Type.String),
['Lua.doc.protectedName'] = Type.Array(Type.String),
['Lua.doc.packageName'] = Type.Array(Type.String),
-- VSCode
["Lua.addonManager.enable"] = Type.Boolean >> true,
['files.associations'] = Type.Hash(Type.String, Type.String),
-- copy from VSCode default
['files.exclude'] = Type.Hash(Type.String, Type.Boolean) >> {
["**/.DS_Store"] = true,
["**/.git"] = true,
["**/.hg"] = true,
["**/.svn"] = true,
["**/CVS"] = true,
["**/Thumbs.db"] = true,
},
['editor.semanticHighlighting.enabled'] = Type.Or(Type.Boolean, Type.String),
['editor.acceptSuggestionOnEnter'] = Type.String >> 'on',
}
return template
|