diff options
Diffstat (limited to 'script')
21 files changed, 101 insertions, 23 deletions
diff --git a/script/core/diagnostics/circle-doc-class.lua b/script/core/diagnostics/circle-doc-class.lua index 40d4afeb..fcd2021d 100644 --- a/script/core/diagnostics/circle-doc-class.lua +++ b/script/core/diagnostics/circle-doc-class.lua @@ -2,7 +2,9 @@ local files = require 'files' local lang = require 'language' local vm = require 'vm' local guide = require 'parser.guide' +local await = require 'await' +---@async return function (uri, callback) local state = files.getState(uri) if not state then @@ -18,6 +20,7 @@ return function (uri, callback) if not doc.extends then goto CONTINUE end + await.delay() local myName = guide.getKeyName(doc) local list = { doc } local mark = {} diff --git a/script/core/diagnostics/code-after-break.lua b/script/core/diagnostics/code-after-break.lua index 21f7e83a..963fd9ed 100644 --- a/script/core/diagnostics/code-after-break.lua +++ b/script/core/diagnostics/code-after-break.lua @@ -2,7 +2,9 @@ local files = require 'files' local guide = require 'parser.guide' local lang = require 'language' local define = require 'proto.define' +local await = require 'await' +---@async return function (uri, callback) local state = files.getState(uri) if not state then @@ -10,12 +12,14 @@ return function (uri, callback) end local mark = {} + ---@async guide.eachSourceType(state.ast, 'break', function (source) local list = source.parent if mark[list] then return end mark[list] = true + await.delay() for i = #list, 1, -1 do local src = list[i] if src == source then diff --git a/script/core/diagnostics/duplicate-doc-alias.lua b/script/core/diagnostics/duplicate-doc-alias.lua index 5fd12847..2625f88f 100644 --- a/script/core/diagnostics/duplicate-doc-alias.lua +++ b/script/core/diagnostics/duplicate-doc-alias.lua @@ -2,7 +2,9 @@ local files = require 'files' local lang = require 'language' local vm = require 'vm' local guide = require 'parser.guide' +local await = require 'await' +---@async return function (uri, callback) local state = files.getState(uri) if not state then @@ -20,6 +22,7 @@ return function (uri, callback) if not name then return end + await.delay() if not cache[name] then local docs = vm.getDocSets(uri, name) cache[name] = {} diff --git a/script/core/diagnostics/duplicate-doc-field.lua b/script/core/diagnostics/duplicate-doc-field.lua index 78112beb..a30dfa88 100644 --- a/script/core/diagnostics/duplicate-doc-field.lua +++ b/script/core/diagnostics/duplicate-doc-field.lua @@ -1,6 +1,7 @@ local files = require 'files' local lang = require 'language' local vm = require 'vm.vm' +local await = require 'await' local function getFieldEventName(doc) if not doc.extends then @@ -29,6 +30,7 @@ local function getFieldEventName(doc) return nil end +---@async return function (uri, callback) local state = files.getState(uri) if not state then @@ -46,6 +48,7 @@ return function (uri, callback) mark = {} elseif doc.type == 'doc.field' then if mark then + await.delay() local name if doc.field.type == 'doc.type' then name = ('[%s]'):format(vm.getInfer(doc.field):view(uri)) diff --git a/script/core/diagnostics/duplicate-index.lua b/script/core/diagnostics/duplicate-index.lua index 5097ab3a..dfd9bd4b 100644 --- a/script/core/diagnostics/duplicate-index.lua +++ b/script/core/diagnostics/duplicate-index.lua @@ -2,14 +2,17 @@ local files = require 'files' local guide = require 'parser.guide' local lang = require 'language' local define = require 'proto.define' +local await = require 'await' +---@async return function (uri, callback) local ast = files.getState(uri) if not ast then return end - + ---@async guide.eachSourceType(ast.ast, 'table', function (source) + await.delay() local mark = {} for _, obj in ipairs(source) do if obj.type == 'tablefield' diff --git a/script/core/diagnostics/duplicate-set-field.lua b/script/core/diagnostics/duplicate-set-field.lua index f5007eb1..ce67ab46 100644 --- a/script/core/diagnostics/duplicate-set-field.lua +++ b/script/core/diagnostics/duplicate-set-field.lua @@ -3,17 +3,21 @@ local lang = require 'language' local define = require 'proto.define' local guide = require 'parser.guide' local vm = require 'vm' +local await = require 'await' +---@async return function (uri, callback) local ast = files.getState(uri) if not ast then return end + ---@async guide.eachSourceType(ast.ast, 'local', function (source) if not source.ref then return end + await.delay() local sets = {} for _, ref in ipairs(source.ref) do if ref.type ~= 'getlocal' then diff --git a/script/core/diagnostics/empty-block.lua b/script/core/diagnostics/empty-block.lua index fc205d7e..e05b6aef 100644 --- a/script/core/diagnostics/empty-block.lua +++ b/script/core/diagnostics/empty-block.lua @@ -2,15 +2,18 @@ local files = require 'files' local guide = require 'parser.guide' local lang = require 'language' local define = require 'proto.define' +local await = require 'await' --- 检查空代码块 +-- 检查空代码块 -- 但是排除忙等待(repeat/while) +---@async return function (uri, callback) local ast = files.getState(uri) if not ast then return end + await.delay() guide.eachSourceType(ast.ast, 'if', function (source) for _, block in ipairs(source) do if #block > 0 then @@ -24,6 +27,7 @@ return function (uri, callback) message = lang.script.DIAG_EMPTY_BLOCK, } end) + await.delay() guide.eachSourceType(ast.ast, 'loop', function (source) if #source > 0 then return @@ -35,6 +39,7 @@ return function (uri, callback) message = lang.script.DIAG_EMPTY_BLOCK, } end) + await.delay() guide.eachSourceType(ast.ast, 'in', function (source) if #source > 0 then return diff --git a/script/core/diagnostics/missing-parameter.lua b/script/core/diagnostics/missing-parameter.lua index b6067175..78b94a09 100644 --- a/script/core/diagnostics/missing-parameter.lua +++ b/script/core/diagnostics/missing-parameter.lua @@ -2,14 +2,18 @@ local files = require 'files' local guide = require 'parser.guide' local vm = require 'vm' local lang = require 'language' +local await = require 'await' +---@async return function (uri, callback) local state = files.getState(uri) if not state then return end + ---@async guide.eachSourceType(state.ast, 'call', function (source) + await.delay() local _, callArgs = vm.countList(source.args) local funcNode = vm.compileNode(source.node) diff --git a/script/core/diagnostics/missing-return-value.lua b/script/core/diagnostics/missing-return-value.lua index c2e882e3..2156d66c 100644 --- a/script/core/diagnostics/missing-return-value.lua +++ b/script/core/diagnostics/missing-return-value.lua @@ -2,6 +2,7 @@ local files = require 'files' local guide = require 'parser.guide' local vm = require 'vm' local lang = require 'language' +local await = require 'await' local function hasDocReturn(func) if not func.bindDocs then @@ -15,13 +16,16 @@ local function hasDocReturn(func) return false end +---@async return function (uri, callback) local state = files.getState(uri) if not state then return end + ---@async guide.eachSourceType(state.ast, 'function', function (source) + await.delay() if not hasDocReturn(source) then return end diff --git a/script/core/diagnostics/missing-return.lua b/script/core/diagnostics/missing-return.lua index 08932c83..5806f121 100644 --- a/script/core/diagnostics/missing-return.lua +++ b/script/core/diagnostics/missing-return.lua @@ -2,6 +2,7 @@ local files = require 'files' local guide = require 'parser.guide' local vm = require 'vm' local lang = require 'language' +local await = require 'await' ---@param uri uri ---@param func parser.object @@ -56,17 +57,20 @@ local function hasReturn(block) return false end +---@async return function (uri, callback) local state = files.getState(uri) if not state then return end + ---@async guide.eachSourceType(state.ast, 'function', function (source) -- check declare only if #source == 0 then return end + await.delay() if not hasDocReturn(uri, source) then return end diff --git a/script/core/diagnostics/need-check-nil.lua b/script/core/diagnostics/need-check-nil.lua index 867d0135..9c86939a 100644 --- a/script/core/diagnostics/need-check-nil.lua +++ b/script/core/diagnostics/need-check-nil.lua @@ -2,14 +2,18 @@ local files = require 'files' local guide = require 'parser.guide' local vm = require 'vm' local lang = require 'language' +local await = require 'await' +---@async return function (uri, callback) local state = files.getState(uri) if not state then return end + ---@async guide.eachSourceType(state.ast, 'getlocal', function (src) + await.delay() local checkNil local nxt = src.next if nxt then diff --git a/script/core/diagnostics/newfield-call.lua b/script/core/diagnostics/newfield-call.lua index b81d8c0a..e22dcffe 100644 --- a/script/core/diagnostics/newfield-call.lua +++ b/script/core/diagnostics/newfield-call.lua @@ -1,7 +1,9 @@ local files = require 'files' local guide = require 'parser.guide' local lang = require 'language' +local await = require 'await' +---@async return function (uri, callback) local state = files.getState(uri) local text = files.getText(uri) @@ -9,8 +11,9 @@ return function (uri, callback) return end - + ---@async guide.eachSourceType(state.ast, 'table', function (source) + await.delay() for i = 1, #source do local field = source[i] if field.type ~= 'tableexp' then diff --git a/script/core/diagnostics/newline-call.lua b/script/core/diagnostics/newline-call.lua index 9c526980..6460d3a7 100644 --- a/script/core/diagnostics/newline-call.lua +++ b/script/core/diagnostics/newline-call.lua @@ -1,7 +1,9 @@ local files = require 'files' local guide = require 'parser.guide' local lang = require 'language' +local await = require 'await' +---@async return function (uri, callback) local state = files.getState(uri) local text = files.getText(uri) @@ -9,6 +11,7 @@ return function (uri, callback) return end + ---@async guide.eachSourceType(state.ast, 'call', function (source) local node = source.node local args = source.args @@ -20,6 +23,9 @@ return function (uri, callback) if not source.next then return end + + await.delay() + local startOffset = guide.positionToOffset(state, args.start) + 1 local finishOffset = guide.positionToOffset(state, args.finish) if text:sub(startOffset, startOffset) ~= '(' diff --git a/script/core/diagnostics/no-unknown.lua b/script/core/diagnostics/no-unknown.lua index ff9f7a83..e706931a 100644 --- a/script/core/diagnostics/no-unknown.lua +++ b/script/core/diagnostics/no-unknown.lua @@ -2,24 +2,29 @@ local files = require 'files' local guide = require 'parser.guide' local lang = require 'language' local vm = require 'vm' +local await = require 'await' +local types = { + 'local', + 'setlocal', + 'setglobal', + 'getglobal', + 'setfield', + 'setindex', + 'tablefield', + 'tableindex', +} + +---@async return function (uri, callback) local ast = files.getState(uri) if not ast then return end - guide.eachSource(ast.ast, function (source) - if source.type ~= 'local' - and source.type ~= 'setlocal' - and source.type ~= 'setglobal' - and source.type ~= 'getglobal' - and source.type ~= 'setfield' - and source.type ~= 'setindex' - and source.type ~= 'tablefield' - and source.type ~= 'tableindex' then - return - end + ---@async + guide.eachSourceTypes(ast.ast, types, function (source) + await.delay() if vm.getInfer(source):view(uri) == 'unknown' then callback { start = source.start, diff --git a/script/core/diagnostics/redefined-local.lua b/script/core/diagnostics/redefined-local.lua index 2157ae71..1fb3ca6b 100644 --- a/script/core/diagnostics/redefined-local.lua +++ b/script/core/diagnostics/redefined-local.lua @@ -1,18 +1,23 @@ local files = require 'files' local guide = require 'parser.guide' local lang = require 'language' +local await = require 'await' +---@async return function (uri, callback) local ast = files.getState(uri) if not ast then return end + + ---@async guide.eachSourceType(ast.ast, 'local', function (source) local name = source[1] if name == '_' or name == ast.ENVMode then return end + await.delay() local exist = guide.getLocal(source, name, source.start-1) if exist then callback { diff --git a/script/core/diagnostics/redundant-parameter.lua b/script/core/diagnostics/redundant-parameter.lua index deda918a..9898d9bd 100644 --- a/script/core/diagnostics/redundant-parameter.lua +++ b/script/core/diagnostics/redundant-parameter.lua @@ -2,14 +2,18 @@ local files = require 'files' local guide = require 'parser.guide' local vm = require 'vm' local lang = require 'language' +local await = require 'await' +---@async return function (uri, callback) local state = files.getState(uri) if not state then return end + ---@async guide.eachSourceType(state.ast, 'call', function (source) + await.delay() local callArgs = vm.countList(source.args) if callArgs == 0 then return diff --git a/script/core/diagnostics/redundant-return-value.lua b/script/core/diagnostics/redundant-return-value.lua index 8f8422fe..36432f98 100644 --- a/script/core/diagnostics/redundant-return-value.lua +++ b/script/core/diagnostics/redundant-return-value.lua @@ -2,6 +2,7 @@ local files = require 'files' local guide = require 'parser.guide' local vm = require 'vm' local lang = require 'language' +local await = require 'await' local function hasDocReturn(func) if not func.bindDocs then @@ -15,13 +16,16 @@ local function hasDocReturn(func) return false end +---@async return function (uri, callback) local state = files.getState(uri) if not state then return end + ---@async guide.eachSourceType(state.ast, 'function', function (source) + await.delay() if not hasDocReturn(source) then return end diff --git a/script/core/diagnostics/return-type-mismatch.lua b/script/core/diagnostics/return-type-mismatch.lua index c170679f..cce4aad8 100644 --- a/script/core/diagnostics/return-type-mismatch.lua +++ b/script/core/diagnostics/return-type-mismatch.lua @@ -63,11 +63,11 @@ return function (uri, callback) if not source.returns then return end + await.delay() local docReturns = getDocReturns(source) if not docReturns then return end - await.delay() for _, ret in ipairs(source.returns) do checkReturn(docReturns, ret) await.delay() diff --git a/script/core/diagnostics/trailing-space.lua b/script/core/diagnostics/trailing-space.lua index aad0b53d..2e0398b2 100644 --- a/script/core/diagnostics/trailing-space.lua +++ b/script/core/diagnostics/trailing-space.lua @@ -1,7 +1,9 @@ local files = require 'files' local lang = require 'language' local guide = require 'parser.guide' +local await = require 'await' +---@async return function (uri, callback) local state = files.getState(uri) local text = files.getText(uri) @@ -10,6 +12,7 @@ return function (uri, callback) end local lines = state.lines for i = 0, #lines do + await.delay() local startOffset = lines[i] local finishOffset = text:find('[\r\n]', startOffset) or (#text + 1) local lastOffset = finishOffset - 1 diff --git a/script/core/diagnostics/unbalanced-assignments.lua b/script/core/diagnostics/unbalanced-assignments.lua index df71f0c9..c21ca993 100644 --- a/script/core/diagnostics/unbalanced-assignments.lua +++ b/script/core/diagnostics/unbalanced-assignments.lua @@ -2,7 +2,17 @@ local files = require 'files' local define = require 'proto.define' local lang = require 'language' local guide = require 'parser.guide' +local await = require 'await' +local types = { + 'local', + 'setlocal', + 'setglobal', + 'setfield', + 'setindex' , +} + +---@async return function (uri, callback, code) local ast = files.getState(uri) if not ast then @@ -31,13 +41,9 @@ return function (uri, callback, code) end end - guide.eachSource(ast.ast, function (source) - if source.type == 'local' - or source.type == 'setlocal' - or source.type == 'setglobal' - or source.type == 'setfield' - or source.type == 'setindex' then - checkSet(source) - end + ---@async + guide.eachSourceTypes(ast.ast, types, function (source) + await.delay() + checkSet(source) end) end diff --git a/script/core/diagnostics/undefined-global.lua b/script/core/diagnostics/undefined-global.lua index 7804aeee..bf161c73 100644 --- a/script/core/diagnostics/undefined-global.lua +++ b/script/core/diagnostics/undefined-global.lua @@ -41,6 +41,7 @@ return function (uri, callback) return end if cache[key] == nil then + await.delay() cache[key] = vm.hasGlobalSets(uri, 'variable', key) end if cache[key] then |