diff options
Diffstat (limited to 'script/vm/getDocs.lua')
-rw-r--r-- | script/vm/getDocs.lua | 136 |
1 files changed, 135 insertions, 1 deletions
diff --git a/script/vm/getDocs.lua b/script/vm/getDocs.lua index 2fb2bda9..3a0765bf 100644 --- a/script/vm/getDocs.lua +++ b/script/vm/getDocs.lua @@ -1,6 +1,6 @@ local files = require 'files' local guide = require 'parser.guide' ----@type vm +---@class vm local vm = require 'vm.vm' local config = require 'config' local collector = require 'core.collector' @@ -180,6 +180,140 @@ function vm.isDeprecated(value, deep) end end +local function isAsync(value) + if value.type == 'function' then + if not value.bindDocs then + return false + end + if value._async ~= nil then + return value._async + end + for _, doc in ipairs(value.bindDocs) do + if doc.type == 'doc.async' then + value._async = true + return true + end + end + value._async = false + return false + end + return value.async == true +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 + return false + end + for _, def in ipairs(defs) do + if isAsync(def) then + return true + end + end + end + return false +end + +local function isNoDiscard(value) + if value.type == 'function' then + if not value.bindDocs then + return false + end + if value._nodiscard ~= nil then + return value._nodiscard + end + for _, doc in ipairs(value.bindDocs) do + if doc.type == 'doc.nodiscard' then + value._nodiscard = true + return true + end + end + value._nodiscard = false + return false + end + return false +end + +function vm.isNoDiscard(value, deep) + if isNoDiscard(value) then + return true + end + if deep then + local defs = vm.getDefs(value) + if #defs == 0 then + return false + end + for _, def in ipairs(defs) do + if isNoDiscard(def) then + return true + end + end + end + return false +end + +local function isCalledInFunction(param) + if not param.ref then + return false + end + 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.isLinkedCall(node, index) + return isLinkedCall(node, index) +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) local names if doc.names then |