diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-11-03 17:29:18 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-11-03 17:29:18 +0800 |
commit | 7b76328600dd9bc5206f38a549da9e4f99c9ff84 (patch) | |
tree | 979dccdcb4c29a2f8e57f0730c0ff58b827b1af8 /script/vm | |
parent | ed6011c30754bfaa646f5a9a819f20f1f32cbfba (diff) | |
download | lua-language-server-7b76328600dd9bc5206f38a549da9e4f99c9ff84.zip |
#687 `---@nodiscard`
Diffstat (limited to 'script/vm')
-rw-r--r-- | script/vm/getDocs.lua | 56 |
1 files changed, 47 insertions, 9 deletions
diff --git a/script/vm/getDocs.lua b/script/vm/getDocs.lua index 1af85409..f5c4e4e1 100644 --- a/script/vm/getDocs.lua +++ b/script/vm/getDocs.lua @@ -163,6 +163,23 @@ local function isDeprecated(value) return false end +function vm.isDeprecated(value, deep) + if deep then + local defs = vm.getDefs(value) + if #defs == 0 then + return false + end + for _, def in ipairs(defs) do + if not isDeprecated(def) then + return false + end + end + return true + else + return isDeprecated(value) + end +end + local function isAsync(value) if value.type == 'function' then if not value.bindDocs then @@ -183,25 +200,46 @@ local function isAsync(value) return value.async == true end -function vm.isDeprecated(value, deep) +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 not isDeprecated(def) then - return false + if isAsync(def) then + return true end end - return true - else - return isDeprecated(value) end + return false end -function vm.isAsync(value, deep) - if isAsync(value) then +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 @@ -210,7 +248,7 @@ function vm.isAsync(value, deep) return false end for _, def in ipairs(defs) do - if isAsync(def) then + if isNoDiscard(def) then return true end end |