diff options
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/diagnostics/await-in-sync.lua | 6 | ||||
-rw-r--r-- | script/core/diagnostics/not-yieldable.lua | 54 |
2 files changed, 58 insertions, 2 deletions
diff --git a/script/core/diagnostics/await-in-sync.lua b/script/core/diagnostics/await-in-sync.lua index 5fb6467d..bfb4af38 100644 --- a/script/core/diagnostics/await-in-sync.lua +++ b/script/core/diagnostics/await-in-sync.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' return function (uri, callback) local state = files.getState(uri) @@ -9,11 +10,12 @@ return function (uri, callback) return end - guide.eachSourceType(state.ast, 'call', function (source) + guide.eachSourceType(state.ast, 'call', function (source) ---@async local currentFunc = guide.getParentFunction(source) - if currentFunc and vm.isAsync(currentFunc) then + if currentFunc and vm.isAsync(currentFunc, false) then return end + await.delay() if not vm.isAsync(source.node, true) then return end diff --git a/script/core/diagnostics/not-yieldable.lua b/script/core/diagnostics/not-yieldable.lua new file mode 100644 index 00000000..2f80e4d0 --- /dev/null +++ b/script/core/diagnostics/not-yieldable.lua @@ -0,0 +1,54 @@ +local files = require 'files' +local await = require 'await' +local guide = require 'parser.guide' +local vm = require 'vm' +local lang = require 'language' + +local function isYieldAble(defs, i) + local hasFuncDef + for _, def in ipairs(defs) do + if def.type == 'function' then + hasFuncDef = true + local arg = def.args and def.args[i] + if arg and vm.isAsync(arg, true) then + return true + end + end + if def.type == 'doc.type.function' then + hasFuncDef = true + local arg = def.args and def.args[i] + if arg and vm.isAsync(arg.extends, true) then + return true + end + end + end + return not hasFuncDef +end + +return function (uri, callback) + local state = files.getState(uri) + if not state then + return + end + + guide.eachSourceType(state.ast, 'call', function (source) ---@async + if not source.args then + return + end + await.delay() + local defs = vm.getDefs(source.node) + if #defs == 0 then + return + end + for i, arg in ipairs(source.args) do + if vm.isAsync(arg, true) + and not isYieldAble(defs, i) then + callback { + start = source.node.start, + finish = source.node.finish, + message = lang.script('DIAG_NOT_YIELDABLE', i), + } + end + end + end) +end |