summaryrefslogtreecommitdiff
path: root/script-beta/vm
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-05-30 16:36:31 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-05-30 16:36:31 +0800
commit7f963936a62ff7a138458c50736fcf106cc2fbe3 (patch)
tree327567938b5394897898dbbba2898511048cd230 /script-beta/vm
parentdb3fe02b476bc81bf7b0dc00125a4622346c0b92 (diff)
downloadlua-language-server-7f963936a62ff7a138458c50736fcf106cc2fbe3.zip
完成 hover
Diffstat (limited to 'script-beta/vm')
-rw-r--r--script-beta/vm/getValue.lua37
1 files changed, 37 insertions, 0 deletions
diff --git a/script-beta/vm/getValue.lua b/script-beta/vm/getValue.lua
index b0361df7..d5665a8c 100644
--- a/script-beta/vm/getValue.lua
+++ b/script-beta/vm/getValue.lua
@@ -776,6 +776,42 @@ local function inferByCallReturn(results, source)
end
end
+local function inferByPCallReturn(results, source)
+ if source.type ~= 'select' then
+ return
+ end
+ local call = source.vararg
+ if not call or call.type ~= 'call' then
+ return
+ end
+ local node = call.node
+ local lib = vm.getLibrary(node)
+ if not lib then
+ return
+ end
+ local func, index
+ if lib.name == 'pcall' then
+ func = call.args[1]
+ index = source.index - 1
+ elseif lib.name == 'xpcall' then
+ func = call.args[1]
+ index = source.index - 2
+ else
+ return
+ end
+ local funcValues = vm.getValue(func)
+ if not funcValues then
+ return
+ end
+ for i = 1, #funcValues do
+ local value = funcValues[i]
+ local src = value.source
+ if src.type == 'function' then
+ mergeFunctionReturns(results, src, index)
+ end
+ end
+end
+
local function getValue(source)
local results = checkLiteral(source)
or checkValue(source)
@@ -798,6 +834,7 @@ local function getValue(source)
inferByUnary(results, source)
inferByBinary(results, source)
inferByCallReturn(results, source)
+ inferByPCallReturn(results, source)
if #results == 0 then
return nil