summaryrefslogtreecommitdiff
path: root/script/vm
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-11-03 16:15:45 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-11-03 16:15:45 +0800
commit5cd171f682ec7f80459741c381a7ca52c1ea1aaf (patch)
tree7ae741641ca66e51ca66fa109d39274ae187e065 /script/vm
parentf1ced65b41bd764c9656a9523ddfd3d43aa2cfb1 (diff)
downloadlua-language-server-5cd171f682ec7f80459741c381a7ca52c1ea1aaf.zip
check await cross linked callback
Diffstat (limited to 'script/vm')
-rw-r--r--script/vm/getDocs.lua58
1 files changed, 55 insertions, 3 deletions
diff --git a/script/vm/getDocs.lua b/script/vm/getDocs.lua
index ed2299ec..1af85409 100644
--- a/script/vm/getDocs.lua
+++ b/script/vm/getDocs.lua
@@ -201,6 +201,9 @@ function vm.isDeprecated(value, deep)
end
function vm.isAsync(value, deep)
+ if isAsync(value) then
+ return true
+ end
if deep then
local defs = vm.getDefs(value)
if #defs == 0 then
@@ -211,10 +214,59 @@ function vm.isAsync(value, deep)
return true
end
end
- return false
- else
- return isAsync(value)
end
+ return false
+end
+
+local function isCalledInFunction(param)
+ local func = guide.getParentFunction(param)
+ for _, ref in ipairs(param.ref) do
+ if ref.type == 'getlocal' then
+ if ref.parent.type == 'call'
+ and guide.getParentFunction(ref) == func then
+ return true
+ end
+ if ref.parent.type == 'callargs'
+ and ref.parent[1] == ref
+ and guide.getParentFunction(ref) == func then
+ if ref.parent.parent.node.special == 'pcall'
+ or ref.parent.parent.node.special == 'xpcall' then
+ return true
+ end
+ end
+ end
+ end
+ return false
+end
+
+local function isLinkedCall(node, index)
+ for _, def in ipairs(vm.getDefs(node)) do
+ if def.type == 'function' then
+ local param = def.args and def.args[index]
+ if param then
+ if isCalledInFunction(param) then
+ return true
+ end
+ end
+ end
+ end
+ return false
+end
+
+function vm.isAsyncCall(call)
+ if vm.isAsync(call.node, true) then
+ return true
+ end
+ if not call.args then
+ return
+ end
+ for i, arg in ipairs(call.args) do
+ if vm.isAsync(arg, true)
+ and isLinkedCall(call.node, i) then
+ return true
+ end
+ end
+ return false
end
local function makeDiagRange(uri, doc, results)