Skip to content

Commit 680e6c9

Browse files
committed
cleanup
1 parent 5762f1b commit 680e6c9

File tree

13 files changed

+78
-26
lines changed

13 files changed

+78
-26
lines changed

script/cli/check.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ lclient():start(function (client)
5050

5151
ws.awaitReady(rootUri)
5252

53-
local disables = config.get(rootUri, 'Lua.diagnostics.disable')
53+
local disables = util.arrayToHash(config.get(rootUri, 'Lua.diagnostics.disable'))
5454
for name, serverity in pairs(define.DiagnosticDefaultSeverity) do
5555
serverity = config.get(rootUri, 'Lua.diagnostics.severity')[name] or 'Warning'
5656
if define.DiagnosticSeverity[serverity] > checkLevel then
5757
disables[name] = true
5858
end
5959
end
60-
config.set(nil, 'Lua.diagnostics.disable', disables)
60+
config.set(nil, 'Lua.diagnostics.disable', util.getTableKeys(disables, true))
6161

6262
local uris = files.getAllUris(rootUri)
6363
local max = #uris

script/config/template.lua

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ local units = {}
4242

4343
local function register(name, default, checker, loader, caller)
4444
units[name] = {
45-
default = default,
45+
name = name,
46+
default = default,
4647
_checker = checker,
47-
loader = loader,
48-
caller = caller,
48+
loader = loader,
49+
caller = caller,
4950
}
5051
end
5152

@@ -194,18 +195,25 @@ local template = {
194195
),
195196
['Lua.runtime.meta'] = Type.String >> '${version} ${language} ${encoding}',
196197
['Lua.runtime.unicodeName'] = Type.Boolean,
197-
['Lua.runtime.nonstandardSymbol'] = Type.Hash(Type.String, Type.Boolean, ';'),
198+
['Lua.runtime.nonstandardSymbol'] = Type.Array(Type.String),
198199
['Lua.runtime.plugin'] = Type.String,
199200
['Lua.runtime.fileEncoding'] = Type.String >> 'utf8' << {
200201
'utf8',
201202
'ansi',
202203
'utf16le',
203204
'utf16be',
204205
},
205-
['Lua.runtime.builtin'] = Type.Hash(Type.String, Type.String),
206+
['Lua.runtime.builtin'] = Type.Hash(
207+
Type.String << util.getTableKeys(define.BuiltIn, true),
208+
Type.String >> 'default' << {
209+
'default',
210+
'enable',
211+
'disable',
212+
}
213+
),
206214
['Lua.diagnostics.enable'] = Type.Boolean >> true,
207-
['Lua.diagnostics.globals'] = Type.Hash(Type.String, Type.Boolean, ';'),
208-
['Lua.diagnostics.disable'] = Type.Hash(Type.String, Type.Boolean, ';'),
215+
['Lua.diagnostics.globals'] = Type.Array(Type.String),
216+
['Lua.diagnostics.disable'] = Type.Array(Type.String),
209217
['Lua.diagnostics.severity'] = Type.Hash(Type.String, Type.String)
210218
>> util.deepCopy(define.DiagnosticDefaultSeverity),
211219
['Lua.diagnostics.neededFileStatus'] = Type.Hash(Type.String, Type.String)

script/core/completion/completion.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ local function checkModule(state, word, position, results)
356356
if not config.get(state.uri, 'Lua.completion.autoRequire') then
357357
return
358358
end
359+
local globals = util.arrayToHash(config.get(state.uri, 'Lua.diagnostics.globals'))
359360
local locals = guide.getVisibleLocals(state.ast, position)
360361
for uri in files.eachFile(state.uri) do
361362
if uri == guide.getUri(state.ast) then
@@ -366,7 +367,7 @@ local function checkModule(state, word, position, results)
366367
local stemName = fileName:gsub('%..+', '')
367368
if not locals[stemName]
368369
and not vm.hasGlobalSets(state.uri, 'variable', stemName)
369-
and not config.get(state.uri, 'Lua.diagnostics.globals')[stemName]
370+
and not globals[stemName]
370371
and stemName:match '^[%a_][%w_]*$'
371372
and matchKey(word, stemName) then
372373
local targetState = files.getState(uri)

script/core/diagnostics/deprecated.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ return function (uri, callback)
1515
return
1616
end
1717

18-
local dglobals = config.get(uri, 'Lua.diagnostics.globals')
18+
local dglobals = util.arrayToHash(config.get(uri, 'Lua.diagnostics.globals'))
1919
local rspecial = config.get(uri, 'Lua.runtime.special')
2020

2121
guide.eachSourceTypes(ast.ast, types, function (src) ---@async

script/core/diagnostics/init.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local define = require 'proto.define'
33
local config = require 'config'
44
local await = require 'await'
55
local vm = require "vm.vm"
6+
local util = require 'utility'
67

78
-- 把耗时最长的诊断放到最后面
89
local diagSort = {
@@ -52,7 +53,8 @@ end
5253
---@param isScopeDiag boolean
5354
---@param response async fun(result: any)
5455
local function check(uri, name, isScopeDiag, response)
55-
if config.get(uri, 'Lua.diagnostics.disable')[name] then
56+
local disables = config.get(uri, 'Lua.diagnostics.disable')
57+
if util.arrayHas(disables, name) then
5658
return
5759
end
5860
local level = config.get(uri, 'Lua.diagnostics.severity')[name]

script/core/diagnostics/lowercase-global.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local guide = require 'parser.guide'
33
local lang = require 'language'
44
local config = require 'config'
55
local vm = require 'vm'
6+
local util = require 'utility'
67

78
local function isDocClass(source)
89
if not source.bindDocs then
@@ -23,10 +24,7 @@ return function (uri, callback)
2324
return
2425
end
2526

26-
local definedGlobal = {}
27-
for name in pairs(config.get(uri, 'Lua.diagnostics.globals')) do
28-
definedGlobal[name] = true
29-
end
27+
local definedGlobal = util.arrayToHash(config.get(uri, 'Lua.diagnostics.globals'))
3028

3129
guide.eachSourceType(ast.ast, 'setglobal', function (source)
3230
local name = guide.getKeyName(source)

script/core/diagnostics/undefined-global.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local lang = require 'language'
44
local config = require 'config'
55
local guide = require 'parser.guide'
66
local await = require 'await'
7+
local util = require 'utility'
78

89
local requireLike = {
910
['include'] = true,
@@ -19,7 +20,7 @@ return function (uri, callback)
1920
return
2021
end
2122

22-
local dglobals = config.get(uri, 'Lua.diagnostics.globals')
23+
local dglobals = util.arrayToHash(config.get(uri, 'Lua.diagnostics.globals'))
2324
local rspecial = config.get(uri, 'Lua.runtime.special')
2425
local cache = {}
2526

script/files.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ function m.compileState(uri, text)
488488
, {
489489
special = config.get(uri, 'Lua.runtime.special'),
490490
unicodeName = config.get(uri, 'Lua.runtime.unicodeName'),
491-
nonstandardSymbol = config.get(uri, 'Lua.runtime.nonstandardSymbol'),
491+
nonstandardSymbol = util.arrayToHash(config.get(uri, 'Lua.runtime.nonstandardSymbol')),
492492
}
493493
)
494494
local passed = os.clock() - clock

script/provider/diagnostic.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ function m.syntaxErrors(uri, ast)
183183
local results = {}
184184

185185
pcall(function ()
186-
local disables = config.get(uri, 'Lua.diagnostics.disable')
186+
local disables = util.arrayToHash(config.get(uri, 'Lua.diagnostics.disable'))
187187
for _, err in ipairs(ast.errs) do
188188
if not disables[err.type:lower():gsub('_', '-')] then
189189
results[#results+1] = buildSyntaxError(uri, err)

script/provider/formatting.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function m.updateNonStandardSymbols(symbols)
8383
end
8484

8585
local eqTokens = {}
86-
for token in pairs(symbols) do
86+
for _, token in ipairs(symbols) do
8787
if token:find("=") and token ~= "!=" then
8888
table.insert(eqTokens, token)
8989
end

0 commit comments

Comments
 (0)