summaryrefslogtreecommitdiff
path: root/script/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-05-23 21:24:29 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-05-23 21:24:29 +0800
commitf0f80fdf1b5c83467687541ffda36cabb8f9bd62 (patch)
tree155b907025c269dd7cf2a0eb7588de9aa8f47163 /script/core
parentc1e9e46dea95140fd14fd12f99fc098c59ba9fcd (diff)
downloadlua-language-server-f0f80fdf1b5c83467687541ffda36cabb8f9bd62.zip
fix #1131
Diffstat (limited to 'script/core')
-rw-r--r--script/core/diagnostics/missing-parameter.lua58
1 files changed, 58 insertions, 0 deletions
diff --git a/script/core/diagnostics/missing-parameter.lua b/script/core/diagnostics/missing-parameter.lua
index 698680ca..f69afa79 100644
--- a/script/core/diagnostics/missing-parameter.lua
+++ b/script/core/diagnostics/missing-parameter.lua
@@ -3,11 +3,69 @@ local guide = require 'parser.guide'
local vm = require 'vm'
local lang = require 'language'
+---@param source parser.object
+---@return integer
+local function countReturns(source)
+ local n = 0
+
+ local docs = source.bindDocs
+ if docs then
+ for _, doc in ipairs(docs) do
+ if doc.type == 'doc.return' then
+ for _, rtn in ipairs(doc.returns) do
+ if rtn.returnIndex and rtn.returnIndex > n then
+ n = rtn.returnIndex
+ end
+ end
+ end
+ end
+ end
+
+ local returns = source.returns
+ if returns then
+ for _, rtn in ipairs(returns) do
+ if #rtn > n then
+ n = #rtn
+ end
+ end
+ end
+
+ return n
+end
+
+local function countMaxReturns(source)
+ local hasFounded
+ local n = 0
+ for _, def in ipairs(vm.getDefs(source)) do
+ if def.type == 'doc.type.function'
+ or def.type == 'function' then
+ hasFounded = true
+ local rets = countReturns(def)
+ if rets > n then
+ n = rets
+ end
+ end
+ end
+
+ if hasFounded then
+ return n
+ else
+ return math.huge
+ end
+end
+
local function countCallArgs(source)
local result = 0
if not source.args then
return 0
end
+ local lastArg = source.args[#source.args]
+ if lastArg.type == 'varargs' then
+ return math.huge
+ end
+ if lastArg.type == 'call' then
+ result = result + countMaxReturns(lastArg) - 1
+ end
result = result + #source.args
return result
end