summaryrefslogtreecommitdiff
path: root/script/vm
diff options
context:
space:
mode:
authorfesily <fesil@foxmail.com>2024-01-16 13:38:52 +0800
committerfesily <fesil@foxmail.com>2024-01-16 13:38:52 +0800
commit10275c3667256e720371ce5280658c3e4f950d2f (patch)
tree27e45d80798e70c022d6031d7a716300849dcd9e /script/vm
parent4432dfea0fe8390be166b832a1ac416c8228296f (diff)
downloadlua-language-server-10275c3667256e720371ce5280658c3e4f950d2f.zip
automatic derivation function param type
Diffstat (limited to 'script/vm')
-rw-r--r--script/vm/compiler.lua31
1 files changed, 31 insertions, 0 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 8a1fa96a..7e12c32a 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -1090,6 +1090,37 @@ local function compileLocal(source)
end
end
end
+ if not hasDocArg
+ and func.parent.type == 'local' then
+ local refs = vm.getRefs(func, function (_)
+ return false
+ end)
+ local findCall
+ if refs then
+ for i, ref in ipairs(refs) do
+ if ref.parent.type == 'call' then
+ findCall = ref.parent
+ break
+ end
+ end
+ end
+ if findCall and findCall.args then
+ local index
+ for i, arg in ipairs(source.parent) do
+ if arg == source then
+ index = i
+ break
+ end
+ end
+ if index then
+ local callerArg = findCall.args[index]
+ if callerArg then
+ hasDocArg = true
+ vm.setNode(source, vm.compileNode(callerArg))
+ end
+ end
+ end
+ end
if not hasDocArg then
vm.setNode(source, vm.declareGlobal('type', 'any'))
end