diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-11-21 20:49:42 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-11-21 20:49:42 +0800 |
commit | 442b2d559537ed0caeb9116bf904bd93002aaa8b (patch) | |
tree | e0785189e18388332f1f90127ef6677f726bad64 /server-beta/src | |
parent | 128e0f95772c0afc43a447c039f08f13b268ad0a (diff) | |
download | lua-language-server-442b2d559537ed0caeb9116bf904bd93002aaa8b.zip |
局部变量在一定程度上向后推测类型
Diffstat (limited to 'server-beta/src')
-rw-r--r-- | server-beta/src/vm/getValue.lua | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/server-beta/src/vm/getValue.lua b/server-beta/src/vm/getValue.lua index 6faf591e..c1b3622d 100644 --- a/server-beta/src/vm/getValue.lua +++ b/server-beta/src/vm/getValue.lua @@ -665,6 +665,30 @@ local function inferByBinary(results, source) end end +local function inferBySetOfLocal(results, source) + if source.ref then + for i = 1, #source.ref do + local ref = source.ref[i] + if ref.type == 'setlocal' then + break + end + merge(results, vm.getValue(ref)) + end + end +end + +local function inferBySet(results, source) + if #results ~= 0 then + return + end + if source.type == 'local' then + inferBySetOfLocal(results, source) + elseif source.type == 'setlocal' + or source.type == 'getlocal' then + inferBySetOfLocal(results, source.node) + end +end + local function getValue(source) local results = checkLiteral(source) or checkValue(source) @@ -679,6 +703,7 @@ local function getValue(source) results = {} checkDef(results, source) + inferBySet(results, source) inferByCall(results, source) inferByGetTable(results, source) inferByUnary(results, source) |