summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-20 21:59:50 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-20 21:59:50 +0800
commit88373142ae448513f598cd49119862648658bb17 (patch)
tree7e917067562412d35511649b3b138e00f51b0cfc
parent6a2ee814158b5e343a8b1f63a26b4de40e29ae2a (diff)
downloadlua-language-server-88373142ae448513f598cd49119862648658bb17.zip
检查lib的返回值
-rw-r--r--server-beta/src/vm/getValue.lua40
1 files changed, 36 insertions, 4 deletions
diff --git a/server-beta/src/vm/getValue.lua b/server-beta/src/vm/getValue.lua
index 88f01721..18a2af0b 100644
--- a/server-beta/src/vm/getValue.lua
+++ b/server-beta/src/vm/getValue.lua
@@ -443,7 +443,7 @@ local function checkValue(source)
end
end
-local function checkCall(results, source)
+local function inferByCall(results, source)
if not source.parent then
return
end
@@ -459,7 +459,7 @@ local function checkCall(results, source)
end
end
-local function checkNext(results, source)
+local function inferByGetTable(results, source)
local next = source.next
if not next then
return
@@ -499,20 +499,52 @@ local function checkLibrary(source)
}
end
+local function checkLibraryReturn(source)
+ if source.type ~= 'select' then
+ return nil
+ end
+ local index = source.index
+ local call = source.vararg
+ if call.type ~= 'call' then
+ return nil
+ end
+ local func = call.node
+ local lib = vm.getLibrary(func)
+ if not lib then
+ return nil
+ end
+ if lib.type ~= 'function' then
+ return nil
+ end
+ if not lib.returns then
+ return nil
+ end
+ local rtn = lib.returns[index]
+ if not rtn then
+ return nil
+ end
+ return alloc {
+ type = rtn.type,
+ value = rtn.value,
+ source = vm.librarySource(rtn),
+ }
+end
+
local function getValue(source)
local results = checkLiteral(source)
or checkValue(source)
or checkUnary(source)
or checkBinary(source)
or checkLibrary(source)
+ or checkLibraryReturn(source)
if results then
return results
end
results = {}
checkDef(results, source)
- checkCall(results, source)
- checkNext(results, source)
+ inferByCall(results, source)
+ inferByGetTable(results, source)
if #results == 0 then
return nil