diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-11-20 17:50:45 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-11-20 17:50:45 +0800 |
commit | 41a21bdfcc878177565557a42fca4cc324552455 (patch) | |
tree | b6ffe8d8f380892c6839225da084295f5a7d9dbd | |
parent | a7c23a257127d583e3754e23544d1ed97dda0a12 (diff) | |
download | lua-language-server-41a21bdfcc878177565557a42fca4cc324552455.zip |
整理代码
-rw-r--r-- | server-beta/src/vm/getValue.lua | 43 |
1 files changed, 16 insertions, 27 deletions
diff --git a/server-beta/src/vm/getValue.lua b/server-beta/src/vm/getValue.lua index d5db880b..fe056c92 100644 --- a/server-beta/src/vm/getValue.lua +++ b/server-beta/src/vm/getValue.lua @@ -12,11 +12,7 @@ local typeSort = { NIL = setmetatable({'<nil>'}, { __tostring = function () return 'nil' end }) -local function merge(a, b) - local t = {} - for i = 1, #a do - t[#t+1] = a[i] - end +local function merge(t, b) for i = 1, #b do t[#t+1] = b[i] end @@ -438,7 +434,7 @@ local function checkCall(result, source) end end -local function checkNext(result, source) +local function checkNext(results, source) local next = source.next if not next then return @@ -449,38 +445,20 @@ local function checkNext(result, source) or next.type == 'setfield' or next.type == 'setindex' or next.type == 'setmethod' then - merge(result, 'table') + merge(results, 'table') end end -local function checkDef(result, source) +local function checkDef(results, source) vm.eachDef(source, function (info) local src = info.source local tp = vm.getValue(src) if tp then - merge(result, tp) + merge(results, tp) end end) end -local function typeInference(source) - local tp = checkLiteral(source) - or checkValue(source) - or checkUnary(source) - or checkBinary(source) - if tp then - return tp - end - - local result = {} - - checkCall(result, source) - checkNext(result, source) - checkDef(result, source) - - return dump(result) -end - local function getValue(source) local result = checkLiteral(source) if result then @@ -492,6 +470,17 @@ local function getValue(source) if results then return results end + + results = {} + checkDef(results, source) + --checkCall(results, source) + --checkNext(results, source) + + if #results == 0 then + return nil + end + + return results end function vm.checkTrue(source) |